首页 > 解决方案 > 解码/编码 mp4 视频时丢弃 P 帧

问题描述

我正在使用 ffmpeg(libAV 库)+ libx264 编码器解码/编码相同的 mp4(视频/mp4)文件。例如,原始视频文件包含 182 帧:

[libx264 @ 0x7fb4a843ce00] frame I:2     Avg QP:17.95  size: 13834
[libx264 @ 0x7fb4a843ce00] frame P:180   Avg QP:19.90  size:  6297

但在followig解码/编码之后,我得到的文件包含181帧:

[libx264 @ 0x7fb4ac421dc0] frame I:2     Avg QP:17.93  size: 13627
[libx264 @ 0x7fb4ac421dc0] frame P:179   Avg QP:19.77  size:  5946

我已经尝试更改 AVCodecContext gop_size/max_b_frames/priv_data (profile, preset, tune, x264opts) 并且我也阅读了这些帖子并试图解决我的问题:

从 MP4 压缩到 MP4 (libx264) 时 ffpmeg 丢弃最后一帧

ffmpeg/libx264 C API:从短 MP4 末尾丢弃的帧

UPD:如果我设置帧速率和时基 = 26/1 和 1/26 及更多 - 帧不会丢失。

UPD2:已解决!

//in function avformat_open_input() add AVDictionary *options:
av_dict_set(&options, "r", "25", 0);
av_dict_set(&options, "ignore_editlist", "1", 0);

我期望使用所有帧解码/编码视频(不更改参数)。

标签: ffmpegframeencodemp4libx264

解决方案


推荐阅读