天天看点

FFMPEG音频视频开发: 视频转码、合并、修改分辨率、比特率

一、环境介绍

操作系统介绍:win10 64位

FFMPEG版本: 4.4.2

QT版本: 5.12.6

二、FFMPEG下载

ubuntu系统下编译安装ffmpeg:  

https://blog.csdn.net/xiaolong1126626497/article/details/104919095 windos系统下安装ffmpeg: https://blog.csdn.net/xiaolong1126626497/article/details/105412560 三、视频转码示例

任意格式转为MP4:
 
转码视频格式并设置音频采样率和输出视频尺寸: mpg-->mp4
C:\FFMPEG\ffmpeg_x86_4.2.2\bin\ffmpeg.exe -i 1.mpg -y -qscale 0 -vcodec libx264 -acodec aac -ac 1 -ar 22050 -s 300*300  1_1.mp4
 
 
转码视频格式并设置音频采样率和输出视频尺寸(软解可以播放-硬解无法播放): wmv-->wmv
C:\FFMPEG\ffmpeg_x86_4.2.2\bin\ffmpeg.exe -i 2.wmv -y -qscale 0 -vcodec libx264 -acodec aac -ac 1 -ar 48000 -s 300*300  2_1.wmv
 
 
转码视频格式并设置音频采样率和输出视频尺寸: wmv-->mp4
C:\FFMPEG\ffmpeg_x86_4.2.2\bin\ffmpeg.exe -i 2.wmv -y -qscale 0 -vcodec libx264 -acodec aac -ac 1 -ar 48000 -s 300*300  2_1.mp4
 
 
转码视频格式并设置音频采样率: wmv-->mp4
C:\FFMPEG\ffmpeg_x86_4.2.2\bin\ffmpeg.exe -i 2.wmv -y -qscale 0 -vcodec libx264 -acodec aac -ac 1 -ar 48000 2_1.mp4
 
 
转码视频格式并设置音频采样率: wmv-->mp4
C:\FFMPEG\ffmpeg_x86_4.2.2\bin\ffmpeg.exe -i Video_2020-10-11_2.wmv -y -qscale 0 -vcodec libx264 -acodec aac -ac 1 -ar 22050 Video_2020-10-11_2_1.mp4
 
 
转码视频格式并设置音频采样率和输出视频尺寸、修改码率: mpg-->mp4
C:\FFMPEG\ffmpeg_x86_4.2.2\bin\ffmpeg.exe -i 1.mpg -y -qscale 0 -vcodec libx264 -acodec aac -ac 1 -ar 22050 -b:v 400k -s 300*300  1_1.mp4
 
视频合并:
C:\FFMPEG\ffmpeg_x86_4.2.2\bin\ffmpeg.exe  -f concat -safe 0 -i filelist.txt -c copy demo.mp4
 
filelist.txt文件内容---里面的视频路径使用相对路径:
file 'd8381671f616468c9193defcd55eeb3b.mp4'
file 'ad6beef4b9e14bcf8f4c07d802cae360.mp4'
file '1d15bf4c221c4e429413568d5c2e58e4.mp4'
 
 
转码视频格式并设置音频采样率和输出视频尺寸、设置输出帧率: 
C:\FFMPEG\ffmpeg_x86_4.2.2\bin\ffmpeg.exe -i 1.mp4 -y -qscale 0 -vcodec libx264 -acodec aac -ac 1 -ar 22050 -s 300*300 -r 30 -aspect 1_1.mp4
 
不同分辨率的源视频合成一个视频,设置画面的中心位置:
C:\FFMPEG\ffmpeg_x86_4.2.2\bin\ffmpeg.exe -i 1.mp4 -i 1.mpg -i 123.mp4 -f lavfi -i color=black -filter_complex "[0:v]format=pix_fmts=yuva420p,rotate=PI*0/180:c=none:ow=rotw(PI*0/180):oh=roth(PI*0/180),pad=1920:1080:(ow-iw)/2:(oh-ih)/2:black,setpts=PTS-STARTPTS+0/TB[va0];[1:v]format=pix_fmts=yuva420p,rotate=PI*0/180:c=none:ow=rotw(PI*0/180):oh=roth(PI*0/180),pad=1920:1080:(ow-iw)/2:(oh-ih)/2:black,setpts=PTS-STARTPTS+3/TB[va1];[2:v]format=pix_fmts=yuva420p,rotate=PI*0/180:c=none:ow=rotw(PI*0/180):oh=roth(PI*0/180),pad=1920:1080:(ow-iw)/2:(oh-ih)/2:black,setpts=PTS-STARTPTS+7/TB[va2];[3:v]scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2:black,trim=duration=12[over0];[over0][va0]overlay[over1];[over1][va1]overlay[over2];[over2][va2]overlay=format=yuv420[outv];[0:a][1:a][2:a] concat=n=3:v=0:a=1[outa]" -aspect 1920:1080 -vcodec libx264 -map "[outv]" -map "[outa]" -y out.mp4
 
//视频倒放,无音频
C:\FFMPEG\ffmpeg_x86_4.2.2\bin\ffmpeg.exe -i 123.mp4 -filter_complex [0:v]reverse[v] -map [v] -preset superfast out.mp4
//视频倒放,音频不变
C:\FFMPEG\ffmpeg_x86_4.2.2\bin\ffmpeg.exe -i 123.mp4 -vf reverse out.mp4
//音频倒放,视频不变
C:\FFMPEG\ffmpeg_x86_4.2.2\bin\ffmpeg.exe -i 123.mp4 -map 0 -c:v copy -af "areverse" out.mp4
//音视频同时倒放
C:\FFMPEG\ffmpeg_x86_4.2.2\bin\ffmpeg.exe -i 123.mp4 -vf reverse -af areverse -preset superfast out.mp4