ffmpeg合并音频至视频

ffmpeg -i autovideo_4k2k.ts -i 1kl-10kr.wav -c:v copy -c:a aac  -strict experimental -map 0:v:0 -map 1:a:0 autovideo_4K_1k.ts 
ffmpeg -i autovideo_1080_1k.mp4 -filter_complex "showwavespic=s=720x240:split_channels=1:colors=0x00ff00|0xff0000|0x0000ff" -frames:v 1 audio.png
ffmpeg -i autovideo_1080.ts -filter_complex "[0:a]showfreqs=s=1920x1080:mode=line:fscale=log,format=yuv420p[v]" -map "[v]" -map 0:a showfreqs_audio_03.mp4

 

ffmpeg 截取关键帧开头的视频片段

使用如下命令获取关键帧时间点

ffprobe -select_streams v -show_frames -v quiet LG.4K.DEMO_Chess_HEVC_60FPS_10bit_HDR.ts -unit | grep key_frame=1 -A 3

获取到如下时间点

key_frame=1
pkt_pts=96005
pkt_pts_time=1.066722 s
pkt_dts=96005
--
key_frame=1
pkt_pts=186095
pkt_pts_time=2.067722 s
pkt_dts=186095
--
key_frame=1
pkt_pts=276185
pkt_pts_time=3.068722 s
pkt_dts=276185
--
key_frame=1
pkt_pts=366275
pkt_pts_time=4.069722 s
pkt_dts=366275
--
key_frame=1
pkt_pts=456365
pkt_pts_time=5.070722 s
pkt_dts=456365
--
key_frame=1
pkt_pts=546455
pkt_pts_time=6.071722 s
pkt_dts=546455
--
key_frame=1
pkt_pts=636545
pkt_pts_time=7.072722 s
pkt_dts=636545
--
key_frame=1
pkt_pts=656064
pkt_pts_time=7.289600 s
pkt_dts=656064

使用截取命令进行截取。

ffmpeg -ss 00:00:07.072 -i LG.4K.DEMO_Chess_HEVC_60FPS_10bit_HDR.ts -vcodec copy -acodec copy LG.4K.DEMO_Chess_HEVC_60FPS_10bit_HDR.no_blackstart.ts

 

FFmpeg 集成libvmaf 分析 PSNR VMAF值

1.github 下载源码

git clone https://github.com/Netflix/vmaf.git

2.下载build tools meson

https://mesonbuild.com/Getting-meson.html

Meson is available in the Python Package Index and can be installed with pip3 install meson which requires root and will install it system-wide.

Alternatively, you can use pip3 install --user meson which will install it for your user and does not require any special privileges. This will install the package in ~/.local/, so you will have to add ~/.local/bin to your PATH.

3.编译 libvmaf

cd vmaf/libvmaf 参考 README.md

meson build –buildtype release

ninja -vC build

sudo ninja -vC build install

4.FFmpeg 使能

./configure --enable-debug=3 --disable-doc --disable-optimizations --enable-pic --extra-cflags=-fPIC --enable-openssl --enable-libx264 --enable-libx265 --enable-gpl --enable-nonfree --enable-libfreetype --enable-libfdk-aac --enable-libaom --enable-libvpx --enable-libopus --enable-libvmaf --enable-version3

make -j8

make install

5.使用

ffmpeg -i xigua_h265.mp4 -i xigua_feijm.mp4 -filter_complex "[0:v]scale=1920x1080:flags=bicubic[main]; [1:v]scale=1920x1080:flags=bicubic,format=pix_fmts=yuv420p,fps=fps=25/1[ref]; [main][ref]libvmaf=psnr=1:phone_model=1:log_fmt=json" -f null - > out.json

其他命令参考:

ffmpeg -i main.mpg -i ref.mpg -lavfi libvmaf -f null -
ffmpeg -i main.mpg -i ref.mpg -lavfi libvmaf="psnr=1:log_fmt=json" -f null -
ffmpeg -i main.mpg -i ref.mkv -lavfi "[0:v]settb=AVTB,setpts=PTS-STARTPTS[main];[1:v]settb=AVTB,setpts=PTS-STARTPTS[ref];[main][ref]libvmaf=psnr=1:log_fmt=json" -f null -

参考文档:

ChristosBampis_Netflix

参考地址:

 

https://ffmpeg.org/ffmpeg-filters.html#libvmaf

Calculating VMAF and PSNR with FFmpeg

ffmpeg 生成纯色的视频及添加音轨

ffmpeg -ss 0 -t 30  -f lavfi -i color=c=0x0000ff:s=1280x720:r=25 -vcodec libx264 -r:v 25 0000ff_30s_1280x720.mp4

同时添加一条音频track

ffmpeg -ss 0 -t 30  -f lavfi -i color=c=0x0000ff:s=1280x720:r=25  -ss 0 -t 30 -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=48000  -vcodec libx264 -r:v 25 -c:a aac  0000ff_30s_1280x720_aac.mp4

同时添加两条不同格式音频track

ffmpeg -ss 0 -t 30  -f lavfi -i color=c=0x0000ff:s=1280x720:r=25  -ss 0 -t 30 -f lavfi -i anullsrc=channel_layout=5.1:sample_rate=48000 -ss 0 -t 30 -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=48000  -map 0:v -map 1:a -map 2:a  -c:v libx264 -r:v 25 -c:a:0 ac3  -c:a:1 aac 0ff0ff_30s_1280x720_aac2_ac35.1.mp4

 

 

ffmpeg 倍速转码视频和音频

参考网页

https://trac.ffmpeg.org/wiki/How%20to%20speed%20up%20/%20slow%20down%20a%20video

ffmpeg -i  test.mp4 -filter_complex "[0:v]setpts=0.8*PTS[v];[0:a]atempo=1.25[a]" -map "[v]" -map "[a]" -b:v 400K -b:a 32k -c:v libx264 -s 1280x720  2_1280_720_264.mp4

上诉命令快放1.25倍,即将原来的视频时长缩短为80%.

ffmpeg 转码 vp9 10bit 视频

/libvpx/libvpx$ ./configure –enable-vp9-highbitdepth

make &make install

make ffmpeg

./configure –enable-debug=3 –disable-doc –disable-optimizations –enable-pic –extra-cflags=-fPIC –enable-openssl –enable-libx264 –enable-libx265 –enable-gpl –enable-nonfree –enable-libfreetype –enable-libfdk-aac –enable-libaom –enable-libvpx –enable-libopus

make && make install

ffmpeg -i /mydata/mymedia/mm_test_libx264_30_4096x2304.mp4 -c:v libvpx-vp9 -r 60 -s 4096*2160 -pix_fmt yuv420p10le -t 60 vp9_4096_2160_60fps_yuv420p10le.mkv

 

ffmpeg 编码x265 10bit 视频

假如x265源码位置如下:

xw@xw-pc:~/mywork/mycode/media/x265/x265$ ls
build COPYING doc readme.rst source

修改文件 x265/source/CMakeLists.txt 找到如下位置将OFF改成ON

if(X64)
# NOTE: We only officially support high-bit-depth compiles of x265
# on 64bit architectures. Main10 plus large resolution plus slow
# preset plus 32bit address space usually means malloc failure. You
# can disable this if(X64) check if you desparately need a 32bit
# build with 10bit/12bit support, but this violates the "shrink wrap
# license" so to speak. If it breaks you get to keep both halves.
# You will need to disable assembly manually.
option(HIGH_BIT_DEPTH "Store pixel samples as 16bit values (Main10/Main12)" ON)
endif(X64)

cmake ../x265/x265/source/

make

make install

编译 ffmpeg

./configure –enable-debug=3 –disable-doc –disable-optimizations –enable-pic –extra-cflags=-fPIC –enable-openssl –enable-libx264 –enable-libx265 –enable-gpl –enable-nonfree –enable-libfreetype –enable-libfdk-aac –enable-libaom –enable-libvpx –enable-libopus

ffmpeg -i /mydata/mymedia/mm_test_libx264_30_4096x2304.mp4 -c:v libx265 -r 60 -s 4096*2160 -pix_fmt yuv420p10le -t 60 h.265_4096_2160_60fps_yuv420p10le.mkv

ffmpeg 编译 AV1 x264 x265转码

代码下载:

1.下载ffmpeg code。

git clone https://github.com/FFmpeg/FFmpeg.git

目前最新版本branch为:

remotes/origin/release/4.2    checkout 到4.2分支。

2.下载AV1  source code 。

git clone https://aomedia.googlesource.com/aom

使用master 分支,remotes/origin/master

3.下载 x264 Source Code

git clone https://code.videolan.org/videolan/x264.git

使用 master 线 remotes/origin/master

4.下载x265 Source Code
hg clone http://hg.videolan.org/x265

 

编译库依赖库:

1.AV1 编译

假设代码位置为/*/aom  。

mkdir aom_build

drwxr-xr-x 19 xw xw 4096 11月 12 15:27 aom/
drwxr-xr-x 9 xw xw 4096 11月 12 19:34 aom_build/

cd aom_build

cmake ../aom 类似如下输出说明configure 成功。

aom_configure: Detected CPU: x86_64
Configuring done
Generating done
Build files have been written to: /mydata/mywork/mycode/media/aom_build

make -j8

sudo make install

2.编译 x264

假设代码存放位置/*../x264

cd x264

./configure –enable-shared –enable-static

make -j8

sudo make install

3.编译x265

假设代码存放位置/*…./x265/

mkdir x265_build

cd x265_build

cmake ../x265

make -j8

sudo make install

4 编译ffmpeg 。

cd ffmpeg

./configure –enable-libx264 –enable-libx265 –enable-libaom –disable-doc –enable-pic –extra-cflags=-fPIC –enable-gpl

make -j8

sudo  make install