[Libav-user] Setting the number of B-frames and P-frames

Matteo Foglio foglio.matteo at gmail.com
Thu May 27 17:19:22 EEST 2021

Hello folks,

I am streaming from an rtsp source. It looks like half of the frames
received are key frames. Is there a way to reduce this percentage and have
a higher number of P-frames and B-frames? If possible, I would like to
increase the number of P-frames (not the one of B-frames).
I am using `pyav` which is a Python wrapper for `libav` (`ffmpeg`)


*import av*
*container = av.open(*
*    url, 'r',*
*    options={*
*        'rtsp_transport': 'tcp',*
*        'stimeout': '5000000',*
*        'max_delay': '5000000',*
*    }*
*stream = container.streams.video[0]*
*codec_context = stream.codec_context*
*codec_context.export_mvs = True*
*codec_context.gop_size = 25  *

*for packet in self.container.demux(video=0):*
*    for video_frame in packet.decode():*
*        print(video_frame.is_key_frame)*



And if I print the picture type I see:


It seems that B-frames are disabled: `codec_context.has_b_frames` is `False`

Note 1: I can't edit the camera source. I don't know if that's necessary
but I wanted to mention it. I can just edit the code used to stream the

Note 2: the same solution should apply to `pyav`, `libavi` and `ffmpeg`.

Thank you!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20210527/717b1291/attachment.htm>

More information about the Libav-user mailing list