<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
{mso-style-priority:34;
margin-top:0cm;
margin-right:0cm;
margin-bottom:0cm;
margin-left:36.0pt;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
/* List Definitions */
@list l0
{mso-list-id:1842155966;
mso-list-type:hybrid;
mso-list-template-ids:417387080 67698703 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}
@list l0:level1
{mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l0:level2
{mso-level-number-format:alpha-lower;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l0:level3
{mso-level-number-format:roman-lower;
mso-level-tab-stop:none;
mso-level-number-position:right;
text-indent:-9.0pt;}
@list l0:level4
{mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l0:level5
{mso-level-number-format:alpha-lower;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l0:level6
{mso-level-number-format:roman-lower;
mso-level-tab-stop:none;
mso-level-number-position:right;
text-indent:-9.0pt;}
@list l0:level7
{mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l0:level8
{mso-level-number-format:alpha-lower;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l0:level9
{mso-level-number-format:roman-lower;
mso-level-tab-stop:none;
mso-level-number-position:right;
text-indent:-9.0pt;}
ol
{margin-bottom:0cm;}
ul
{margin-bottom:0cm;}
--></style></head><body lang=EN-GB link=blue vlink="#954F72"><div class=WordSection1><p class=MsoNormal>>From: BIGLER Don (Framatome)</p><p class=MsoNormal>>Sent: 27 February 2019 14:55</p><p class=MsoNormal>>To: libav-user@ffmpeg.org</p><p class=MsoNormal>>Subject: [Libav-user] Multithreaded Asynchronous Encoding/Muxing</p><p class=MsoNormal>><o:p> </o:p></p><p class=MsoNormal>>All,</p><p class=MsoNormal>><o:p> </o:p></p><p class=MsoNormal>>I am writing an application that displays, encodes, and muxes live video using libav as the backend. The audio and video encoding occurs asynchronously in the background, each in its own thread, such that the encoded packets arrive to the </p><p class=MsoNormal>>av_interleaved_write_frame() function call at different times. H.264 video encoding by itself works fine. However when I add audio, the audio is out of sync from the video even though the audio and video pts are in sync (from avdevice </p><p class=MsoNormal>>using >the matroska muxer). The cause of the problem is not clear to me. Specifically, here are my questions:</p><p class=MsoNormal>><o:p> </o:p></p><p class=MsoNormal>>1. Can the av_interleaved_write_frame() function handle multithreaded asynchronous calls for audio and video streams? </p><p class=MsoNormal>>2. The transcoding example uses a filter graph using buffer/abuffer filters. My current implementation does not use the buffer/abuffer filters because I am not applying any filters before encoding. Are they required for my situation?</p><p class=MsoNormal>>3. The encoding happens randomly within the stream such that the first pts received by the muxer is not zero. Is this required?</p><p class=MsoNormal>><o:p> </o:p></p><p class=MsoNormal>>I will greatly appreciate any assistance!</p><p class=MsoNormal>><o:p> </o:p></p><p class=MsoNormal>>Regards,</p><p class=MsoNormal>>Don Bigler<span lang=EN-US style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:"Arial",sans-serif'><o:p> </o:p></span></p><p class=MsoNormal>Hi Don,<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I don’t think that av_interleaved_write_frame() is thread safe. What you could do is gather video and audio in a thread safe queue, possibly order the packets, and then in separate thread send from that queue to the av_interleaved_write_frame(). For me this works fine. <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Kind regards,<o:p></o:p></p><p class=MsoNormal>Strahinja <o:p></o:p></p></div></body></html>