From patchwork Thu Aug 17 11:54:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vittorio Giovara X-Patchwork-Id: 4731 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.46.211 with SMTP id u202csp1874880vsu; Thu, 17 Aug 2017 05:01:13 -0700 (PDT) X-Received: by 10.223.179.211 with SMTP id x19mr3446394wrd.7.1502971272951; Thu, 17 Aug 2017 05:01:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502971272; cv=none; d=google.com; s=arc-20160816; b=mqAGOs6/OSMSue/oUztYp2z+NjrffDPUF4v4moPP7ouq1/KbiSw8VeeS/UXDhw71W9 PLTlNMgj9perUG1DWJ0dNItvcfbTEh2uGgCfniezeW6SgTSJwSEpDiJEMLJyPQHZ/wAm 5FoaBC9IgJT/K5Yhinlr7lXd/9s5JmeTtjqG/Xg5f/TeoAIf0GpY4J0x/VzizQAf6NU3 5j6SkspgJXMOgIe9+HDFR27ukB8u/2ob1cKKhzsBtn5dY+NWqV6mTxzDEuXR9QDKCHSe iyc+mtUsJsrsbExhv/IVzxjFjw5+Y/LzNNZjrjQlOejDXpUwphMUT/bh7YCI5aq2ySo9 qk6A== 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:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=yj25GvQhBlD8xpP9o3e4ubgw5LSwAn+yzLmz6bfDODc=; b=l6aZUE79C7+DVOGbAbAOqSj9i2E+jD1VdgrycWJ6LegGFzLv3lenduxrHhDb7Qmp6F WzlYXRQbj+tRJVAPSJGyYv/Sbf1yroanBfLSVM4QtCjWruHM9GKidM2Cz71o3nONXdVd bVeVV2X1jYE3HXqa3uu0OvmeIZww4EKE0c37XN2VyLhpuOz1R95MNv2q8kx8609L09NK D5drOQ986QaIQqt+PKTo5P6bhiJynr+0/OpRq9YSm156hcATILPSfucy81sEV+vF5hOV e/GF6ylqJRURJpmwjiOkXSEW6l0Q7+Ed3JMHi5bq3P+nkFS3d6AFuqoyjGXJaX3yEVCU Frtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=oYFlv6Ys; 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=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 34si2339080wrs.352.2017.08.17.05.01.11; Thu, 17 Aug 2017 05:01:12 -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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=oYFlv6Ys; 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=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2CD256899BE; Thu, 17 Aug 2017 15:01:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f195.google.com (mail-wr0-f195.google.com [209.85.128.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3FB696882E2 for ; Thu, 17 Aug 2017 15:00:56 +0300 (EEST) Received: by mail-wr0-f195.google.com with SMTP id y67so8051775wrb.3 for ; Thu, 17 Aug 2017 05:01:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=Bz83RiQZbE87E3o2ux1GZ7FB11vugy9ADj02Qne+YJA=; b=oYFlv6YskSJ6lN7ceV53Ot2YVV9sB4iz+QmVdaXt1FMfk9KRFquYckZm2oezRw87C4 nK9IdP6KLHsrJmdpInJeygPawt8TeglmLW9myLIUF5TSzGjH1tCnz7YW3Qd3PsbHEto6 dDv6dy5X6LOiX1MyINOORmAsgNsnuAOKfzTkZkcOG5TZyaIX34sTl9JPidUXKCGetmHk ibbUkUO9lnwfCFEcoEfi35m0kEu97RMZHF8ym65HUz0d7RBvDfeWdC63jwMpUeKnpRcL D1A7/j7siLLSiWIBbOk7Bk3+afEkCfWTMf2x9v+nKBvpeTdFep/n9KR3QTd3BejdQqfH 3uzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=Bz83RiQZbE87E3o2ux1GZ7FB11vugy9ADj02Qne+YJA=; b=h+TTECJLr9nh7wLm0NtZZBndx7Dwq6G7M6biXGtjwyBJ0Y7jhZ8pRyZFvvYetzw4wf EJvAIf+MudMI+cEI2IqeUEY26qi0SFikYPkXi0ujl+7mgJ9HHLFB0ytEAvrgXU2WqWNS QINRCR9C/u9lhyfxm91bwYOXXbYZoEON/hBTSh1alNcxx4vFdrB9HzjuEy1mSSVCCph8 qj3yoTrSooI6T5XQUQ+LQyyp0k73H+AoKinssVXVF4gLr7eS2VJpuowXuMbD0IJ4zh8G IAkqd98NtIZKAUsbZ7MVHq+60wR61TvbU+p2tSVpwY6JJV0SR8n6M0tJGoYmywxM2D5p NXCQ== X-Gm-Message-State: AHYfb5gXemy8WfVTSExf6dp5kGQOyzGFVC5amkYo7cD2lK+mivZIUIIQ MiIRUWLPr51jtqNUvcs5CA== X-Received: by 10.28.113.203 with SMTP id d72mr1162679wmi.109.1502970885824; Thu, 17 Aug 2017 04:54:45 -0700 (PDT) Received: from vimacbookpro.vimeows.com ([151.82.53.2]) by smtp.gmail.com with ESMTPSA id l131sm4236078wmb.5.2017.08.17.04.54.43 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 17 Aug 2017 04:54:44 -0700 (PDT) From: Vittorio Giovara To: ffmpeg-devel@ffmpeg.org Date: Thu, 17 Aug 2017 13:54:44 +0200 Message-Id: <20170817115444.24936-1-vittorio.giovara@gmail.com> X-Mailer: git-send-email 2.13.2 Subject: [FFmpeg-devel] [PATCH] mp4: Support writing declarative SEis to hvcC 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Vittorio Giovara --- Right now only one SEI type is added, there could be more declarative ones, but I'm not sure how to properly identify them. Also, the way to check for the seiPayloadType could be improved, suggestions are welcome. Vittorio libavcodec/extract_extradata_bsf.c | 1 + libavformat/hevc.c | 28 ++++++++++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/libavcodec/extract_extradata_bsf.c b/libavcodec/extract_extradata_bsf.c index 4cd0ca1137..e0d8aa99b5 100644 --- a/libavcodec/extract_extradata_bsf.c +++ b/libavcodec/extract_extradata_bsf.c @@ -54,6 +54,7 @@ static int extract_extradata_h2645(AVBSFContext *ctx, AVPacket *pkt, { static const int extradata_nal_types_hevc[] = { HEVC_NAL_VPS, HEVC_NAL_SPS, HEVC_NAL_PPS, + HEVC_NAL_SEI_PREFIX, HEVC_NAL_SEI_SUFFIX, }; static const int extradata_nal_types_h264[] = { H264_NAL_SPS, H264_NAL_PPS, diff --git a/libavformat/hevc.c b/libavformat/hevc.c index 1a2d6cdd2b..9ff2b858dd 100644 --- a/libavformat/hevc.c +++ b/libavformat/hevc.c @@ -22,6 +22,7 @@ #include "libavcodec/get_bits.h" #include "libavcodec/golomb.h" #include "libavcodec/hevc.h" +#include "libavcodec/hevc_sei.h" #include "libavutil/intreadwrite.h" #include "avc.h" #include "avio.h" @@ -763,17 +764,10 @@ static int hvcc_add_nal_unit(uint8_t *nal_buf, uint32_t nal_size, nal_unit_parse_header(&gbc, &nal_type); - /* - * Note: only 'declarative' SEI messages are allowed in - * hvcC. Perhaps the SEI playload type should be checked - * and non-declarative SEI messages discarded? - */ switch (nal_type) { case HEVC_NAL_VPS: case HEVC_NAL_SPS: case HEVC_NAL_PPS: - case HEVC_NAL_SEI_PREFIX: - case HEVC_NAL_SEI_SUFFIX: ret = hvcc_array_add_nal_unit(nal_buf, nal_size, nal_type, ps_array_completeness, hvcc); if (ret < 0) @@ -787,6 +781,15 @@ static int hvcc_add_nal_unit(uint8_t *nal_buf, uint32_t nal_size, if (ret < 0) goto end; break; + case HEVC_NAL_SEI_PREFIX: + case HEVC_NAL_SEI_SUFFIX: + if (nal_size > 2 && *(nal_buf + 2) == HEVC_SEI_TYPE_MASTERING_DISPLAY_INFO) { + ret = hvcc_array_add_nal_unit(nal_buf, nal_size, nal_type, + ps_array_completeness, hvcc); + if (ret < 0) + goto end; + } + break; default: ret = AVERROR_INVALIDDATA; goto end; @@ -835,6 +838,7 @@ static int hvcc_write(AVIOContext *pb, HEVCDecoderConfigurationRecord *hvcc) { uint8_t i; uint16_t j, vps_count = 0, sps_count = 0, pps_count = 0; + int sei_prefix_count = 0, sei_suffix_count = 0; /* * We only support writing HEVCDecoderConfigurationRecord version 1. @@ -925,12 +929,20 @@ static int hvcc_write(AVIOContext *pb, HEVCDecoderConfigurationRecord *hvcc) case HEVC_NAL_PPS: pps_count += hvcc->array[i].numNalus; break; + case HEVC_NAL_SEI_PREFIX: + sei_suffix_count += hvcc->array[i].numNalus; + break; + case HEVC_NAL_SEI_SUFFIX: + sei_prefix_count += hvcc->array[i].numNalus; + break; default: break; } if (!vps_count || vps_count > HEVC_MAX_VPS_COUNT || !sps_count || sps_count > HEVC_MAX_SPS_COUNT || - !pps_count || pps_count > HEVC_MAX_PPS_COUNT) + !pps_count || pps_count > HEVC_MAX_PPS_COUNT || + sei_prefix_count > UINT16_MAX || + sei_suffix_count > UINT16_MAX) return AVERROR_INVALIDDATA; /* unsigned int(8) configurationVersion = 1; */