音视频编辑相关信息收集

FFmpeg
website

ffmpeg  -y -loglevel level+error -vcodec h264 -r 15  -i "in.h264" -vcodec h264  -fpsmax 15 -b:v 1M "out.mp4"
ffmpeg -y -vcodec h264 -r 15 -i in.h264 -vcodec h264 -fpsmax 15 -b:v 1M -filter:v "setpts=15.0*PTS" -preset ultrafast out.mp4

-c:v 用于指定视频编码,-c:a 指定音频编码 -c:v copy 表示复制输入文件中的视频流到输出文件,不重新进行编码
-b:v 用于指定视频的比特率。 -r 15 选项用于指定输出视频的帧率为 15 FPS。
-c:v libx264

-filter:v fps=15

改变视频播放速度(音频不受影响)
$ ffmpeg -i input.mp4 -vf "setpts=0.5*PTS" output.mp4

上述命令会加快视频画面的播放速度,音频播放速度不变。

如果想放慢视频画面的切换速度,可以相应地将 setpts=0.5*PTS 中的 0.5 改为大于 1 的数值。

// 稍微增加点文件大小,编码速度提升很多
-preset ultrafast

// 查看信息
ffmpeg -i bbb.mp4 -hide_banner

// 去掉 ffmpeg 的版本和编译信息
-hide_banner

// 查看信息
ffprobe -show_streams -i out.mp4

调整视频速率
调整视频速率的原理为:修改视频的 presentation timestamp (PTS),dts

调整音频速率
调整视频速率的原理为:简单的方法是调整音频采样率,但是这种方法会改变音色, 一般采用通过对原音进行重采样,差值等方法。

ffmpeg -i in.mkv -filter:a "atempo=2.0" -vn out.mkv


h264 结构相关

H264结构中,一个视频图像编码后的数据叫做一帧,一帧由一个片(slice)或多个片组成,一个片由一个或多个宏块(MB)组成。

H264在网络传输的是NALU,NALU的结构是:NAL头+RBSP

tbn tbc tbr

There are three different time bases for time stamps in FFmpeg. The
values printed are actually reciprocals of these, i.e. 1/tbr, 1/tbn and
1/tbc.

tbn is the time base in AVStream that has come from the container, I
think. It is used for all AVStream time stamps.

tbc is the time base in AVCodecContext for the codec used for a
particular stream. It is used for all AVCodecContext and related time
stamps.

tbr is guessed from the video stream and is the value users want to see
when they look for the video frame rate, except sometimes it is twice
what one would expect because of field rate versus frame rate.