繁体   English   中英

跳过和/或丢失了编码为H264视频的编码图像吗?

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

我正在尝试将图像编码为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;
}

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM