通过ffmpeg的API设置视频比特率将被忽略libx264 codeC [英] setting video bit rate through ffmpeg API is ignored for libx264 Codec

查看:1753
本文介绍了通过ffmpeg的API设置视频比特率将被忽略libx264 codeC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用转码FFMPEG API在C code的视频。
我试图用FFmpeg的API来设置视频码率,如下图所示:

I am transcoding a video using FFMPEG API in c code. I am trying to set the video bit rate using the ffmpeg API as shown below:

ovCodecCtx->bit_rate = 100 * 1000;

我使用EN $ C Cr是libx264。

The Encoder I am using is libx264.

但此参数是不考虑效果和生成的视频质量非常糟糕。
我甚至尝试设置相关参数,如rc_min_rate,rc_max_rate等。但视频质量仍然非常低,因为这些相关参数不采取生效。

But this parameter is not taken into effect and the resulting video quality is very bad. I have even tried setting related parameters like rc_min_rate, rc_max_rate, etc.. but the video quality is still very low as these related parameters are not taken into effect.

可以在任何专家告诉了如何使用FFmpeg的API设置正确的比特率?
谢谢

Could any expert tell how one can set the bit rate correctly using the FFMPEG API? Thanks

推荐答案

我已经找到了解决我的问题。事实上谁是面临同样的问题已经有人张贴在的ffmpeg(libav)用户论坛的解决方案。这似乎在我的情况下工作了。我张贴的答案我自己的问题,使面临类似问题的其他用户可能会从这篇文章中受益。

I have found the solution to my problem. In fact somebody who was facing the same problem has posted the solution in ffmpeg(libav) user forum. This seems to work in my case too. I am posting the answer to my own question so that other users facing similar issue might benefit from this post.

问题:

设置视频码率编程的H264视频codeC没有被libx264 codeC荣幸。即使是工作MPEG1,2和MPEG4视频codeCS,该设置未确认为H264视频codeC。所得的视频质量非常糟糕。

Setting the Video Bit Rate programmatically for the H264 Video Codec was not honoured by the libx264 Codec. Even though it was working for MPEG1, 2 and MPEG4 video codecs, this setting was not recognised for H264 Video Codec. And the resulting video quality was very bad.

解决方案:

我们需要设置点为德codeD /帧的大小,他们被送到EN codeR之前。
谁找到了解决办法的人已通过ffmpeg.c来源消失了,能想出解决办法。我们首先需要重新调整从流的基time_base的AVFrame的点到$ C $立方厘米那么time_base得到一个简单的帧号(例如,1,2,3)。

We need to set the pts for the decoded/resized frames before they are fed to encoder. The person who found the solution has gone through ffmpeg.c source and was able to figure this out. We need to first rescale the AVFrame's pts from the stream's time_base to the codec time_base to get a simple frame number (e.g. 1, 2, 3).

pic->pts = av_rescale_q(pic->pts, ost->time_base, ovCodecCtx->time_base);

avcodec_encode_video2(ovCodecCtx, &newpkt, pic, &got_packet_ptr);

而当我们从libx264 codeC收回的EN codeD包,我们需要重新调整PTS和EN codeD视频包的DTS到流时基

And when we receive back the encoded packet from the libx264 codec, we need to rescale the pts and dts of the encoded video packet to the stream time base

newpkt.pts = av_rescale_q(newpkt.pts, ovCodecCtx->time_base, ost->time_base);
newpkt.dts = av_rescale_q(newpkt.dts, ovCodecCtx->time_base, ost->time_base);

感谢

这篇关于通过ffmpeg的API设置视频比特率将被忽略libx264 codeC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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