FFmpeg任意格式转码(比如:AVI、MP4、WMV、FLV等)
1.:fmpeg官网下载地址:http://www.ffmpeg.org/download.html
2:下载windows、linux
2.1:下载windows
2.2:下载linux和命令
1.安装依赖
yum install autoconf automake bzip2 bzip2-devel cmake freetype-devel gcc gcc-c++ git libtool make mercurial pkgconfig zlib-devel
2.mkdir ~/ffmpeg_sources3.安装Yasm
git clone --depth 1 git://github.com/yasm/yasm.git
cd yasm
autoreconf -fiv
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin"make && make install
make distclean
4.安装libx264
cd ~/ffmpeg_sources
git clone --depth 1 git://git.videolan.org/x264
cd x264
PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static
make && make install
make distclean
5.安装libx265
cd ~/ffmpeg_sources
tar zxvf x265_v3_3.tar.gzcd ~/ffmpeg_sources/x265/build/linux
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED:bool=off ../../source
make && make install
6.安装libfdk_aaccd ~/ffmpeg_sources
git clone --depth 1 git://git.code.sf.net/p/opencore-amr/fdk-aaccd fdk-aac
autoreconf -fiv
./configure --prefix="$HOME/ffmpeg_build" --disable-shared
make && make install
make distclean7.安装libmp3lame安装
cd ~/ffmpeg_sources
curl -O -L https://downloads.sourceforge.net/project/lame/lame/3.100/lame-3.100.tar.gz
tar xzvf lame-3.100.tar.gz
cd lame-3.100
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --disable-shared --enable-nasm
make && make instal
8.安装libopus
cd ~/ffmpeg_sources
curl -O -L https://archive.mozilla.org/pub/opus/opus-1.3.1.tar.gz
tar xzvf opus-1.3.1.tar.gz
cd opus-1.3.1
./configure --prefix="$HOME/ffmpeg_build" --disable-shared
make && make install
9.安装libvpx
cd ~/ffmpeg_sources
git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git
cd libvpx
./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm
make && make install
10.编译安装ffmpeg
cd ~/ffmpeg_sources
curl -O -L https://ffmpeg.org/releases/ffmpeg-snapshot-git.tar.bz2
ar xjvf ffmpeg-snapshot.tar.bz2cd ffmpeg
PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \
--prefix="$HOME/ffmpeg_build" \
--pkg-config-flags="--static" \
--extra-cflags="-I$HOME/ffmpeg_build/include" \
--extra-ldflags="-L$HOME/ffmpeg_build/lib" \
--extra-libs=-lpthread \
--extra-libs=-lm \
--bindir="$HOME/bin" \
--enable-gpl \
--enable-libfdk_aac \
--enable-libfreetype \
--enable-libmp3lame \
--enable-libopus \
--enable-libvpx \
--enable-libx264 \
--enable-libx265 \
--enable-nonfreemake && make install
3:
/*** 多种类型转码* @param path(比如:http://localhost:8081/2021/06/27/21546789.avi)* @param type(转码类型)* @param ffmpegType(比如:mp4)* @return*/public String path(String path,Integer type,String ffmpegType){String newFilePath = basePath + UUID.randomUUID().toString() ;String transcoding="";if(StringUtils.isEmpty(type)){if(StringUtils.isEmpty(ffmpegType))ffmpegType=videoFormat;transcoding = ffmpegPath + " -y -r 5 -i "+path+" -strict -2 -vcodec libx264 -acodec aac -ac 1 "+newFilePath+ffmpegType;}else {switch (type){case 1:if(StringUtils.isEmpty(ffmpegType))ffmpegType=videoFormat;transcoding = ffmpegPath + " -r 5 -i "+path+" -strict -2 -vcodec libx264 -acodec opus -ac 1 "+newFilePath+ffmpegType;break;case 2:if(StringUtils.isEmpty(ffmpegType))ffmpegType=".avi";transcoding=ffmpegPath + " -i "+path+" -strict -2 -vcodec libx264 -acodec pcm_u8 "+newFilePath+ffmpegType;break;case 16:if(StringUtils.isEmpty(ffmpegType))ffmpegType=".avi";transcoding=ffmpegPath + " -i "+path+" -strict -2 -vcodec libx264 -acodec pcm_alaw "+newFilePath+ffmpegType;break;case 3:if(StringUtils.isEmpty(ffmpegType))ffmpegType=videoFormat;transcoding=ffmpegPath + " -i "+path+" -strict -2 -c:v libx265 -b:v 500k -max_muxing_queue_size 9999 -r 30 -crf 23 -preset veryfast "+newFilePath+ffmpegType;break;case 4:if(StringUtils.isEmpty(ffmpegType))ffmpegType=videoFormat;transcoding=ffmpegPath + " -i "+path+" -strict -2 -vcodec libx265 -acodec opus -ac 1 -max_muxing_queue_size 9999 -r 30 -crf 23 -preset veryfast "+newFilePath+ffmpegType;break;/* case 12:transcoding=ffmpegPath + " -i "+path+" -strict -2 -vcodec libx265 -acodec pcm_u8 -max_muxing_queue_size 9999 -r 30 -crf 23 -preset veryfast "+newFilePath+".avi";ffmpegType=".avi";break;case 15:transcoding=ffmpegPath + " -i "+path+" -strict -2 -vcodec libx265 -acodec pcm_alaw -ac 1 -max_muxing_queue_size 9999 -r 30 -crf 23 -preset veryfast "+newFilePath+".avi";ffmpegType=".avi";break;*/case 5:if(StringUtils.isEmpty(ffmpegType))ffmpegType=videoFormat;transcoding=ffmpegPath + " -i "+path+" -strict -2 -vcodec libvpx-vp9 -acodec opus -ac 1 -max_muxing_queue_size 9999 -r 30 -crf 23 -preset veryfast "+newFilePath+ffmpegType;break;case 6:if(StringUtils.isEmpty(ffmpegType))ffmpegType=videoFormat;transcoding= ffmpegPath + " -i "+path+" -strict -2 -vcodec libvpx-vp9 -acodec aac -f mp4 -y -max_muxing_queue_size 9999 -r 30 -crf 23 -preset veryfast "+newFilePath+ffmpegType;break;case 12:if(StringUtils.isEmpty(ffmpegType))ffmpegType=videoFormat;transcoding= ffmpegPath + " -i "+path+" -strict -2 -vcodec libvpx-vp9 -acodec vorbis -f mp4 -y -max_muxing_queue_size 9999 -r 30 -crf 23 -preset veryfast "+newFilePath+ffmpegType;break;case 11:if(StringUtils.isEmpty(ffmpegType))ffmpegType=".avi";transcoding= ffmpegPath + " -i "+path+" -strict -2 -vcodec libvpx-vp9 -acodec pcm_u8 -y -max_muxing_queue_size 9999 -r 30 -crf 23 -preset veryfast "+newFilePath+ffmpegType;ffmpegType=".avi";break;case 14:if(StringUtils.isEmpty(ffmpegType))ffmpegType=".avi";transcoding= ffmpegPath + " -i "+path+" -strict -2 -vcodec libvpx-vp9 -acodec pcm_alaw -y -max_muxing_queue_size 9999 -r 30 -crf 23 -preset veryfast "+newFilePath+ffmpegType;ffmpegType=".avi";break;case 7:if(StringUtils.isEmpty(ffmpegType))ffmpegType= ".webm";transcoding=ffmpegPath + " -i "+path+" -strict -2 -c:v libvpx -b:v 1M -c:a vorbis -max_muxing_queue_size 9999 -r 30 -crf 23 -preset veryfast "+newFilePath+ffmpegType;break;case 8:if(StringUtils.isEmpty(ffmpegType))ffmpegType= ".webm";transcoding=ffmpegPath + " -i "+path+" -strict -2 -c:v libvpx -b:v 1M -c:a libopus -max_muxing_queue_size 9999 -r 30 -crf 23 -preset veryfast "+newFilePath+ ffmpegType;break;case 9:if(StringUtils.isEmpty(ffmpegType))ffmpegType=".avi";transcoding=ffmpegPath + " -i "+path+" -strict -2 -c:v libvpx -b:v 1M -c:a aac -max_muxing_queue_size 1024 -r 30 -crf 23 -preset veryfast "+newFilePath+ ffmpegType;ffmpegType= ".avi";break;case 10:if(StringUtils.isEmpty(ffmpegType))ffmpegType=".avi";transcoding=ffmpegPath + " -i "+path+" -strict -2 -c:v libvpx -b:v 1M -c:a pcm_u8 -max_muxing_queue_size 9999 -r 30 -crf 23 -preset veryfast "+newFilePath+ffmpegType;ffmpegType= ".avi";break;case 13:if(StringUtils.isEmpty(ffmpegType))ffmpegType=".avi";transcoding=ffmpegPath + " -i "+path+" -strict -2 -c:v libvpx -b:v 1M -c:a pcm_alaw -max_muxing_queue_size 9999 -r 30 -crf 23 -preset veryfast "+newFilePath+ ffmpegType;ffmpegType= ".avi";break;case 200:transcoding=ffmpegPath + " -i "+path+" -strict -2 -c:v libvpx -b:v 1M -c:a aac -max_muxing_queue_size 1024"+newFilePath+ ".webm";ffmpegType= ".webm";break;case 201:transcoding=ffmpegPath + " -i "+path+" -b:v 64k -bufsize 64k -strict -2 -c:v libvpx -c:a copy -y -max_muxing_queue_size 1024 -r 30 -crf 23 -preset veryfast "+newFilePath+ ".mp4";ffmpegType= ".mp4";break;default:if(StringUtils.isEmpty(ffmpegType))ffmpegType= videoFormat;transcoding = ffmpegPath + " -r 5 -i "+path+" -strict -2 -vcodec libx264 -acodec aac -ac 1 "+newFilePath+ffmpegType;break;}}try {Runtime rt = Runtime.getRuntime();Process proc = rt.exec(transcoding);InputStream stderr = proc.getErrorStream();InputStreamReader isr = new InputStreamReader(stderr);BufferedReader br = new BufferedReader(isr);String line = null;while ( (line = br.readLine()) != null) {System.out.println(line);}int exitVal = proc.waitFor();System.out.println("Process exitValue: " + exitVal);} catch (Exception e) {e.printStackTrace();return null;}return newFilePath+ffmpegType;}
4:安装包:
这里支持的大类型有:h264、h265、vp8、vp9
FFmpeg任意格式转码(比如:AVI、MP4、WMV、FLV等)相关推荐
- 最简单的基于FFMPEG 4.2的封装格式转换器(无编解码MP4转FLV)
文章目录 最简单的基于FFMPEG 4.2的封装格式转换器(无编解码) 配置 代码 结果 关键函数说明 avformat_open_input avformat_find_stream_info av ...
- php 视频上传 FFMpeg 视频格式转码
啥也不说先上源码,安装不会的可以看我的另一篇文章或者查看专栏https://blog.csdn.net/qq_29099209/article/details/79720723 <?phpnam ...
- flv格式的视频怎么转mp4?
flv格式的视频怎么转mp4?FLV 是FLASH VIDEO的简称,一种由flash发展而来的视频文件,是处理mp4外使用最广泛的视频格式之一,flv格式的视频有很多的优点,例如文件体积较小和加载速 ...
- iOS开发 iOS集成FFmpeg及视频格式转码
点击下载 Demo 一.FFmpeg简介 FFmpeg是一个开源免费跨平台的视频和音频流方案,属于自由软件,采用LGPL或GPL许可证(依据你选择的组件).它提供了录制.转换以及流化音视频的完整解决方 ...
- 文件转码(mp3\mp4\rmvb\avi\pdf\txt等)--Ubuntu小笔记
播放swf文件 安装swf解码器 sudo apt-get install swfmill 如何保存串流视频(mms/rtsp) mplayer -dumpfile dump.rm -dumpstre ...
- ffmpeg 常用命令总结:(avi转MP4、MP4转ts、视频压缩、去除视频声音、合并音频和视频)
文章目录 配置 说明: 0.ffmpeg一些命令参数: a) 通用选项 b) 视频选项 c)高级视频选项 d)音频选项 e)音频/视频捕获选项 f)高级选项 1.avi转MP4命令: 2.MP4转ts ...
- ffmpeg使用bsf后码流从avcc格式变成annex-b造成硬解异常
ffmpeg使用bsf后码流从avcc格式变成annex-b造成硬解异常 问题的产生 第一个ffmpeg拷贝(copy)第三方的流到源站,第二个ffmpeg进程的源流为第一个ffmpeg的输出,并使用 ...
- ffmpeg源码分析及mp4文件解析
一.mp4文件的组织 1. mp4文件的box(ffmpeg中叫atom) mp4是由一系列的box组成的,每个box的header是8个字节(4字节的长度,4字节的type) 第一个box比较特殊, ...
- ts转换mp4 linux_佳佳AVI MP4格式转换器下载-佳佳AVI MP4格式转换器免费版下载v6.5.5.0...
佳佳AVI MP4格式转换器支持将AVI视频格式快速转换为MP4,软件采用顶级音频编码,转换速度超快,同时转换质量完美平衡,转换的视频和音频可以在各种移动设备上播放,比如mp3.4.5播放器以及电脑. ...
最新文章
- CSS实现 全兼容的多列均匀布局问题
- 为你揭示最危害程序员职业生涯的三大观念
- 关于vue2.0组件通信
- 如何在腾讯云上安装Cloud Foundry
- HDU-5783 Divide the Sequence(贪心)
- 万达9.3亿美元并购北欧最大院线 全球市场份额逼近20%
- 南信大校园网稳定|多拨|软路由|硬路由|保姆级教学|一步到位|openwrt|pandavan老毛子
- matlab色散光纤,基于MATLAB的高速光通信色散补偿技术
- 内网代理——常用工具
- 流媒体弱网优化之路(FEC+mediasoup)——mediasoup的Nack优化以及FEC引入
- ifox格式如何快速的转换成mp4格式?
- JavaWeb宿舍管理系统环境搭建运行教程
- 判断奇数和偶数不常见的方法
- js 安卓和ios的一些奇奇怪怪的注意点
- win7系统没有计算机睡眠状态,如何解决win7系统无法进入睡眠状态
- 腾讯又一长达 8 年的服务下架。。。
- 【前端监控系统】埋点数据上报的3种方式
- 8种网页数据的采集工具
- EasyPlayer RTSP播放器:一个适用于安防行业的工具利器(EasyPlayer Windows v2.0.17.0709)
- 不用找,你想要的中国风ppt模板素材都在这里