mplex drops last access unit / frame from input video stream
Darrell Walisser <[email protected]> Fri, 8 Aug 2014 12:24:55 -0400
| Newsgroups | gmane.comp.video.mjpeg.devel |
|---|---|
| Message-ID | <CAPDU3-LzQFvnmLAq23Jx6JhiVrSXWDwpUT1sWwLL2cawBfuh_Q@mail.gmail.com> |
--===============8558167146164398847==
Content-Type: multipart/alternative; boundary=20cf303bfaa64a8c7a050020a536
--20cf303bfaa64a8c7a050020a536
Content-Type: text/plain; charset=UTF-8
I posted this to mjpeg-users yesterday but it shows a blank message in the
archives? Anyways I did some more hacking on the source code and it seems
like there is a condition where if the next AU causes an end-of-stream
condition, it will not necessarily be pushed into the access unit buffer,
(because eoscan is set to true) and subsequently gets left out of the
output.
The fix is to ensure it gets added in this case. It seems to do the right
thing, but I will let you decide if this is the correct way to fix it.
-------------------------------
diff -ru -U 10 mjpegtools-2.0.0/mplex/videostrm_in.cpp
mjpegtools/mplex/videostrm_in.cpp
--- mjpegtools-2.0.0/mplex/videostrm_in.cpp 2005-12-09 15:05:26 -0500
+++ mjpegtools/mplex/videostrm_in.cpp 2014-08-08 11:25:25 -0400
@@ -307,20 +307,43 @@
old_frames = decoding_order;
}
break;
}
}
+ // make sure the last AU gets added at the end of the stream
+ if (bs.eos() && AU_pict_data)
+ {
+ stream_length = bs.bitcount();
+ access_unit.start = AU_start;
+ access_unit.length = static_cast<int>(stream_length - AU_start)>>3;
+ access_unit.end_seq = 0;
+ avg_frames[access_unit.type-1]+=access_unit.length;
+
+ mjpeg_debug( "LAST AU %d %d %d @ %lld: DTS=%ud",
+ decoding_order,
+ access_unit.type,
+ access_unit.length,
+ bs.bitcount() / 8-4,
+ static_cast<unsigned int>(access_unit.DTS/300) );
+ aunits.Append( access_unit );
+ decoding_order++;
+ AU_hdr = syncword;
+ AU_start = stream_length;
+ AU_pict_data = 0;
+ }
+
last_buffered_AU = decoding_order;
num_pictures = decoding_order;
eoscan = bs.eos() || muxinto.AfterMaxPTS(access_unit.PTS);
}
void VideoStream::Close()
{
unsigned int comp_bit_rate ;
unsigned int peak_bit_rate ;
---------------------------
--20cf303bfaa64a8c7a050020a536
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div><br></div><div>I posted this to mjpeg-users yesterday=
but it shows a blank message in the archives? Anyways I did some more hack=
ing on the source code and it seems like there is a condition where if the =
next AU causes an end-of-stream condition, it will not necessarily be pushe=
d into the access unit buffer, (because eoscan is set to true) and subseque=
ntly gets left out of the output.</div>
<div><br></div><div>The fix is to ensure it gets added in this case. It see=
ms to do the right thing, but I will let you decide if this is the correct =
way to fix it.</div><div><br></div><div><div>------------------------------=
-</div>
<div>diff -ru -U 10 mjpegtools-2.0.0/mplex/videostrm_in.cpp mjpegtools/mple=
x/videostrm_in.cpp</div><div>--- mjpegtools-2.0.0/mplex/videostrm_in.cpp =
=C2=A0 =C2=A0 2005-12-09 15:05:26 -0500</div><div>+++ mjpegtools/mplex/vide=
ostrm_in.cpp =C2=A0 2014-08-08 11:25:25 -0400</div>
<div>@@ -307,20 +307,43 @@</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 o=
ld_frames =3D decoding_order;</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }</div><div><br></div><div=
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 break;</div><div><br></div><div><br></div>
<div><br></div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
}</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 }</div><div><br></div><div>+ =C2=
=A0 =C2=A0// make sure the last AU gets added at the end of the stream</div=
><div>+ =C2=A0 =C2=A0if (bs.eos() && AU_pict_data)</div><div>+ =C2=
=A0 =C2=A0{</div>
<div>+ =C2=A0 =C2=A0 =C2=A0 =C2=A0stream_length =3D bs.bitcount();</div><di=
v>+ =C2=A0 =C2=A0 =C2=A0 =C2=A0access_unit.start =3D AU_start;</div><div>+ =
=C2=A0 =C2=A0 =C2=A0 =C2=A0access_unit.length =3D static_cast<int>(st=
ream_length - AU_start)>>3;</div><div>+ =C2=A0 =C2=A0 =C2=A0 =C2=A0ac=
cess_unit.end_seq =3D 0;</div>
<div>+ =C2=A0 =C2=A0 =C2=A0 =C2=A0avg_frames[access_unit.type-1]+=3Daccess_=
unit.length;</div><div>+</div><div>+ =C2=A0 =C2=A0 =C2=A0 =C2=A0mjpeg_debug=
( "LAST AU %d %d %d @ %lld: DTS=3D%ud",</div><div>+ =C2=A0 =C2=A0=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 decoding_order,</d=
iv><div>+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 access_unit.type,</div>
<div>+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 access_unit.length,</div><div>+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 bs.bitcount() / 8-4,</div><div>+ =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 static_cast<=
unsigned int>(access_unit.DTS/300) );</div><div><br></div><div><br></div=
>
<div>+ =C2=A0 =C2=A0 =C2=A0 =C2=A0aunits.Append( access_unit );</div><div>+=
=C2=A0 =C2=A0 =C2=A0 =C2=A0decoding_order++;</div><div>+ =C2=A0 =C2=A0 =C2=
=A0 =C2=A0AU_hdr =3D syncword;</div><div>+ =C2=A0 =C2=A0 =C2=A0 =C2=A0AU_st=
art =3D stream_length;</div><div>+ =C2=A0 =C2=A0 =C2=A0 =C2=A0AU_pict_data =
=3D 0;</div><div>+ =C2=A0 =C2=A0}</div>
<div>+</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 last_buffered_AU =3D decoding_=
order;</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 num_pictures =3D decoding_orde=
r;</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 eoscan =3D bs.eos() || muxinto.Aft=
erMaxPTS(access_unit.PTS);</div><div>=C2=A0}</div><div><br></div><div>
=C2=A0void VideoStream::Close()</div><div>=C2=A0{</div><div>=C2=A0 =C2=A0 =
=C2=A0unsigned int comp_bit_rate ;</div><div>=C2=A0 =C2=A0 =C2=A0unsigned i=
nt peak_bit_rate =C2=A0;</div></div><div><br></div><div>-------------------=
--------</div><div><br></div><div><br></div>
</div>
--20cf303bfaa64a8c7a050020a536--
--===============8558167146164398847==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
--===============8558167146164398847==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Mjpeg-developer mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mjpeg-developer
--===============8558167146164398847==--