1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > FFmpeg任意格式转码(比如:AVI MP4 WMV FLV等)

FFmpeg任意格式转码(比如:AVI MP4 WMV FLV等)

时间:2020-02-12 00:17:42

相关推荐

FFmpeg任意格式转码(比如:AVI MP4 WMV FLV等)

1.:fmpeg官网下载地址:/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_sources

3.安装Yasm

git clone --depth 1 git:///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:///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.gz

cd ~/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_aac

cd ~/ffmpeg_sources

git clone --depth 1 git://git./p/opencore-amr/fdk-aac

cd fdk-aac

autoreconf -fiv

./configure --prefix="$HOME/ffmpeg_build" --disable-shared

make && make install

make distclean

7.安装libmp3lame安装

cd ~/ffmpeg_sources

curl -O -L /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 /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 /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 /releases/ffmpeg-snapshot-git.tar.bz2

ar xjvf ffmpeg-snapshot.tar.bz2

cd 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-nonfree

make && make install

3:

/*** 多种类型转码* @param path(比如:http://localhost:8081//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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。