您的位置:首页 - 文章 - 随笔 - 正文

FFmpeg随笔

jar

<dependency> <groupId>org.bytedeco</groupId> <artifactId>javacv</artifactId> <version>0.8</version>
</dependency>

一、截取视频第一针:

ffmpeg -i d:/test.mp4 -ss 1 -f image2 d:/001.png

-ss后跟的时间单位为秒
上述命令行 -ss 1代表截取第一秒该帧作为封面
image2:即转换成图片

/** *根据视频截取第一帧图片 * @param video 视频地址 * @param outImg 图片地址 */ public static void getVedioFirstImg(String video,String outImg){ String cmdStr2 = "ffmpeg -i /home/ftpFile/images/"+video+" -ss 1 -f image2 " +"/home/ftpFile/images/"+outImg; try { String[] cmdA = { BINSH, "-c", cmdStr2}; Process process = Runtime.getRuntime().exec(cmdA); process.waitFor(); } catch (Exception e) { e.printStackTrace(); } }
public static void VideoCutFirstPicture(String localPath, String targetFilePath) {	log.info("截取视频的第一秒图片");	String command = "ffmpeg -i " + localPath + " -f image2 -ss 1 -frames:v 1 -y "	+ targetFilePath;	log.info("the command is : " + command);	Runtime runtime = Runtime.getRuntime();	try {	Process proc = runtime.exec(command);	InputStream stderr = proc.getErrorStream();	InputStreamReader isr = new InputStreamReader(stderr);	BufferedReader br = new BufferedReader(isr);	String line = null;	StringBuffer sb = new StringBuffer();	while ((line = br.readLine()) != null)	sb.append(line);	int exitVal = proc.waitFor();	log.info("the exitVal is : " + exitVal);	} catch (IOException e) {	e.printStackTrace();	} catch (InterruptedException e) {	log.error("ffmpeg exec cmd Exception ", e);	}	log.info("执行命令结束");	}
本文原创,作者:西决,其版权均为品创网络所有。如需转载,请注明出处:https://www.sxpcwlkj.com/ffmpeg%e9%9a%8f%e7%ac%94/

发表评论