Java調用FFmpeg進行截圖

/**
	 * 視頻截圖
	 * @param veido_path    視頻路徑
	 * @param ffmpeg_path	ffmpeg路徑
	 * @param image_name	圖片保存路徑
	 * @param time			截圖時間戳
	 * @return
	 */
	public static boolean processImg(String veido_path, String ffmpeg_path, String image_name, float time) {
		File file = new File(veido_path);
		if (!file.exists()) {
			log.info("路徑[" + veido_path + "]對應的視頻文件不存在!");
			return false;
		}
		List<String> commands = new java.util.ArrayList<String>();
		commands.add(ffmpeg_path);
		commands.add("-ss");//SS參數放在最開始截圖速度最快
		commands.add("\""+time+"\"");//這個參數是設置截取視頻多少秒時的畫面
		commands.add("-i");
		commands.add(veido_path);
		commands.add("-y");
		commands.add("-f");
		commands.add("image2");
//		commands.add("-t");
//		commands.add("\""+z+"\"");
//		commands.add("-s");
	//	commands.add("700x525");
		commands.add(image_name+".jpg");
		try {
			ProcessBuilder builder = new ProcessBuilder();
			builder.command(commands);
			builder.start();
			log.info(veido_path+",第 "+time+" 秒截取成功...");
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

 參數介紹:

    -i  輸入文件 "f:\\test.flv" 

    -f 表示輸出文件格式

    -ss 表示相對於文件開始處的時間偏移值, 即從5秒出開始截圖

    -s 表示截圖的的大小,如果不指定,則爲視頻原始分辨率

    -vframes 表示截圖的楨數

    -y 輸出文件"f:\\test.jpg"   

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章