[FFmpeg-devel] [PATCH] lavc/hevc: Allow arbitrarily many trailing_zero_8bits after a NAL unit in bytestream format.

Michael Niedermayer michael at niedermayer.cc
Thu Mar 17 14:57:55 CET 2016


On Thu, Mar 17, 2016 at 01:48:37PM +0000, Mark Thompson wrote:
> On 17/03/16 12:30, Hendrik Leppkes wrote:
> > On Thu, Mar 17, 2016 at 1:21 PM, Hendrik Leppkes <h.leppkes at gmail.com> wrote:
> >> On Thu, Mar 17, 2016 at 1:10 PM, Mark Thompson <sw at jkqxz.net> wrote:
> >>>>
> >>>> Wouldn't it be simpler then to add a condition to the existing loop to
> >>>> only error out when no NALs exist?
> >>>
> >>> I apologise if I'm not understanding exactly what you mean, but wouldn't that
> >>> then accept any trailing garbage at all as long as there is one valid NAL unit?
> >>
> >> Yes, it would. From what I can tell, that just how h264 works as well,
> >> and to share code, it could probably even be adjusted to use
> >> avpriv_find_start_code, since the structure of the start codes is
> >> exactly the same.
> >> Decoders should generally be rather forgiving, and if we can decode
> >> one or more NALs from a buffer, then we shouldn't discard all of that
> >> work on account of a few random bytes, IMHO.
> >>
> >> That said, how do these extra zeros even end up being left over? From
> >> what I can tell, ff_hevc_extract_rbsp should consume all data from the
> >> previous start code up to the next one?
> >>
> > 
> > Something I forgot to mention, it would already skip random garbage in
> > between NALs right now, and just error out when its at the end of a
> > buffer. That seems inconsistent, if anything.
> 
> Ok, attached is another version which just allows any garbage you like at the
> end of the packet as long as at least one NAL unit is found.
> 
> Still fixes <https://trac.ffmpeg.org/ticket/5344>.
> 
> Thanks,
> 
> - Mark
> 

>  hevc_parse.c |   10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> daf73b16f8185221a1e8112ab1928157a855fe76  0001-lavc-hevc-Allow-arbitrary-garbage-in-bytestream-as-l.patch
> From 725fb99402fa468e5f11f94e0ec09b2e0c91e6b2 Mon Sep 17 00:00:00 2001
> From: Mark Thompson <mrt at jkqxz.net>
> Date: Thu, 17 Mar 2016 13:41:02 +0000
> Subject: [PATCH] lavc/hevc: Allow arbitrary garbage in bytestream as long as
>  at least one NAL unit is found.
> 
> ---
>  libavcodec/hevc_parse.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/hevc_parse.c b/libavcodec/hevc_parse.c
> index 63ed84a..d557cc7 100644
> --- a/libavcodec/hevc_parse.c
> +++ b/libavcodec/hevc_parse.c
> @@ -232,8 +232,14 @@ int ff_hevc_split_packet(HEVCContext *s, HEVCPacket *pkt, const uint8_t *buf, in
>                  ++buf;
>                  --length;
>                  if (length < 4) {
> -                    av_log(avctx, AV_LOG_ERROR, "No start code is found.\n");
> -                    return AVERROR_INVALIDDATA;
> +                    if (pkt->nb_nals > 0) {
> +                        // No more start codes: we discarded some irrelevant
> +                        // bytes at the end of the packet.
> +                        return 0;

does the case of garbage still print something at some level?
if not, it should. It could be usefull for debuging to know if theres
something funky going on with NAL parsing

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Freedom in capitalist society always remains about the same as it was in
ancient Greek republics: Freedom for slave owners. -- Vladimir Lenin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20160317/fc3ca0a0/attachment.sig>


More information about the ffmpeg-devel mailing list