<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=koi8-r">
<style type="text/css" id="owaParaStyle">P {margin-top:0;margin-bottom:0;}</style>
</head>
<body fpstyle="1" ocsi="0">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">
<div>What i am trying to do is to use a ffmpeg to encode files to a custom codec inside a quicktime container, and i have been using the transcode example as reference
<a href="https://www.ffmpeg.org/doxygen/4.1/transcoding_8c-example.html" rel="noreferrer" target="_blank">
https://www.ffmpeg.org/doxygen/4.1/transcoding_8c-example.html</a></div>
<div>I am able to register the codec, read the packages, and write to the output file as expected.</div>
<div><br>
</div>
<div>The only thing i am dwelling with at the moment is that some codecs (e.g. ProRes) tend to drain the memory usage.<br>
</div>
<div>When transcoding a prores file, looking at the memory profile, i can see that av_interleaved_write_frame() is not freeing the memory allocated during the encoding function.</div>
<div>av_interleaved_write_frame() will start freeing memory just after a <span style="color:rgb(0,0,0); font-family:Tahoma; font-size:13.3333px">
"Delay between the first packet and last packet in the muxing queue is 10004900 > 10000000: forcing output" log, and from that point on memory usage during encode_write_frame() will be steady. In both case, reaching or not the "</span><span style="color:rgb(0,0,0); font-family:Tahoma; font-size:13.3333px"><span style="color:rgb(0,0,0); font-family:Tahoma; font-size:13.3333px">forcing
output"</span> point, all the memory will be freed correctly at the end of the transcoding. The problem is that when using high resolution files (>4K) the app, which is 32bit, will run out of memory before getting to the
</span><span style="color:rgb(0,0,0); font-family:Tahoma; font-size:13.3333px"><span style="color:rgb(0,0,0); font-family:Tahoma; font-size:13.3333px">"</span><span style="color:rgb(0,0,0); font-family:Tahoma; font-size:13.3333px"><span style="color:rgb(0,0,0); font-family:Tahoma; font-size:13.3333px">forcing
output"</span> point.</span> I could notice this behavior with quicktime files only, when using h265 for example,</span><span style="color:rgb(0,0,0); font-family:Tahoma; font-size:13.3333px"> av_interleaved_write_frame() will always free the memory.</span></div>
<div><span style="color:rgb(0,0,0); font-family:Tahoma; font-size:13.3333px"><br>
</span></div>
<div>So if i guess correctly i should find some setting in the muxer to limit memory usage / number of frames in the queue. At the moment i am setting "max_interleave_delta" in the output format context, and it is working fine. I have compared the quicktime
header of files exported with and without the "max_interleave_delta", and the only difference i could spot is that the frame chucks are smaller on the latter, besides of that the files are then playing correctly.
<br>
</div>
<div><br>
</div>
<div>But, is this a correct way to limit the muxer queue? or am i missing some other flag to set in the format context?</div>
<div><br>
</div>
<div>This is a file i am testing with:</div>
<div><br>
</div>
<div>Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:\Users\simone\Videos\bbb_sunflower_2160p_30fps_normal_9sec.mov':<br>
Metadata:<br>
major_brand : qt <br>
minor_version : 537199360<br>
compatible_brands: qt <br>
creation_time : 2019-03-20T13:29:43.000000Z<br>
Duration: 00:00:09.67, start: 0.000000, bitrate: 431795 kb/s<br>
Stream #0:0(eng), 10, 1/30: Video: prores, 1 reference frame (apch / 0x68637061), yuv422p10le(bt709, progressive), 3840x2160, 0/1, 429391 kb/s, SAR 1:1 DAR 16:9, 30 fps, 30 tbr, 30 tbn, 30 tbc (default)<br>
Metadata:<br>
creation_time : 2019-03-20T13:29:43.000000Z<br>
handler_name : Apple Alias Data Handler<br>
encoder : Apple ProRes 422 HQ<br>
timecode : 00:00:00:00<br>
Stream #0:1(eng), 0, 1/48000: Audio: pcm_s16le (sowt / 0x74776F73), 48000 Hz, stereo, s16, 1536 kb/s (default)<br>
Metadata:<br>
creation_time : 2019-03-20T13:29:43.000000Z<br>
handler_name : Apple Alias Data Handler<br>
timecode : 00:00:00:00<br>
Stream #0:2(eng), 0, 1/30: Data: none (tmcd / 0x64636D74), 0/1, 0 kb/s (default)<br>
Metadata:<br>
creation_time : 2019-03-20T13:29:43.000000Z<br>
handler_name : Apple Alias Data Handler<br>
timecode : 00:00:00:00</div>
<div><br>
</div>
<div>Output #0, mov, to 'C:\Users\simone\Videos\bbb_sunflower_2160p_30fps_normal_9sec_AiM.mov':<br>
Codec 0x8024 is not in the full list.<br>
Stream #0:0, 0, 1/30: Video: unknown_codec (aaimv), 1 reference frame (AIVM / 0x4D564941), argb, 3840x2160, 0/1, q=2-31, 200 kb/s, 30 tbn, 30 tbc<br>
Metadata:<br>
encoder : AIM<br>
Stream #0:1, 0, 1/48000: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s<br>
Stream #0:2, 0, 0/0: Unknown: none<br>
</div>
<div><br>
</div>
<div><br>
</div>
<div>Thanks,</div>
<div>Simone.<br>
</div>
<div><br>
</div>
<div style="font-family: Times New Roman; color: #000000; font-size: 16px">
<hr tabindex="-1">
<div id="divRpF742981" style="direction: ltr;"><font size="2" face="Tahoma" color="#000000"><b>From:</b> Libav-user [libav-user-bounces@ffmpeg.org] on behalf of Anton Shekhovtsov [shekh.anton@gmail.com]<br>
<b>Sent:</b> Wednesday, March 20, 2019 10:21 AM<br>
<b>To:</b> This list is about using libavcodec, libavformat, libavutil, libavdevice and libavfilter.<br>
<b>Subject:</b> Re: [Libav-user] 32bit transcoding app running out of memory / setting "max_interleave_delta"<br>
</font><br>
</div>
<div></div>
<div>
<div dir="ltr">
<div dir="ltr"><br>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">ÓÒ, 20 ÍÁÒ. 2019 Ç. × 12:13, Carl Eugen Hoyos <<a href="mailto:ceffmpeg@gmail.com" target="_blank" rel="noopener noreferrer">ceffmpeg@gmail.com</a>>:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
2019-03-20 11:06 GMT+01:00, Simone Donadini <<a href="mailto:Simone.Donadini@avolites.com" target="_blank" rel="noopener noreferrer">Simone.Donadini@avolites.com</a>>:<br>
<br>
> we are developing a 32bit transcoder using ffmpeg based on the<br>
> transcoding example<br>
> <a href="https://www.ffmpeg.org/doxygen/4.1/transcoding_8c-example.html" rel="noreferrer" target="_blank">
https://www.ffmpeg.org/doxygen/4.1/transcoding_8c-example.html</a><br>
> and we are encountering some problem with memory usage<br>
> transcoding files with large resolutions.<br>
<br>
Please run massif (or an equivalent tool) to find out where<br>
the memory allocations happen: Everything else includes<br>
guesswork that can easily be avoided.<br>
<br>
Please provide "ffmpeg -i" output for both input and output<br>
file so we at least know what you are trying to do.<br>
<br>
Carl Eugen<br>
_______________________________________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org" target="_blank" rel="noopener noreferrer">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" rel="noopener noreferrer">libav-user-request@ffmpeg.org</a> with subject "unsubscribe".</blockquote>
<div><br>
</div>
<div><span style="color:rgb(0,0,0); font-family:Tahoma; font-size:13.3333px">"Delay between the first packet and last packet in the muxing queue is 10004900 > 10000000: forcing output"</span></div>
<div>I can be wrong but does this warning tell the packets are coming in wrong order?</div>
<div>If you mux multiple streams (a+v) you should preinterleave streams packets with enough accuracy, otherwise ffmpeg must buffer everything and this is where memory is wasted. </div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>