简体   繁体   English

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

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

I'm trying to encode images into an H264 MP4 video. 我正在尝试将图像编码为H264 MP4视频。 The issues I'm having is that some of the images are skipped or at the end of the video simply missing. 我遇到的问题是某些图像被跳过了,或者在视频末尾完全丢失了。 I need the video to play every single image I encode since it is an animation. 我需要视频播放我编码的每个图像,因为它是动画。

Any help setting the encoder properly would be greatly appreciated! 正确设置编码器的任何帮助将不胜感激!

Encoder settings: 编码器设置:

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;
}

Update 07/24/13: 更新13年7月24日:
I was able to achieve a better video by setting the gop_size=FPS and writing the last video frame repeatedly FPS+1 times seemed to resolve all issues. 通过设置gop_size=FPS并重复写入最后一个视频帧FPS+1次,我似乎可以解决所有问题,从而获得更好的视频。 To me it seems odd to do that but might be something standard in the video encoding world? 对我来说,这样做似乎很奇怪,但是在视频编码领域可能是标准的东西吗? Any tips feedback about this? 关于此的任何提示反馈吗?

From what I understand, you have a set of images and you want to make a video out of them. 据我了解,您有一组图像,并且想要用它们制作视频。 If this is the case and you don't care about the size of the video, you can try to disable inter prediction. 如果是这种情况,并且您不关心视频的大小,则可以尝试禁用帧间预测。 Maybe the encoder finds that some of the images are not required and skips them. 也许编码器发现某些图像不是必需的,并跳过了它们。

Inter frame prediction can be disabled by setting gop_size to 0. 可以通过将gop_size设置为0来禁用帧间预测。

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

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