[FFmpeg-user] The parameter of bit_rate in video encoding does not work

Li codingpotatolinda at gmail.com
Thu Nov 21 02:33:55 CET 2013


I find the answer on the Internet.

http://stackoverflow.com/questions/11466184/setting-video-bit-rate-through-ffmpeg-api-is-ignored-for-libx264-codec

"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);

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

"

It works!


On Thu, Nov 14, 2013 at 1:41 AM, Li <codingpotatolinda at gmail.com> wrote:

> My program is to decode a video file, process each frame, and encode
> frames back to the output video file.
> I find that the output video file has a large size.
> So I set the bit_rate to be 0.2 of the original bit_rate.
> The code snippet is as follows:
>
> ouVStruct.ouCodecContext->bit_rate = 0.2 *
> inVStruct.inCodecContext->bit_rate;  (or 0.5)
> ------------
> input video file .mp4 (recorded by Nexus 4)
> Video:
>     1280x720
>     H.264/AVC
>     30 frames per second
>     Bitrate: 7974 kbps
> Audio:
>     codec: MPEG-4AAC
>     Channels: Stereo
>     Sample rate: 48000 Hz
>     Bitrate: 96 kbps
> The file size is: 21.2MB
> ------------
> ------------
> output video file .mp4 (processed by my program using ffmpeg)
> Video:
>     1280x720
>     H.264/AVC
>     30 frames per second
>     Bitrate: 25289 kbps
> Audio:
>     codec: MPEG-4AAC
>     Channels: Stereo
>     Sample rate: 48000 Hz
>     Bitrate: 96 kbps
> The file size is: 66.6MB
> ------------
>
> The file is too big for me.
>
> If I use the ffmpeg command to do fps processing (actually the original
> fps is 30 too. So this command is only for test purpose):
> ffmpeg -i VID_2013_output.mp4 -r  30 VID_2013_output_fps30.mp4
>
> The file size is 1.9MB!  Bitrate: 584 kbps
>
>
> Since the ffmpeg command can achieve the purpose (lower the video encoding
> bit rate), where is wrong with my ffmpeg C++ code?
>
> Thanks!
>
>
>
>
>


More information about the ffmpeg-user mailing list