From patchwork Sat Sep 29 07:43:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fu, Linjie" X-Patchwork-Id: 10514 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:1296:0:0:0:0:0 with SMTP id 22-v6csp620346jap; Sat, 29 Sep 2018 00:43:49 -0700 (PDT) X-Google-Smtp-Source: ACcGV613isC8+imybSkj3ITJrmt6FBig6VdxZ6Lg5SSKCPa9jrYqXfbLg+7crqrs+1ilNW4GVhQ5 X-Received: by 2002:a1c:1d58:: with SMTP id d85-v6mr3980684wmd.142.1538207029477; Sat, 29 Sep 2018 00:43:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538207029; cv=none; d=google.com; s=arc-20160816; b=x7w4/j1ywSK49gHBdxKRXbz5CByzAqvZD7/xwJ3lXtynSq3pGqHrtWe7EOHDLZtj3R M8gdA+AuQpes+QsCBDp7inkm0R6q0ITso23yAIGHjSY43ADjvAIF5efS7QxeVcOVlMLh iQJMFnjGrFCEWcJWhB04HjG/XDuk5iW9MLUVHSUHYD2RxylfK949hqVP4xBhSjM2AieV SP2rhUDoHlMGKJweUY4kRMYpVfHkFg2VKfhs1GGl7n26Jbk3gFamGRBwUwWIpWxo/n6B f/CGcVowd6k9W5QZcNVzvRctGoN0+zp4TEJJGd2qnrYYdlaCDmp4iDdxZnRV9ey2TO25 Ym7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:delivered-to; bh=b09GFYqpUtZrkRx/XWS0wE+RxNRzQUXAxTTQAHWr8uM=; b=lZwxjUTXvP4XfcHNCZgWo9Hw/KPQrC+dpP3oijm1WMmec+ji6BVROPWACTyov6r9nX A8N/SPBtuSczPUxlJbISQ5mueQgbvKycieNFCmzU4HP1pptvtCvLem6mMgYOYRAkxqSw u2hpPztSsJgw4U0ksTx6GO4WiegJisb28030L4QqLJDlG/UPCdzWpMTIG7emZ/0LG5QX FJdwCAzfYOkljv00C3yBJbRoeCgwHLlvNb1BHiEoGzssbaTLnjT336jTf1INzQumbxGF ZbOYpuOUVXryhhlwumDChEN6yxHMD7XoAL1CwWS5hdIZ7pEJl0AtHCVZqlymZ+nigWoo l78w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id y204-v6si3458109wme.33.2018.09.29.00.43.48; Sat, 29 Sep 2018 00:43:49 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4177C689E81; Sat, 29 Sep 2018 10:43:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 143826883A0 for ; Sat, 29 Sep 2018 10:43:21 +0300 (EEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Sep 2018 00:43:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,318,1534834800"; d="scan'208";a="74037169" Received: from kubernetes-master.sh.intel.com ([10.239.159.161]) by fmsmga007.fm.intel.com with ESMTP; 29 Sep 2018 00:43:36 -0700 From: Linjie Fu To: ffmpeg-devel@ffmpeg.org Date: Sat, 29 Sep 2018 15:43:26 +0800 Message-Id: <20180929074326.7207-1-linjie.fu@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH V3] avcodec/h264_mp4toannexb_bsf: extract extradata for first coming frame 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: Linjie Fu MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Add "new_nal_slice" to indicate the first coming nal_slice (including H264_NAL_IDR_SLICE and H264_NAL_SLICE) Extract extradata of streams when the first nal_slice comes, not only H264_NAL_IDR_SLICE but also H264_NAL_SLICE. This patch aims at the following issues: 1. the IDR frame is missing in the first GOP of a stream (common in live stream, IDR.No.Inband.SPPS.mkv in ticket #6418) 2. there is no IDR frame in the input stream. (No.Inband.SPPS.No.IDR.mkv in ticket #6418) Both clips could be decoded successfully using software decoding but had problems in hwaccel using qsv before applying the patch. V3: modified the commit message and the code duplication. Signed-off-by: Linjie Fu --- libavcodec/h264_mp4toannexb_bsf.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libavcodec/h264_mp4toannexb_bsf.c b/libavcodec/h264_mp4toannexb_bsf.c index fb3f24ea40..8dd9159b22 100644 --- a/libavcodec/h264_mp4toannexb_bsf.c +++ b/libavcodec/h264_mp4toannexb_bsf.c @@ -33,6 +33,7 @@ typedef struct H264BSFContext { int32_t pps_offset; uint8_t length_size; uint8_t new_idr; + uint8_t new_nal_slice; uint8_t idr_sps_seen; uint8_t idr_pps_seen; int extradata_parsed; @@ -236,13 +237,17 @@ static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out) if (!s->new_idr && unit_type == H264_NAL_IDR_SLICE && (buf[1] & 0x80)) s->new_idr = 1; - /* prepend only to the first type 5 NAL unit of an IDR picture, if no sps/pps are already present */ - if (s->new_idr && unit_type == H264_NAL_IDR_SLICE && !s->idr_sps_seen && !s->idr_pps_seen) { + /* prepend to the first type 5 NAL unit of an IDR picture, + * or the first type 1 NAL unit of an IDR missing picture, + * if no sps/pps are already present */ + if (s->new_idr && !s->idr_sps_seen && !s->idr_pps_seen + && (unit_type == H264_NAL_IDR_SLICE || (!s->new_nal_slice && H264_NAL_SLICE == unit_type))) { if ((ret=alloc_and_copy(out, ctx->par_out->extradata, ctx->par_out->extradata_size, buf, nal_size, 1)) < 0) goto fail; s->new_idr = 0; + s->new_nal_slice = 1; /* if only SPS has been seen, also insert PPS */ } else if (s->new_idr && unit_type == H264_NAL_IDR_SLICE && s->idr_sps_seen && !s->idr_pps_seen) { if (s->pps_offset == -1) {