<div dir="ltr"><div dir="ltr"><br></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Feb 4, 2022 at 10:05 AM Francesco Taioli <<a href="mailto:taioli.francesco98@gmail.com">taioli.francesco98@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hi all,</div><div>I have a performance problem regarding image acquisition from a <br></div><div>large number of cameras (they are greater than 100) in a <b>python</b> program.</div><div>Currently, I use cv2 with a ffmpeg pipeline.<br></div><div><br></div><div><b>What I want to do</b></div><div>I want to do some image processing on those cameras multiple times in a minute. <br></div><div><br></div><div><b>Current solution - pseudocode</b><br></div><div><pre><code><span>while</span> <span>True</span>:
    <span>for</span> every rtsp_cameras_connection_params:
        <b>open_connection</b>
        read_current_frame # the real time frame
        process_frame
        close connection</code></pre></div><div>This solution works, but opening the connection takes a lot of time.</div><div><br></div><div><b>Why do you open the connection inside the loop, you may ask?</b></div><div>As far as I know and I have tried, this is the only solution that allows me <br></div><div>to fetch the LAST frame from a camera (the real time frame, no buffer) without <br></div><div>givingĀ  performance issues for the powerful high-end server that this code runs on.</div><div><br></div><div><b>What do I want?</b></div><div>Ideally, this</div><div><pre><code><span>open_all_the_cameras</span></code></pre></div><div><pre><code><span>while</span> <span>True</span>:
    <span>for</span> every rtsp_camera_already_opened:
        read_current_frame # the real time frame
        process_frame
<br></code></pre><div>As you can see, the ideal solution is to open <b>once</b> all the cameras</div><div>and save them into an array. Then, at every loop, read the last frame.</div><div><br></div><div><b>What have I tried?</b><br></div><pre><code></code></pre></div><div>Basically every solution. <b>Multithreading</b>, <b>multiprocessing,</b> and every <br></div><div>stackoverflow answers. These solutions work only for a limited amount of cameras (10-15),</div><div>then the CPU will be 100% on usage (because the threads, in the background, are <br></div><div>always reading the last frame and discarding it if I am not asking the last).</div><div><br></div><div>There is a way to open the connection, and read the last frame (the real time one),</div><div>not the one that I was before (the buffered one)?</div><div><br></div><div>Thanks to all. Hope it's clear.<br></div></div>
_______________________________________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
<a href="https://ffmpeg.org/mailman/listinfo/libav-user" rel="noreferrer" target="_blank">https://ffmpeg.org/mailman/listinfo/libav-user</a><br>
<br>
To unsubscribe, visit link above, or email<br>
<a href="mailto:libav-user-request@ffmpeg.org" target="_blank">libav-user-request@ffmpeg.org</a> with subject "unsubscribe".<br>
</blockquote></div><div><br></div><div>Hello Francesco,</div><div><br></div><div>If you are using av_read_frame to retrieve a AVPacket* structure it is nearly cost free to do av_packet_unref() if you don't need that packet. Decoding is what takes the majority of the time, ie from AVPacket -> AVFrame. Decoding 100 streams is costly and can be done on a GPU if you can spare one. You would also need to make sure that on a set interval you are decoding full GOPs as one packet may not contain full information to decode a frame that you need. Maybe you can set buffer size in the input parameters while opening the connection, here is the example for UDP</div><div><br></div><div><div style="line-height:19px"><div style="">udp://localhost:8888?overrun_nonfatal=1&buffer_size=524288000?fifo_size=2788766<br></div></div></div><div dir="ltr" class="gmail_signature"><br>Regards<br>Strahinja Radman</div></div>