Java代码使用ffmpeg视频按帧存储
来源:互联网 发布:Ubuntu配置caffe CPU 编辑:程序博客网 时间:2024/05/21 09:00
public class VideoThumbTaker
{
protected static String ffmpegApp;
public VideoThumbTaker(String ffmpegApp){ this.ffmpegApp = ffmpegApp;}
@SuppressWarnings(“unused”)
/**
* 获取指定时间内的图片
* @param videoFilename:视频路径
* @param thumbFilename:图片保存路径
* @param width:图片长
* @param height:图片宽
* @param hour:指定时
* @param min:指定分
* @param sec:指定秒
* @throws IOException
* @throws InterruptedException
*/
public void V2PAll(String videoFilename, String thumbFilename,int width,
int height,int hour, int min,float sec) throws IOException, InterruptedException{
System.out.printf(“%d:%d:%.3f\n”,hour,min,sec);
System.out.println(“first enter into V2PAll!”);
ProcessBuilder processBuilder = new ProcessBuilder(ffmpegApp,”-y”,
“-i”, videoFilename, thumbFilename+”1.jpg”,
“-ss”,”10”, “-t” , “0.001”,
//”-f”,”mjpeg”,//hour , “:” + min + “:” + sec,
“-s” , width + “*” + height
//”-vframes”, “200”
);
System.out.println(processBuilder.command());
Process process = processBuilder.start(); System.out.println(process); System.out.println("process has get start..."); InputStream stderr = process.getErrorStream(); InputStreamReader isr = new InputStreamReader(stderr); BufferedReader br = new BufferedReader(isr); String line; //这里出现问题!! while ((line = br.readLine()) !=null) { System.out.println(line); ; } process.waitFor(); if(br != null) br.close(); if(isr != null) isr.close(); if(stderr !=null) stderr.close();
}
public void getThumb(String videoFilename, String thumbFilename,int width, int height,float sec) throws IOException, InterruptedException{ ProcessBuilder processBuilder = new ProcessBuilder(ffmpegApp,"-y", "-i", videoFilename, "-vframes", "1", "-ss",""+ sec*0.04, "-f", "mjpeg", "-s", width + "*" + height, "-an", thumbFilename); Process process = processBuilder.start(); InputStream stderr = process.getErrorStream(); InputStreamReader isr = new InputStreamReader(stderr); BufferedReader br = new BufferedReader(isr); String line; while ((line = br.readLine()) !=null) ; process.waitFor(); if(br != null) br.close(); if(isr != null) isr.close(); if(stderr !=null) stderr.close();}public static void main(String[] args){ VideoThumbTaker videoThumbTaker = new VideoThumbTaker("D:\\ffmpeg\\ffmpeg.exe"); VideoInfo videoInfo = new VideoInfo("D:\\ffmpeg\\ffmpeg.exe", "C:/Users/ASUS-PC/Desktop/2.mp4"); System.out.println("videoName : " + videoInfo.getVideoFilename()); try { System.out.println("get Here!"); videoInfo.getInfo(); }catch (Exception e) { System.out.println("This is an error!!"); e.printStackTrace(); } System.out.println("Seconds: " + (int)videoInfo.getSeconds()); System.out.println("Path: " + videoInfo.getVideoFilename()); int width = videoInfo.getWidth(); int height = videoInfo.getHeigt(); System.out.println("Width:" + width + " ; Height :" + height); int hour = videoInfo.getHours(); int min = videoInfo.getMinutes(); float sec = videoInfo.getSeconds(); System.out.printf("Hour:Min:Sec %d:%d:%.3f\n",hour,min,sec); sec = hour*3600 + min*60 + sec; for(int i = 0; i < (int)sec*25; i++) { try { videoThumbTaker.getThumb("C:/Users/ASUS-PC/Desktop/2.mp4", "C:\\Users\\ASUS-PC\\Desktop\\Video\\"+i+".jpg", width, height, i); } catch (Exception e){ e.printStackTrace(); } } /*try { videoThumbTaker.V2PAll("C:/Users/ASUS-PC/Desktop/2.mp4", "C:\\Users\\ASUS-PC\\Desktop\\Video\\", width, height, hour, min, sec); System.out.println("get True!"); } catch (Exception e){ System.out.println("Or get False ! Error"); e.printStackTrace(); } */ System.out.println("over");}
}
- Java代码使用ffmpeg视频按帧存储
- 使用ffmpeg提取视频帧
- java使用ffmpeg对视频截图
- 使用java连接ffmpeg转码视频
- Java 使用 ffmpeg.exe ( FLV视频转换器 )
- ffmpeg+SDL的使用之获取视频帧将其存储为PPM格式图片
- Ffmpeg视频截图代码
- java调用ffmpeg获取视频信息函数代码
- 使用FFMPEG合并视频
- 使用FFMPEG合并视频
- 使用FFMPEG合并视频
- 使用FFMPEG合并视频
- 使用FFMPEG合并视频
- 使用ffmpeg合并视频
- JAVA ffmpeg 视频处理
- 使用ffmpeg视频拆帧以及将图片合成视频
- 使用Java调用linux命令ffmpeg视频转码
- java使用ffmpeg转换视频为flv文件
- x = tf.constant([[0.7, 0.9]])与x = tf.constant([0.7, 0.9])
- get提交和post提交的区别
- 创建订单
- Python操作SQLite/MySQL/LMDB/LevelDB
- Linux之HA高可用集群的基础概念总结
- Java代码使用ffmpeg视频按帧存储
- 使用jquery动态添加导航页卡和标题
- 京东订单
- Bean
- lite-server
- c++继承(子类调用父类函数、全局函数)
- Shiro学习参考
- dash激活
- *.问题记录集1