ffmpeg 视频转换、图片批量提取

该博客介绍了一个使用Java调用ffmpeg命令行工具进行视频转换和批量提取图片的方法。通过指定输入视频路径、输出视频路径以及时间点,实现了视频格式转换;同时,根据时间数组,提取了相应帧数的图片并保存为指定尺寸的jpg格式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

public static void coverterVideo(String in, String out, Integer[] times) {
		String prfix_ffmpeg = Contants.getRes("FFMPEG_PATH");

		StringBuilder commond = new StringBuilder();
		commond.append(prfix_ffmpeg);
		commond.append(" -i ");
		commond.append(in);
		commond.append(" -vcodec copy -acodec copy -f mp4 ");
		commond.append(out);

		System.out.println(commond.toString());
		Process pro = null;
		Process pro1 = null;
		try {
			if(!new File(out).exists()){
				System.out.println("***********coverter begin*********");
				pro = Runtime.getRuntime().exec(commond.toString());
				System.out.println("***********"
						+ new SimpleDateFormat("yy-MM-dd HH:MM:ss")
						.format(new Date()) + "***********");
				doWaitFor(pro);
				System.out.println("***********"
						+ new SimpleDateFormat("yy-MM-dd HH:MM:ss")
						.format(new Date()) + "***********");
				System.out.println("**********coverter finished!!!*********");
			}
			// pro.destroy();
			
			if(new File(out).exists()){
				System.out.println("*********************截图开始***********************");
//				for(Integer mm : videoTimes){ //videoTimes  时间数组
//					StringBuilder commond1 = new StringBuilder();
//					commond1.append(prfix_ffmpeg);
//					commond1.append(" -i ");
//					commond1.append(out);
//					commond1.append(" -y -f image2 -ss ");
//					commond1.append(mm);
//					commond1.append(" -vframes 1 ");
//					commond1.append("-s 350*240 ");
//					commond1.append("D:/SOFT/ffmpeg/imgs/");
//					commond1.append(mm);
//					commond1.append(".jpg");
//					pro1 = Runtime.getRuntime().exec(commond1.toString());
//					doWaitFor(pro1);
//				}
				System.out.println("*********************截图结束***********************");
			}
			
		} catch (Exception e) {
			e.printStackTrace();
			try {
				pro.getErrorStream().close();
				pro.destroy();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		}
	}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值