From patchwork Sun Jul 21 04:52:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andriy Gelman X-Patchwork-Id: 14014 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id A2D8B447684 for ; Sun, 21 Jul 2019 07:59:33 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7DD6968ABBA; Sun, 21 Jul 2019 07:59:33 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f195.google.com (mail-qt1-f195.google.com [209.85.160.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2FB4068A882 for ; Sun, 21 Jul 2019 07:59:27 +0300 (EEST) Received: by mail-qt1-f195.google.com with SMTP id w17so35158584qto.10 for ; Sat, 20 Jul 2019 21:59:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=d5qwTGnt7K5+b41RzElC4uxgBjH+/w0LjiYBZSEvM6w=; b=W6GS7RUzXlFd0mShyawe68Vtsp7pM46iajAhBmJaak/ysvGNUYFTq5TFflqYXL0E9n OwCy9ok8syRQ9u7w2VK9uYR+cmnPAW/n0fQOC+X8NnH8kxlH7icITgRZRj6Jk+nxVnT6 bxirWxbzbNVxDH4dOwCpqSNc0joaVKD//l9caHVH/xv/ARJ15K0DDwT6CZZSRmYZ9PQR NJCVl/ZBm71p5qecHVfiYGJrk8exy+DxmWiRVSVNDqXgTbCrDl/2BULs0NjZ7WW/QWb6 GEBjRcVGUNQPv1eRY++/jzJEmxiYV3fkiusQGHMU4ijG/+L7LYlMEu5t2ySVG/sUw5sO PjkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=d5qwTGnt7K5+b41RzElC4uxgBjH+/w0LjiYBZSEvM6w=; b=mzOiALVQGjkULBYE4eC+VQWVrHFTZYNzRlBTdOWoXkGkDg9/54xR/y8Mh2vqORyQgM xfrRD/03ek/SYFrHOSoy+DKG5lrQFo+m4skqLD4ca+VXePKbUXh4R3GAo3pZEC8wsZcS NWfxL9H+e872Mftf9mqNAdD2QACDKh0gBGDU2Qh4kwWZXGH+bGF+cMTwmZcV3Ljl6pFK i9g4wOYQ4BcE53lV3T1ZRphb2ZWr9Yl4RevRsW3FN4G0Q6o36Sy/QnabWbBIuhj0h8Ly EiftS8g37qaXhKFHmROnyVOEI38rd6ugyARZ+Z5E8/kwd2QxoLkLnsbs+6oMeCDC65BH hDJw== X-Gm-Message-State: APjAAAVE5FlSw6SSY5AlfS9NWbQOBLaVsV72pgh3om106o47EbnPXiMR I5MKMuKzP7wujjB+GrrDLF7d+3Ik X-Google-Smtp-Source: APXvYqz3u2BU/VvORiW0IJBZiLx+0GlrZVmAM6BEi1Pei6ERDAhvceOgHhBSN/uh0I7plboZ2Bazvg== X-Received: by 2002:aed:2a43:: with SMTP id k3mr45071649qtf.301.1563684777727; Sat, 20 Jul 2019 21:52:57 -0700 (PDT) Received: from localhost.localdomain (c-24-60-253-205.hsd1.ma.comcast.net. [24.60.253.205]) by smtp.gmail.com with ESMTPSA id t29sm14268238qtt.42.2019.07.20.21.52.56 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 20 Jul 2019 21:52:57 -0700 (PDT) From: Andriy Gelman X-Google-Original-From: Andriy Gelman To: ffmpeg-devel@ffmpeg.org Date: Sun, 21 Jul 2019 00:52:36 -0400 Message-Id: <20190721045236.30572-1-andriy.gelman@gmail.com> X-Mailer: git-send-email 2.22.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] hevc_mp4toannexb: Do not duplicate parameter sets X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Andriy Gelman Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Andriy Gelman Fixes #7799 Currently, the mp4toannexb filter always inserts extradata at the start of each IRAP unit. This can lead to duplication of parameter sets if the demuxed packet from mdat atom already contains a version of the parameters. As in ticket #7799 this can also lead to decoding errors when the parameter sets of the IRAP frames are different from the ones stored in extradata. This commit avoids duplicating the parameter sets if they are already present in the demuxed packet. This commit also makes an update to the hevc-bsf-mp4toannexb fate test since the result before this patch contained duplicate vps/sps/pps nal units. --- libavcodec/hevc_mp4toannexb_bsf.c | 9 ++++++++- tests/fate/hevc.mak | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/libavcodec/hevc_mp4toannexb_bsf.c b/libavcodec/hevc_mp4toannexb_bsf.c index 09bce5b34c..5c27306b09 100644 --- a/libavcodec/hevc_mp4toannexb_bsf.c +++ b/libavcodec/hevc_mp4toannexb_bsf.c @@ -123,6 +123,7 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out) int got_irap = 0; int i, ret = 0; + int vps_detected, sps_detected, pps_detected = 0; ret = ff_bsf_get_packet(ctx, &in); if (ret < 0) @@ -146,9 +147,15 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out) nalu_type = (bytestream2_peek_byte(&gb) >> 1) & 0x3f; + switch (nalu_type) { + case HEVC_NAL_VPS: vps_detected = 1; break; + case HEVC_NAL_SPS: sps_detected = 1; break; + case HEVC_NAL_PPS: pps_detected = 1; break; + } + /* prepend extradata to IRAP frames */ is_irap = nalu_type >= 16 && nalu_type <= 23; - add_extradata = is_irap && !got_irap; + add_extradata = is_irap && !got_irap && !(vps_detected && sps_detected && pps_detected); extra_size = add_extradata * ctx->par_out->extradata_size; got_irap |= is_irap; diff --git a/tests/fate/hevc.mak b/tests/fate/hevc.mak index 559c3898bc..4f812b0834 100644 --- a/tests/fate/hevc.mak +++ b/tests/fate/hevc.mak @@ -238,7 +238,7 @@ FATE_HEVC-$(call ALLYES, HEVC_DEMUXER MOV_DEMUXER HEVC_MP4TOANNEXB_BSF MOV_MUXER fate-hevc-bsf-mp4toannexb: tests/data/hevc-mp4.mov fate-hevc-bsf-mp4toannexb: CMD = md5 -i $(TARGET_PATH)/tests/data/hevc-mp4.mov -c:v copy -fflags +bitexact -f hevc fate-hevc-bsf-mp4toannexb: CMP = oneline -fate-hevc-bsf-mp4toannexb: REF = 1873662a3af1848c37e4eb25722c8df9 +fate-hevc-bsf-mp4toannexb: REF = 3c9d998a3aa2b9e0fb1c1f434952bf8b fate-hevc-skiploopfilter: CMD = framemd5 -skip_loop_filter nokey -i $(TARGET_SAMPLES)/hevc-conformance/SAO_D_Samsung_5.bit -sws_flags bitexact FATE_HEVC += fate-hevc-skiploopfilter