截取图片DEMO. JAVA Windows FFmpeg

package com.test.util;


import java.io.File;
import java.util.List;
/**
 * 使用FFmpeg截取视频中的一帧图片
 * @author LPQ
 * @date 2017-08-22
 */
public class FFmpegPictures {


/**
 * 截取图片DEMO
 * @param FFmpegPath FFmpeg路径
 * @param videoPath 视频路径
 * @return 执行结果
 */
public static String createPictures(String FFmpegPath,String videoPath) {

String result = "图片截取";// 执行结果
File file = new File(videoPath);
if (!file.exists()) {
System.err.println("路径《" + videoPath + "》对应的视频文件不存在!");
result += "失败";
}
List<String> commands = new java.util.ArrayList<String>();
commands.add(FFmpegPath);
commands.add("-i");
commands.add(videoPath);
commands.add("-y");
commands.add("-f");
commands.add("image2");
commands.add("-ss");
commands.add("1");//截取秒数
commands.add("-s");
commands.add("1920x1080");//截取尺寸
commands.add(videoPath.substring(0, videoPath.lastIndexOf(".")).replaceFirst("video", "file") + ".jpg");//图片名称及类型
try {
ProcessBuilder builder = new ProcessBuilder(commands);//利用指定的操作系统程序和参数构造一个进程生成器。
builder.start();//使用此进程生成器的属性启动一个新进程
result += "成功";
} catch (Exception e) {
e.printStackTrace();
result += "失败";
}
return result;
}
 
public static void main(String[] args) {  
String result = createPictures("D:/ffmpeg/ffmpeg-20170130-cba4f0e-win32-static/bin/ffmpeg.exe","D:/ffmpeg/ffmpeg-20170130-cba4f0e-win32-static/bin/heyJude.mp4");
System.out.println(result);     
}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值