<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body><br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">Hi, I'm using mux.c example to write a file called a.mp4.</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">In order to do this I need to use the write_packet callback.</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">So, in the mux.c example file, after the line 566 I have added these lines of codes:</p>
<br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><strong>566</strong></p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"> /* allocate the output media context */</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"> avformat_alloc_output_context2(&oc, NULL, NULL, filename);</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"> if (!oc) {</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"> printf("Could not deduce output format from file extension: using MPEG.\n");</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"> avformat_alloc_output_context2(&oc, NULL, "mpeg", filename);</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"> }</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"> if (!oc)</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"> return 1;</p>
<br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><strong>// my code</strong></p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">pBuffer= (uint8_t*)av_malloc(BUFFERSIZE);</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">pAVIOContext= avio_alloc_context(pBuffer, BUFFERSIZE, 1, this, nullptr, <strong>write_packet</strong>, nullptr);</p>
<br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><strong>// my code</strong></p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><strong>oc->pb= pAVIOContext;</strong></p>
<br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">After that I have removed the lines</p>
<br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><strong>599</strong></p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"> /* open the output file, if needed */</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"> if (!(fmt->flags & AVFMT_NOFILE)) {</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"> ret = avio_open(&oc->pb, filename, AVIO_FLAG_WRITE);</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"> if (ret < 0) {</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"> fprintf(stderr, "Could not open '%s': %s\n", filename,</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"> av_err2str(ret));</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"> return 1;</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"> }</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"> }</p>
<br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">Now my callback is called but the file produced is different from the one produced by avio_open() (without using the callback).</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">Is my approach correct or have I to use another way in order to use write_packet callback?</p>
<br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><br />-- </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="background-color:#ffffff;"><span style="font-size:-0.083em;"><span style="color:#232629;">+39.347.4070897</span></span></span></p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><a href="http://www.labcsp.com">http://www.labcsp.com</a><span style="color:#232629;"> </span></p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><a href="http://www.denisgottardello.it">http://www.denisgottardello.it</a><span style="color:#232629;"> </span></p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="background-color:#ffffff;"><span style="color:#232629;">GMT+1</span></span></p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="background-color:#ffffff;"><span style="color:#232629;">Skype: mrdebug</span></span></p>
</body>
</html>