如何用ffmpeg编写一个显式控制关键帧位置的视频编码器? [英] How to write a video encoder with ffmpeg that explicitly controls the position of keyframes?

查看:170
本文介绍了如何用ffmpeg编写一个显式控制关键帧位置的视频编码器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用ffmpeg编写一个编码器,可以将iFrames(关键帧)放在我想要的位置。在哪里可以找到教程或参考资料?



P.S

可以使用mencoder或任何开源编码器执行此操作。我想编码H263文件。我在&对于linux。

解决方案

您需要查看libavcodec文档,特别是avcodec_encode_video()。我发现最好的文档是ffmpeg头文件和ffmpeg源提供的API示例源代码。具体来说,看看libavcodec / api-example.c甚至ffmpeg.c。



要强制一帧,你需要设置图片的pict_type成员你编码为1:1是一个I帧,2是一个P帧,我不记得我的头顶部的B帧的代码是什么...另外,key_frame成员需要设置到1。



有些介绍材料可用这里这里,但我真的不知道这是多么好。



您需要小心如何分配框架对象API调用需要。在我看来,api-example.c是你最好的选择。寻找功能video_encode_example() - 它的简洁,并说明您需要担心的所有重要的事情 - 特别注意通过一个空的图片参数的avcodec_encode_video()的第二次调用 - 需要获取视频的最后一帧,因为MPEG视频按顺序进行编码,您可能会出现几帧延迟。


I want to write an encoder with ffmpeg which can put iFrames (keyframes) at positions I want. Where can I found tutorials or reference material for it?

P.S
Is it possible to do this with mencoder or any opensource encoder. I want to encode H263 file. I am writing under & for linux.

解决方案

You'll need to look at the libavcodec documentation - specifically, at avcodec_encode_video(). I found that the best available documentation is in the ffmpeg header files and the API sample source code that's provided with the ffmpeg source. Specifically, look at libavcodec/api-example.c or even ffmpeg.c.

To force an I frame, you'll need to set the pict_type member of the picture you're encoding to 1: 1 is an I frame, 2 is a P frame, and I don't remember what's the code for a B frame off the top of my head... Also, the key_frame member needs to be set to 1.

Some introductory material is available here and here, but I don't really know how good it is.

You'll need to be careful how you allocate the frame objects that the API calls require. api-example.c is your best bet as far as that goes, in my opinion. Look for the function video_encode_example() - it's concise and illustrates all the important things you need to worry about - pay special attention to the second call to avcodec_encode_video() that passes a NULL picture argument - it's required to get the last frames of video since MPEG video is encoded out of sequence and you may end up with a delay of a few frames.

这篇关于如何用ffmpeg编写一个显式控制关键帧位置的视频编码器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆