From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id A874E44143 for ; Fri, 28 Oct 2022 14:56:07 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1F7E768BCF5; Fri, 28 Oct 2022 17:56:06 +0300 (EEST) Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DDC5B68B83A for ; Fri, 28 Oct 2022 17:55:59 +0300 (EEST) Received: by mail-pf1-f171.google.com with SMTP id e4so4996920pfl.2 for ; Fri, 28 Oct 2022 07:55:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sandflow-com.20210112.gappssmtp.com; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=NiAy6Wj30N3uVIlq3tB/OeBUcumgn3t5G23REfUn0ZA=; b=TVxIc02hd5xHqYqjRra6Ps88BDxfGR/D/OqTWHYlY9mSu+IKGGi+44cmKiR3VZRul/ q7ddO7fW7c82/AxgsYpMfS6edvL//URi1Wq1fMWKkrJyFiJGSchwYc8GT2WQecxbvWw6 RQuNfiLubNZH7iBs79qYUzjnNEfHscys6jNrn013+yx5552MGDtzCv3jiQKs+IBTAhUV IqTbhB3F6zGPZb2kdp58lrp3V4wU+P+W4kjl39RkAa2DeeIB6/9okmSJcvhdq2hyqTcJ e0rQ8GTURchz4Tjk7n0W0U1YOkDA15j0dJYIiA0zCupAaXi+yKTXO3ou5X08Z1ue8F0Z 9FbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NiAy6Wj30N3uVIlq3tB/OeBUcumgn3t5G23REfUn0ZA=; b=u5WxREs6WybW4aKeV6CeZVpeXR4Lf6W1No8NJSIEUr1V2gZvVj4xCWeMLQp9o336vy ibxb7xFzCgreMwxl9kx6cQ1p0clNRGWqRxJRdh6K0dc/U4QUZii2/ceuG2QeaCjRARWb 0jt/EEWk8/HXlRYFFq159nH5uoT6MdksIclBjqb+SgCNwyizXcYPbZVdOwxPGB0FVEG+ jCPsd4Sn0DCg8ShDLe2K+zqZeCPi5OkJXz+XjWYr9Uebv9Oz/pKMFx9gHxQrcwWW/PwT 6onoBi69SvQAQf+EImcIM4lT0miLY0MgnbOcZjxQ5v7fz9jPdDFlHUWgzLHh0vvVsSwf 35Ig== X-Gm-Message-State: ACrzQf3/m/pK13BtjrJ1kxEH7SBKZ94LiQBcsfmzv+era99K9hBoIbD+ kUgQBBPRGZz0y92tEhM8HpYzGk829ZhiWw== X-Google-Smtp-Source: AMsMyM6g2hLIoq/K8vyL2kMNQtEaM4TbQqsQS7Se6OK5Ml6DqA0J6k41owcZzX26g/JjlH/rgrTgZA== X-Received: by 2002:a65:564d:0:b0:46b:1a7d:3b82 with SMTP id m13-20020a65564d000000b0046b1a7d3b82mr47128877pgs.459.1666968957525; Fri, 28 Oct 2022 07:55:57 -0700 (PDT) Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com. [209.85.216.49]) by smtp.gmail.com with ESMTPSA id o18-20020a170903211200b00186b945c0d1sm3157580ple.2.2022.10.28.07.55.56 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 28 Oct 2022 07:55:57 -0700 (PDT) Received: by mail-pj1-f49.google.com with SMTP id v4-20020a17090a088400b00212cb0ed97eso4690792pjc.5 for ; Fri, 28 Oct 2022 07:55:56 -0700 (PDT) X-Received: by 2002:a17:90b:4b90:b0:213:6a84:b4e9 with SMTP id lr16-20020a17090b4b9000b002136a84b4e9mr11572994pjb.212.1666968956240; Fri, 28 Oct 2022 07:55:56 -0700 (PDT) MIME-Version: 1.0 References: <20221002162755.8413-1-pal@sandflow.com> In-Reply-To: <20221002162755.8413-1-pal@sandflow.com> From: Pierre-Anthony Lemieux Date: Fri, 28 Oct 2022 07:55:44 -0700 X-Gmail-Original-Message-ID: Message-ID: To: ffmpeg-devel@ffmpeg.org, Zane van Iperen Subject: Re: [FFmpeg-devel] [PATCH v2 1/3] avformat/imfdec: use CPL start timecode if available X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Hi Zane et al., Quick ping on the revised patchset below. It addresses https://trac.ffmpeg.org/ticket/9842. Best, -- Pierre On Sun, Oct 2, 2022 at 9:28 AM wrote: > > From: Pierre-Anthony Lemieux > > The IMF CPL contains an optional timecode start address. This patch reads the > latter, if present, into the context's timecode metadata parameter. > This addresses https://trac.ffmpeg.org/ticket/9842. > > --- > libavformat/imf.h | 2 + > libavformat/imf_cpl.c | 106 ++++++++++++++++++++++++++++++++++++++++++ > libavformat/imfdec.c | 11 +++++ > 3 files changed, 119 insertions(+) > > diff --git a/libavformat/imf.h b/libavformat/imf.h > index 4271cd9582..70ed007312 100644 > --- a/libavformat/imf.h > +++ b/libavformat/imf.h > @@ -59,6 +59,7 @@ > #include "libavformat/avio.h" > #include "libavutil/rational.h" > #include "libavutil/uuid.h" > +#include "libavutil/timecode.h" > #include > > /** > @@ -130,6 +131,7 @@ typedef struct FFIMFCPL { > AVUUID id_uuid; /**< CompositionPlaylist/Id element */ > xmlChar *content_title_utf8; /**< CompositionPlaylist/ContentTitle element */ > AVRational edit_rate; /**< CompositionPlaylist/EditRate element */ > + AVTimecode *tc; /**< CompositionPlaylist/CompositionTimecode element */ > FFIMFMarkerVirtualTrack *main_markers_track; /**< Main Marker Virtual Track */ > FFIMFTrackFileVirtualTrack *main_image_2d_track; /**< Main Image Virtual Track */ > uint32_t main_audio_track_count; /**< Number of Main Audio Virtual Tracks */ > diff --git a/libavformat/imf_cpl.c b/libavformat/imf_cpl.c > index 474db6b7f5..183e6dd84e 100644 > --- a/libavformat/imf_cpl.c > +++ b/libavformat/imf_cpl.c > @@ -116,6 +116,22 @@ int ff_imf_xml_read_uint32(xmlNodePtr element, uint32_t *number) > return ret; > } > > +static int ff_imf_xml_read_boolean(xmlNodePtr element, int *value) > +{ > + int ret = 0; > + > + xmlChar *element_text = xmlNodeListGetString(element->doc, element->xmlChildrenNode, 1); > + if (xmlStrcmp(element_text, "true") == 0 || xmlStrcmp(element_text, "1") == 0) > + *value = 1; > + else if (xmlStrcmp(element_text, "false") == 0 || xmlStrcmp(element_text, "0") == 0) > + *value = 0; > + else > + ret = 1; > + xmlFree(element_text); > + > + return ret; > +} > + > static void imf_base_virtual_track_init(FFIMFBaseVirtualTrack *track) > { > memset(track->id_uuid, 0, sizeof(track->id_uuid)); > @@ -179,6 +195,90 @@ static int fill_content_title(xmlNodePtr cpl_element, FFIMFCPL *cpl) > return 0; > } > > +static int digit_to_int(char digit) > +{ > + if (digit >= '0' && digit <= '9') > + return digit - '0'; > + return -1; > +} > + > +/** > + * Parses a string that conform to the TimecodeType used in IMF CPL and defined > + * in SMPTE ST 2067-3. > + * @param[in] s string to parse > + * @param[out] tc_comps pointer to an array of 4 integers where the parsed HH, > + * MM, SS and FF fields of the timecode are returned. > + * @return 0 on success, < 0 AVERROR code on error. > + */ > +static int parse_cpl_tc_type(const char *s, int *tc_comps) > +{ > + if (av_strnlen(s, 11) != 11) > + return AVERROR(EINVAL); > + > + for (int i = 0; i < 4; i++) { > + int hi; > + int lo; > + > + hi = digit_to_int(s[i * 3]); > + lo = digit_to_int(s[i * 3 + 1]); > + > + if (hi == -1 || lo == -1) > + return AVERROR(EINVAL); > + > + tc_comps[i] = 10 * hi + lo; > + } > + > + return 0; > +} > + > +static int fill_timecode(xmlNodePtr cpl_element, FFIMFCPL *cpl) > +{ > + xmlNodePtr tc_element = NULL; > + xmlNodePtr element = NULL; > + xmlChar *tc_str = NULL; > + int df = 0; > + int comps[4]; > + int ret = 0; > + > + tc_element = ff_imf_xml_get_child_element_by_name(cpl_element, "CompositionTimecode"); > + if (!tc_element) > + return 0; > + > + element = ff_imf_xml_get_child_element_by_name(tc_element, "TimecodeDropFrame"); > + if (!element) { > + av_log(NULL, AV_LOG_ERROR, "CompositionTimecode element is missing\ > + a TimecodeDropFrame child element\n"); > + return AVERROR_INVALIDDATA; > + } > + > + if (ff_imf_xml_read_boolean(element, &df)) { > + av_log(NULL, AV_LOG_ERROR, "TimecodeDropFrame element is invalid\n"); > + return AVERROR_INVALIDDATA; > + } > + element = ff_imf_xml_get_child_element_by_name(tc_element, "TimecodeStartAddress"); > + if (!element) { > + av_log(NULL, AV_LOG_ERROR, "CompositionTimecode element is missing\ > + a TimecodeStartAddress child element\n"); > + return AVERROR_INVALIDDATA; > + } > + > + tc_str = xmlNodeListGetString(element->doc, element->xmlChildrenNode, 1); > + ret = parse_cpl_tc_type(tc_str, comps); > + xmlFree(tc_str); > + if (ret) > + return ret; > + > + cpl->tc = av_malloc(sizeof(AVTimecode)); > + if (!cpl->tc) > + return AVERROR(ENOMEM); > + ret = av_timecode_init_from_components(cpl->tc, cpl->edit_rate, > + df ? AV_TIMECODE_FLAG_DROPFRAME : 0, > + comps[0], comps[1], comps[2], comps[3], > + NULL); > + > + return ret; > +} > + > static int fill_edit_rate(xmlNodePtr cpl_element, FFIMFCPL *cpl) > { > xmlNodePtr element = NULL; > @@ -682,6 +782,8 @@ int ff_imf_parse_cpl_from_xml_dom(xmlDocPtr doc, FFIMFCPL **cpl) > goto cleanup; > if ((ret = fill_edit_rate(cpl_element, *cpl))) > goto cleanup; > + if ((ret = fill_timecode(cpl_element, *cpl))) > + goto cleanup; > if ((ret = fill_virtual_tracks(cpl_element, *cpl))) > goto cleanup; > > @@ -731,6 +833,7 @@ static void imf_cpl_init(FFIMFCPL *cpl) > av_uuid_nil(cpl->id_uuid); > cpl->content_title_utf8 = NULL; > cpl->edit_rate = av_make_q(0, 1); > + cpl->tc = NULL; > cpl->main_markers_track = NULL; > cpl->main_image_2d_track = NULL; > cpl->main_audio_track_count = 0; > @@ -753,6 +856,9 @@ void ff_imf_cpl_free(FFIMFCPL *cpl) > if (!cpl) > return; > > + if (cpl->tc) > + av_freep(&cpl->tc); > + > xmlFree(cpl->content_title_utf8); > > imf_marker_virtual_track_free(cpl->main_markers_track); > diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c > index 4e60dcc4ba..03de9ce151 100644 > --- a/libavformat/imfdec.c > +++ b/libavformat/imfdec.c > @@ -627,6 +627,8 @@ static int imf_read_header(AVFormatContext *s) > IMFContext *c = s->priv_data; > char *asset_map_path; > char *tmp_str; > + AVDictionaryEntry* tcr; > + char tc_buf[AV_TIMECODE_STR_SIZE]; > int ret = 0; > > c->interrupt_callback = &s->interrupt_callback; > @@ -646,6 +648,15 @@ static int imf_read_header(AVFormatContext *s) > if ((ret = ff_imf_parse_cpl(s->pb, &c->cpl)) < 0) > return ret; > > + tcr = av_dict_get(s->metadata, "timecode", NULL, 0); > + if (!tcr && c->cpl->tc) { > + ret = av_dict_set(&s->metadata, "timecode", > + av_timecode_make_string(c->cpl->tc, tc_buf, 0), 0); > + if (ret) > + return ret; > + av_log(s, AV_LOG_INFO, "Setting timecode to IMF CPL timecode %s\n", tc_buf); > + } > + > av_log(s, > AV_LOG_DEBUG, > "parsed IMF CPL: " AV_PRI_URN_UUID "\n", > -- > 2.25.1 > _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".