[Libav-user] Setting libx264 bitrate via API
jettoblack
jettoblack at gmail.com
Sun Aug 5 06:40:06 CEST 2012
After digging through ffmpeg.c, I finally figured it out.
My code was sending pictures into the encoder using a pts in the stream's
time_base of 1/90000 (e.g. 3003, 6006, 9009). The solution was 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, enc->time_base);
avcodec_encode_video2(enc, &newpkt, pic, &got_packet_ptr);
Then when a packet is received from the encoder, you need to rescale pts and
dts back to the stream time_base.
newpkt.pts = av_rescale_q(newpkt.pts, enc->time_base, ost->time_base);
newpkt.dts = av_rescale_q(newpkt.dts, enc->time_base, ost->time_base);
av_interleaved_write_frame(out, &newpkt);
I guess not every codec requires this to be done, but libx264 does if you
want to encode CBR/ABR.
--
View this message in context: http://libav-users.943685.n4.nabble.com/Setting-libx264-bitrate-via-API-tp4655453p4655531.html
Sent from the libav-users mailing list archive at Nabble.com.
More information about the Libav-user
mailing list