On Tue, Jul 5, 2016 at 11:42 PM, Vittorio Giovara
<[email protected]> wrote:
> From: Hendrik Leppkes <[email protected]>
>
> Some streams contain an additional AnnexB NAL inside the mp4/nalff NALU.
> This commonly occurs in interlaced streams where both fields are packed
> into the same MP4 NAL with an AnnexB startcode in between.
>
> Port handling of this format from the previous h264 nal handling.
>
> Bug-Id: ffmpeg/trac5529
>
> Signed-off-by: Vittorio Giovara <[email protected]>
> ---
> libavcodec/h2645_parse.c | 19 ++++++++++++++++++-
> 1 file changed, 18 insertions(+), 1 deletion(-)
>
> diff --git a/libavcodec/h2645_parse.c b/libavcodec/h2645_parse.c
> index cd7440a..7ae7b80 100644
> --- a/libavcodec/h2645_parse.c
> +++ b/libavcodec/h2645_parse.c
> @@ -200,6 +200,7 @@ int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t
> *buf, int length,
> enum AVCodecID codec_id)
> {
> int consumed, ret = 0;
> + const uint8_t *next_avc = is_nalff ? buf : buf + length;
>
> pkt->nb_nals = 0;
> while (length >= 4) {
> @@ -207,7 +208,7 @@ int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t
> *buf, int length,
> int extract_length = 0;
> int skip_trailing_zeros = 1;
>
> - if (is_nalff) {
> + if (buf >= next_avc) {
> int i;
> for (i = 0; i < nal_length_size; i++)
> extract_length = (extract_length << 8) | buf[i];
> @@ -220,6 +221,7 @@ int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t
> *buf, int length,
> extract_length, length);
> return AVERROR_INVALIDDATA;
> }
> + next_avc = buf + extract_length;
> } else {
> if (buf[2] == 0) {
> length--;
> @@ -228,10 +230,20 @@ int ff_h2645_packet_split(H2645Packet *pkt, const
> uint8_t *buf, int length,
> }
> if (buf[0] != 0 || buf[1] != 0 || buf[2] != 1)
> return AVERROR_INVALIDDATA;
> + else if (buf >= (next_avc - 3))
> + break;
This part isn't quite right, the ffmpeg variant has an inner-loop here
to skip until the next start code, which this break would escape out
of.
Here, it breaks out of the main decoding loop, discarding the
remaining buffer entirely.
>
> buf += 3;
> length -= 3;
> extract_length = length;
> +
> + if (buf == next_avc) {
> + /* skip to the start of the next NAL */
> + int offset = next_avc - buf;
> + buf += offset;
> + length -= offset;
> + continue;
> + }
> }
>
> if (pkt->nals_allocated < pkt->nb_nals + 1) {
> @@ -257,6 +269,11 @@ int ff_h2645_packet_split(H2645Packet *pkt, const
> uint8_t *buf, int length,
> buf[consumed + 2] == 0x01 && buf[consumed + 3] == 0xE0)
> skip_trailing_zeros = 0;
>
> + if (is_nalff && extract_length != consumed && extract_length)
> + av_log(logctx, AV_LOG_DEBUG,
> + "NALFF: Consumed only %d bytes instead of %d\n",
> + consumed, extract_length);
> +
> nal->size_bits = get_bit_length(nal, skip_trailing_zeros);
>
> ret = init_get_bits(&nal->gb, nal->data, nal->size_bits);
> --
> 2.9.0
>
> _______________________________________________
> libav-devel mailing list
> [email protected]
> https://lists.libav.org/mailman/listinfo/libav-devel
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel