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