From patchwork Fri Nov 4 15:10:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Birkbeck X-Patchwork-Id: 1293 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.90.1 with SMTP id o1csp1368627vsb; Fri, 4 Nov 2016 08:10:45 -0700 (PDT) X-Received: by 10.28.19.131 with SMTP id 125mr3724783wmt.133.1478272245603; Fri, 04 Nov 2016 08:10:45 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id y138si5600349wme.81.2016.11.04.08.10.44; Fri, 04 Nov 2016 08:10:45 -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; 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 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 7C5AA689D9B; Fri, 4 Nov 2016 17:10:39 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-yw0-f174.google.com (mail-yw0-f174.google.com [209.85.161.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B3107689CF6 for ; Fri, 4 Nov 2016 17:10:32 +0200 (EET) Received: by mail-yw0-f174.google.com with SMTP id l124so89492155ywb.3 for ; Fri, 04 Nov 2016 08:10:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=NPWRSjQ6STHwR2zQbX+W/ttn8VlUiWUFexxnd7q/FWs=; b=XZ+0R4k1xje7smCqADkG82sWSydIAPMP1nVVlp/8CKJd8o9Y/8UIrPGRB8Vh2mTB8J bBcpdbuf5RX3VLmEhDbRVw+2hfS8zZs91LjTF4V/Ekv/wQZBE7BTWX8PBHc+KfBpz+fB N2ZlNkmwanCpySFjOLfc0K1H/wrsYg18RbtrOwbkduJlxrhWFl/y32Lw6pibrqKPedVH o7Xc40z6W0xm0L+2XBFal24lyIzCJZWDb+zV5koszzke72XOK9J8m35pxq2qg+lVEg3F 58jYAHNPFXrNKATL6ZBJ5LMTz7TvEeKsC2UGItzky5RZjr5DGXM8D61kdYd6eKNlRUl7 RSKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=NPWRSjQ6STHwR2zQbX+W/ttn8VlUiWUFexxnd7q/FWs=; b=AtGr8j1onIgyzeN1DmV0vsdVUGXg51dIV7GBnUEHofrU+yT1Z4zTVrZgZ/qaSAWxut xQVdGG9+kqz6RmQgLB57WlknTLVsIWtvRvVaIb3Vwr2g9HYae/FiNe70+PMsQzplvR/e l5F0EKw2hzUetGW2TCAq3HmuZ0vhMNgq9hJcAGHxY8uyiVswWkbP/GpvZDntupWIIG9o zO+J+hKxvPCcftEBHfdEyuKDWgMDIxhcdajGkhHmDkAjXG0ry2+g/jZArFbo/bK8AR3M mhTpnoR8JYBi6EMuTXUCIGmafbTj5f6Cw0BR7qpxPUPawWuBVxsr+l1E+adK6kA+3ebo /irw== X-Gm-Message-State: ABUngvfTf/Yea01ZUBctkU125k9cdx+G7S3KVgk/HIiqZ+cy6GZ0FE4gu9i+w8RSyPr7wNT0K7+cm3yCT53q2g== X-Received: by 10.107.40.199 with SMTP id o190mr5770348ioo.5.1478272234641; Fri, 04 Nov 2016 08:10:34 -0700 (PDT) MIME-Version: 1.0 Received: by 10.36.245.2 with HTTP; Fri, 4 Nov 2016 08:10:33 -0700 (PDT) In-Reply-To: <2F849DDE-36A7-4FF3-A1D2-AC60ABEA360B@dericed.com> References: <20160417020849.GY4535@nb4> <2F849DDE-36A7-4FF3-A1D2-AC60ABEA360B@dericed.com> From: Neil Birkbeck Date: Fri, 4 Nov 2016 08:10:33 -0700 Message-ID: To: FFmpeg development discussions and patches X-Content-Filtered-By: Mailman/MimeDel 2.1.20 Subject: Re: [FFmpeg-devel] [PATCH] lavf/matroskaenc.c: use metadata key/value to set mastering metadata 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" On Wed, Jun 8, 2016 at 11:27 PM, Dave Rice wrote: > > > On Jun 8, 2016, at 11:03 PM, Neil Birkbeck > wrote: > > > > The most recent patch should still apply cleanly (unless we have a > > better way to set these elements). Thanks > > There are specific mastering metadata elements as recently defined in the > Matroska specification [1]. It would be better to use these defined > elements from the specification rather than somehow fit this data into tags. > Dave Rice > > [1] https://matroska.org/technical/specs/index.html#MasteringMetadata Yes, the new elements are read and written, and are propagated within ffmpeg in side data. This patch is to address how we can manually specify those values when creating a new file from an input that doesn't have the metadata already. The current patch doesn't write them to tags in the output file, but uses the "metadata" command line. I kept this like stereo_mode, but maybe we should instead use specific muxer option to do this? Or perhaps there is another generic way to instantiate side data from command line upstream from the muxer that I am missing. > > > > On Tue, Apr 19, 2016 at 8:12 AM, Neil Birkbeck > wrote: > >> Updated patch attached. > >> > >> On Sat, Apr 16, 2016 at 7:08 PM, Michael Niedermayer > >> wrote: > >>> On Sun, Apr 03, 2016 at 03:38:33PM -0700, Neil Birkbeck wrote: > >>>> Use "master_display" key/value pair to specify mastering metadata in a > >>>> similar formatting as accepted by libx265 (unless there is some other > >>>> generic way to add side data to a stream from command line). > >>>> Currently, the packet side data propagates from an input file to > >>>> output file if it is transmuxed (mkv -> mkv). Perhaps we want to also > >>>> use this same metadata key in matroskadec to also allow for the > >>>> metadata to propagate during transcoding. > >>> > >>>> matroskaenc.c | 51 ++++++++++++++++++++++++++++++ > +++++++++++++++++---- > >>>> 1 file changed, 47 insertions(+), 4 deletions(-) > >>>> d92564f3ec6cf08430a79b64f4d1ec304637afe1 > 0001-lavf-matroskaenc.c-use-metadata-key-value-to-set-mas.patch > >>>> From b30d80f6ba4b09811039f64af3e7f709d86df5fe Mon Sep 17 00:00:00 > 2001 > >>>> From: Neil Birkbeck > >>>> Date: Fri, 1 Apr 2016 17:02:42 -0700 > >>>> Subject: [PATCH] lavf/matroskaenc.c: use metadata key/value to set > mastering > >>>> metadata > >>>> > >>>> Add key/value metadata interface to allow command line setting of > AVMasteringDisplayMetadata. The formatting is the same as the option in > libx265. > >>>> > >>>> Signed-off-by: Neil Birkbeck > >>> > >>> this does not apply cleanly anymore after codecpar > >>> > >>> Applying: lavf/matroskaenc.c: use metadata key/value to set mastering > metadata > >>> Using index info to reconstruct a base tree... > >>> Falling back to patching base and 3-way merge... > >>> Auto-merging libavformat/matroskaenc.c > >>> CONFLICT (content): Merge conflict in libavformat/matroskaenc.c > >>> Failed to merge in the changes. > >>> Patch failed at 0001 lavf/matroskaenc.c: use metadata key/value to set > mastering metadata > >>> When you have resolved this problem run "git am --resolved". > >>> If you would prefer to skip this patch, instead run "git am --skip". > >>> To restore the original branch and stop patching run "git am --abort". > >>> > >>> > >>> [...] > >>> > >>> -- > >>> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC7 > 87040B0FAB > >>> > >>> Democracy is the form of government in which you can choose your > dictator > >>> > >>> _______________________________________________ > >>> ffmpeg-devel mailing list > >>> ffmpeg-devel@ffmpeg.org > >>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel > >>> > > _______________________________________________ > > ffmpeg-devel mailing list > > ffmpeg-devel@ffmpeg.org > > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel > From e83d6ca87c7da2d6a9ff09dcec339cadc054610f Mon Sep 17 00:00:00 2001 From: Neil Birkbeck Date: Thu, 3 Nov 2016 17:13:03 -0700 Subject: [PATCH] lavf/matroskaenc.c: use metadata key/value to set mastering metadata Add key/value metadata interface to allow command line setting of AVMasteringDisplayMetadata. The formatting is the same as the option in libx265. Signed-off-by: Neil Birkbeck --- libavformat/matroskaenc.c | 49 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 2cfeee9..4287171 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -804,17 +804,61 @@ static int mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb, } static int mkv_write_video_color(AVIOContext *pb, AVCodecParameters *par, AVStream *st) { + AVDictionaryEntry *tag; AVIOContext *dyn_cp; uint8_t *colorinfo_ptr; int side_data_size = 0; int ret, colorinfo_size; const uint8_t *side_data = av_stream_get_side_data( st, AV_PKT_DATA_MASTERING_DISPLAY_METADATA, &side_data_size); + AVMasteringDisplayMetadata *metadata = + (side_data_size == sizeof(AVMasteringDisplayMetadata)) ? + (AVMasteringDisplayMetadata*)side_data : NULL; ret = avio_open_dyn_buf(&dyn_cp); if (ret < 0) return ret; + // If key-value pair metadata is specified, override the packet side data + // Accept a format similar to the command line argument in x265: + // G(x,y)B(x,y)R(x,y)WP(x,y),L(max,min) + if (tag = av_dict_get(st->metadata, "master_display", NULL, 0)) { + int primaries[4][2]; + int luma[2]; + int num_read = sscanf(tag->value, + "G(%d,%d)B(%d,%d)R(%d,%d)WP(%d,%d)L(%d,%d)", + primaries[1], primaries[1] + 1, + primaries[2], primaries[2] + 1, + primaries[0], primaries[0] + 1, + primaries[3], primaries[3] + 1, + luma + 1, luma + 0); + if (num_read >= 8) { + const float chroma_denom = 50000.f; + const float luma_denom = 10000.f; + int i, j; + if (!metadata) { + metadata = (AVMasteringDisplayMetadata*) av_stream_new_side_data( + st, AV_PKT_DATA_MASTERING_DISPLAY_METADATA, + sizeof(AVMasteringDisplayMetadata)); + memset(metadata, 0, sizeof(AVMasteringDisplayMetadata)); + } + for (i = 0; i < 3; ++i) { + for (j = 0; j < 2; ++j) { + metadata->display_primaries[i][j] = + av_make_q(primaries[i][j], chroma_denom); + } + } + metadata->white_point[0] = av_make_q(primaries[3][0], chroma_denom); + metadata->white_point[1] = av_make_q(primaries[3][1], chroma_denom); + metadata->has_primaries = 1; + if (num_read == 10) { + metadata->min_luminance = av_make_q(luma[0], luma_denom); + metadata->max_luminance = av_make_q(luma[1], luma_denom); + metadata->has_luminance = 1; + } + } + } + if (par->color_trc != AVCOL_TRC_UNSPECIFIED && par->color_trc < AVCOL_TRC_NB) { put_ebml_uint(dyn_cp, MATROSKA_ID_VIDEOCOLORTRANSFERCHARACTERISTICS, @@ -840,11 +884,9 @@ static int mkv_write_video_color(AVIOContext *pb, AVCodecParameters *par, AVStre put_ebml_uint(dyn_cp, MATROSKA_ID_VIDEOCOLORCHROMASITINGHORZ, (xpos >> 7) + 1); put_ebml_uint(dyn_cp, MATROSKA_ID_VIDEOCOLORCHROMASITINGVERT, (ypos >> 7) + 1); } - if (side_data_size == sizeof(AVMasteringDisplayMetadata)) { + if (metadata) { ebml_master meta_element = start_ebml_master( dyn_cp, MATROSKA_ID_VIDEOCOLORMASTERINGMETA, 0); - const AVMasteringDisplayMetadata *metadata = - (const AVMasteringDisplayMetadata*)side_data; if (metadata->has_primaries) { put_ebml_float(dyn_cp, MATROSKA_ID_VIDEOCOLOR_RX, av_q2d(metadata->display_primaries[0][0])); @@ -1425,6 +1467,7 @@ static int mkv_check_tag_name(const char *name, unsigned int elementid) { return av_strcasecmp(name, "title") && av_strcasecmp(name, "stereo_mode") && + av_strcasecmp(name, "master_display") && av_strcasecmp(name, "creation_time") && av_strcasecmp(name, "encoding_tool") && av_strcasecmp(name, "duration") && -- 2.8.0.rc3.226.g39d4020