<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
 I did some digging and found the error is coming from this code in flvenv.c line 921.
<div><br>
</div>
<div>  if (pkt->dts < -flv->delay) {</div>
<div>        av_log(s, AV_LOG_WARNING,</div>
<div>               "Packets are not in the proper order with respect to DTS\n");</div>
<div>        return AVERROR(EINVAL);</div>
<div><br>
</div>
<div>flv is a pointer to  FLVContext from AVFormatContext->priv_data.<br>
</div>
<div><br>
</div>
<div>Looks like the avformat_write_header()/avformat_init_output uses the state of the muxer at the last run even if the AVFormatContext has been freed and reallocated.</div>
So how do I get the FLVContext to be initlized as if a fresh run. Or how do I free the old FLVContext so when avformat_write_header() initlizes the priv_data it is fresh.<br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Libav-user <libav-user-bounces@ffmpeg.org> on behalf of william keeling <WilliamKeeling@hotmail.com><br>
<b>Sent:</b> Monday, March 1, 2021 2:32 PM<br>
<b>To:</b> libav-user@ffmpeg.org <libav-user@ffmpeg.org><br>
<b>Subject:</b> [Libav-user] Reuse of format context after free and reallocate?</font>
<div> </div>
</div>
<style type="text/css" style="display:none">
<!--
p
        {margin-top:0;
        margin-bottom:0}
-->
</style>
<div dir="ltr">
<p class="x_MsoNormal" style="margin:0in 0in 8pt; line-height:107%; font-size:11pt; font-family:Calibri,sans-serif">
I have a program the creates flash format stream and is work the first time thru but when I process the second stream, I get DTS/PTS non monotonically errors. </p>
<p class="x_MsoNormal" style="margin:0in 0in 8pt; line-height:107%; font-size:11pt; font-family:Calibri,sans-serif">
After each stream I free and reallocate all contexts: </p>
<p class="x_MsoNormal" style="margin:0in 0in 8pt; line-height:107%; font-size:11pt; font-family:Calibri,sans-serif">
avcodec_free_context() of all streams video and audio </p>
<p class="x_MsoNormal" style="margin:0in 0in 8pt; line-height:107%; font-size:11pt; font-family:Calibri,sans-serif">
avformat_free_context() </p>
<p class="x_MsoNormal" style="margin:0in 0in 8pt; line-height:107%; font-size:11pt; font-family:Calibri,sans-serif">
avio_close() </p>
<p class="x_MsoNormal" style="margin:0in 0in 8pt; line-height:107%; font-size:11pt; font-family:Calibri,sans-serif">
 </p>
<p class="x_MsoNormal" style="margin:0in 0in 8pt; line-height:107%; font-size:11pt; font-family:Calibri,sans-serif">
What am I missing so the format context can be reallocate and used? </p>
<p class="x_MsoNormal" style="margin:0in 0in 8pt; line-height:107%; font-size:11pt; font-family:Calibri,sans-serif">
 </p>
<p class="x_MsoNormal" style="margin:0in 0in 8pt; line-height:107%; font-size:11pt; font-family:Calibri,sans-serif">
Thanks William </p>
</div>
</body>
</html>