ffmpeg视频上传功能常用的俩个工具类【1.视频转码=2.视频抓图】

   我们在用ffmpeg做视频上传功能时,经常会用到视频的转码和视频抓图的俩个功能,这里贴出俩个常用的工具类代码

1.ffmpeg视频转码,多数在做视频上传功能时,会将视频转为flv格式,因为flv体积小便于快速读取播放,这里以转FLV为例(attachmentContentType为视频类型,若转为其他类型只需更改该参数即可)代码逻辑这里不做的过多解释,直接上代码


/**
 * 功能:将任意格式的视频转化为flv格式,有利于在线视频播放
 * 前置条件:E盘下放有 ffmpeg.exe、ffplay.exep、threadGC2.dll(ffmpeg来自 ffmpeg.rev12665.7z)
 *                 E盘下还需 mencoder.exe、drv43260.dll
 *  ps:   ffmpeg 能解析的格式:asx,asf,mpg,wmv,3gp,mp4,mov,avi,flv等
 *         mencoder 解析剩下的格式:wmv9,rm,rmvb  
 */
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
 *  功能函数
 * @param inputFile 待处理视频,需带路径
 * @param outputFile 处理后视频,需带路径
 * @return
 */
@Service
@Transactional
public class ConvertFlv {
	public static boolean convert(String inputFile, String outputFile, String ffmpeg, String mencoder, String video_temp_path, String attachmentContentType)
	{
		if (!checkfile(inputFile)) {
			System.out.println(inputFile + " is not file");
			return false;
		}
		if (process(inputFile,outputFile,ffmpeg,mencoder,video_temp_path,attachmentContentType)) {
			System.out.println("ok");
			return true;
		}
		return false;
	}
	//检查文件是否存在
	private static boolean checkfile(String path) {
		File file = new File(path);
		if (!file.isFile()) {
			return false;
		}
		return true;
	}
	/**
	 * 转换过程 :先检查文件类型,在决定调用 processFlv还是processAVI
	 * @param inputFile
	 * @param outputFile
	 * @param ffmpeg 
	 * @param mencoder 
	 * @param video_temp_path 
	 * @param attachmentContentType 
	 * @return
	 */
	private static boolean process(String inputFile,String outputFile, String ffmpeg, String mencoder, String video_temp_path, String attachmentContentType) {
		int type = checkContentType(attachmentContentType);
		boolean status =
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

郝南过

感谢大佬打赏,送你一个么么哒

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值