<div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Hello folks, </div><div><br></div><div>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).</div><div>I am using `pyav` which is a Python wrapper for `libav` (`ffmpeg`)</div><div><br></div><div>Code:</div><div><br></div><div><i>import av</i></div><div><i>container = av.open(</i></div><div><i>    url, 'r',</i></div><div><i>    options={</i></div><div><i>        'rtsp_transport': 'tcp',</i></div><div><i>        'stimeout': '5000000',</i></div><div><i>        'max_delay': '5000000',</i></div><div><i>    }</i></div><div><i>)</i></div><div><i>stream = container.streams.video[0]</i></div><div><i>codec_context = stream.codec_context</i></div><div><i>codec_context.export_mvs = True</i></div><div><i>codec_context.gop_size = 25  </i></div><div><i><br></i></div><div><i>for packet in self.container.demux(video=0):</i></div><div><i>    for video_frame in packet.decode():</i></div><div><i>        print(video_frame.is_key_frame)</i></div><div><br></div><div>Output:</div><div><br></div><div><i>True</i></div><div><i>False</i></div><div><i>True</i></div><div><i>False</i></div><div><i>...</i></div><div><br></div><div>And if I print the picture type I see:</div><div><br></div><div><i>I</i></div><div><i>P</i></div><div><i>I</i></div><div><i>P</i></div><div><i>...</i></div><div><br></div>It seems that B-frames are disabled: `codec_context.has_b_frames` is `False`<div><br></div><div>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 video.</div><div><br></div><div>Note 2: the same solution should apply to `pyav`, `libavi` and `ffmpeg`.</div><div><br></div><div><br></div><div>Thank you!</div><div><br></div><div>Matteo</div><div><br></div></div></div></div>