H264视频中的编码图像被跳过和/或丢失

Encoded images into H264 video are skipped and/or missing?

本文关键字:视频 编码 图像 H264      更新时间:2023-10-16

我正在尝试将图像编码为H264 MP4视频。我遇到的问题是,一些图像被跳过,或者在视频的末尾只是丢失了。我需要视频来播放我编码的每一个图像,因为它是一个动画。

如有任何关于正确设置编码器的帮助,我们将不胜感激!

编码器设置:

AVCodecContext *c;
...
c->codec_id = AV_CODEC_ID_H264;
c->bit_rate = mOutputWidth*mOutputHeight*4;//400000;
/* Resolution must be a multiple of two. */
c->width    = mOutputWidth;
c->height   = mOutputHeight;
    /* timebase: This is the fundamental unit of time (in seconds) in terms
     * of which frame timestamps are represented. For fixed-fps content,
     * timebase should be 1/framerate and timestamp increments should be
     * identical to 1. */
c->time_base.den = mFps;
c->time_base.num = 1;
c->gop_size      = 12; /* emit one intra frame every twelve frames at most */
c->pix_fmt       = AV_PIX_FMT_YUV420P;
...
av_dict_set(&pOptions, "preset", "medium", 0);
av_dict_set(&pOptions, "tune", "animation", 0);
/* open the codec */
ret = avcodec_open2(c, codec, &pOptions);
if (ret < 0) {
    LOGE("Could not open video codec: %s", av_err2str(ret));
    return -1;
}

2013年7月24日更新:
通过设置gop_size=FPS并重复写入最后一个视频帧,我能够获得更好的视频。FPS+1次似乎解决了所有问题。对我来说,这样做似乎很奇怪,但可能是视频编码世界的标准?对此有任何提示反馈吗?

据我所知,你有一组图像,你想用它们制作一个视频。如果是这种情况,并且您不关心视频的大小,则可以尝试禁用帧间预测。也许编码器发现有些图像是不需要的,并跳过它们。

可以通过将gop_size设置为0来禁用帧间预测。