On 17/03/16 12:30, Hendrik Leppkes wrote: > On Thu, Mar 17, 2016 at 1:21 PM, Hendrik Leppkes <h.lepp...@gmail.com> wrote: >> On Thu, Mar 17, 2016 at 1:10 PM, Mark Thompson <s...@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
>From 725fb99402fa468e5f11f94e0ec09b2e0c91e6b2 Mon Sep 17 00:00:00 2001 From: Mark Thompson <m...@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; + } else { + av_log(avctx, AV_LOG_ERROR, "No start code is found.\n"); + return AVERROR_INVALIDDATA; + } } } -- 2.7.0
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel