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 9A6174C9ED for ; Sun, 11 Aug 2024 16:13:08 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C53F868D9B7; Sun, 11 Aug 2024 19:13:04 +0300 (EEST) Received: from mail-oo1-f46.google.com (mail-oo1-f46.google.com [209.85.161.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4D4BE68D864 for ; Sun, 11 Aug 2024 19:12:58 +0300 (EEST) Received: by mail-oo1-f46.google.com with SMTP id 006d021491bc7-5d5b1e33fa8so2136743eaf.3 for ; Sun, 11 Aug 2024 09:12:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=media-io-com.20230601.gappssmtp.com; s=20230601; t=1723392776; x=1723997576; darn=ffmpeg.org; h=cc:to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=mftlzzhflT9WBuqGVeJ3iLaG9tUmm+QdNjAhzpJb5Hs=; b=27AluE+YpERrf4CX7SEy9mWga3yDZ1epazrIbCET2FdV5GN0m3knlppLNNvQLlHNgq x7mbjCwObsPndRksD/8u6ylaeZBoH7G/oEDlbzuzCsLewjW+/4aQQH5v7rL++tpTVF1G ZH2DfzivEtybtm9/B3gTEv46zBEe5aCyUwIBzovtAUi3cWsg7utOO6zBdFjZ0ntDfC3C Vh74DxtGTZdPCwxicOuE8uM7KX45QQdT3ttw0yn+dBkdshkaVVwlwM+1Oyp3xM9/Geqb CkGMtfYrh3lzAwIgKKB5GsuPCwg9JjGBGf8SZznHFbuXget5Wkbdmiwn22fs5vJd63Ek yfWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723392776; x=1723997576; h=cc:to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=mftlzzhflT9WBuqGVeJ3iLaG9tUmm+QdNjAhzpJb5Hs=; b=LfwcZfMEDVzc3RWHbV3r+HlVFM0bNN1S9njYyaCcZ26yJvbGrHTrQPty37gif/eN+b h8VbLr+oic9oB6eb9Cn51zGphTfpmF3JlLMLjvI63N9PhdvGtAjWlRjJx0IIXaIwMso0 MkTpJL3lVqIfxPVcNK2sSws/3dwIKPZ4xyVhQFrU0VI35Ezzm9C7FG3epBcBXxQ/0G63 kqVNomeGU1dFkk0wzMCqPeVMRBAHwgP8zSBdJvXDtDxqb2BVf6mT2XRTm4ouDKzvXsz8 NMINyZoYNiFWSeAtZlHUxfC7wOvQH1j1q1txlpv5ssU6nseFel/po2+XDxrHPtI0sNeO T0oQ== X-Gm-Message-State: AOJu0Yw45hwUojVZ373jaKuz6C4R+p9FJ0xNqdqBl9ztFO+cDQsjYJRa cRzUgTtUkNn131yoE6sukh9ng11/XOV8+v45NMgvDqDcPl/0+mB0mlWQ1U50LQLLFRYtjqV3BVB 0UlgEY6d9wZUorZV+T5dS66BxeUO7jSDVPpFbxHlwOlZ7X4XJBwc= X-Google-Smtp-Source: AGHT+IFAXsbOyAg0kMR+UprPg+7V4v7X/x/pSL+0Geb1mt2qXzNcINHB25Kcpromk074965O1Uui9X9cf945CbfV/XA= X-Received: by 2002:a05:6820:828:b0:5c4:e036:e383 with SMTP id 006d021491bc7-5d87a2fb1ddmr6729874eaf.8.1723392776572; Sun, 11 Aug 2024 09:12:56 -0700 (PDT) MIME-Version: 1.0 From: Marc-Antoine ARNAUD Date: Sun, 11 Aug 2024 18:12:45 +0200 Message-ID: To: FFmpeg development discussions and patches Content-Type: multipart/mixed; boundary="00000000000041cf7c061f6aa6a8" Subject: [FFmpeg-devel] avformat/mxf: improve parsing 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 Cc: Robert Nagy Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --00000000000041cf7c061f6aa6a8 Content-Type: text/plain; charset="UTF-8" -- Marc-Antoine ARNAUD CEO & Founder mobile: +33 6 84 71 84 45 email: arnaud.marc-antoine@luminvent.com website: luminvent.com --00000000000041cf7c061f6aa6a8 Content-Type: message/rfc822; name="0002-avformat-mxf-stop-parsing-if-index-table-is-coherent.eml" Content-Disposition: attachment; filename="0002-avformat-mxf-stop-parsing-if-index-table-is-coherent.eml" Content-ID: X-Attachment-Id: f_lzprjybp0 From: Marc-Antoine Arnaud Date: Sat, 13 Jul 2024 18:26:15 +0200 Subject: [PATCH 2/2] avformat/mxf: stop parsing if index table is coherent X-Unsent: 1 To: ffmpeg-devel@ffmpeg.org sponsored by nxtedition Signed-off-by: Marc-Antoine Arnaud --- libavformat/mxfdec.c | 56 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index df958819300..83f9e5fc9e0 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -2063,6 +2063,52 @@ static int mxf_compute_ptses_fake_index(MXFContext *mxf, MXFIndexTable *index_ta return 0; } +static int mxf_validate_coherent_index_tables(MXFContext *mxf, int *is_coherent) { + int i, j, ret, nb_sorted_segments = 0; + MXFIndexTable *index_tables; + int nb_index_tables = 0; + int coherent_index_tables = 1; + MXFIndexTableSegment **sorted_segments = NULL; + + ret = mxf_get_sorted_table_segments(mxf, &nb_sorted_segments, &sorted_segments); + + index_tables = av_calloc(nb_index_tables, sizeof(MXFIndexTable)); + if (!index_tables) { + av_log(mxf->fc, AV_LOG_ERROR, "failed to allocate index tables\n"); + av_free(sorted_segments); + return AVERROR(ENOMEM); + } + + /* distribute sorted segments to index tables */ + for (i = j = 0; i < nb_sorted_segments; i++) { + if (i != 0 && sorted_segments[i-1]->index_sid != sorted_segments[i]->index_sid) { + /* next IndexSID */ + j++; + } + + index_tables[j].nb_segments++; + } + + for (i = j = 0; j < nb_index_tables; i += index_tables[j++].nb_segments) { + if (sorted_segments[i]->index_start_position) { + av_log(mxf->fc, AV_LOG_WARNING, "IndexSID %i starts at EditUnit %"PRId64" - seeking may not work as expected\n", + sorted_segments[i]->index_sid, sorted_segments[i]->index_start_position); + coherent_index_tables = 0; + } + } + + av_free(sorted_segments); + + if (ret == 0 && coherent_index_tables) { + *is_coherent = 1; + } else { + *is_coherent = 0; + } + + return 0; +} + + /** * Sorts and collects index table segments into index tables. * Also computes PTSes if possible. @@ -3752,6 +3798,16 @@ static int mxf_read_header(AVFormatContext *s) if (!essence_offset) essence_offset = klv.offset; + if (mxf->mxf_inspect_mode == 1) { + int ret_local, coherent_index_tables; + ret_local = mxf_validate_coherent_index_tables(mxf, &coherent_index_tables); + + // Break only if index table is coherent + if (ret_local == 0 && coherent_index_tables == 1) { + break; + } + } + /* seek to footer, previous partition or stop */ if (mxf_parse_handle_essence(mxf) <= 0) break; -- 2.39.3 (Apple Git-146) --00000000000041cf7c061f6aa6a8 Content-Type: message/rfc822; name="0001-avformat-mxf-start-to-add-mxf_inspect_mode-and-skip-RI.eml" Content-Disposition: attachment; filename="0001-avformat-mxf-start-to-add-mxf_inspect_mode-and-skip-RI.eml" Content-ID: X-Attachment-Id: f_lzprjybt1 From: Marc-Antoine Arnaud Date: Fri, 12 Jul 2024 17:24:05 +0200 Subject: [PATCH 1/2] avformat/mxf: start to add mxf_inspect_mode and skip RIP if needed sponsored by nxtedition X-Unsent: 1 To: ffmpeg-devel@ffmpeg.org Signed-off-by: Marc-Antoine Arnaud --- libavformat/mxfdec.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index a5863445ab5..df958819300 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -321,6 +321,7 @@ typedef struct MXFContext { int nb_index_tables; MXFIndexTable *index_tables; int eia608_extract; + int mxf_inspect_mode; } MXFContext; /* NOTE: klv_offset is not set (-1) for local keys */ @@ -3713,7 +3714,9 @@ static int mxf_read_header(AVFormatContext *s) return AVERROR_INVALIDDATA; mxf->run_in = run_in; - mxf_read_random_index_pack(s); + if (mxf->mxf_inspect_mode == 0) { + mxf_read_random_index_pack(s); + } while (!avio_feof(s->pb)) { const MXFMetadataReadTableEntry *metadata; @@ -4261,6 +4264,15 @@ static const AVOption options[] = { { "eia608_extract", "extract eia 608 captions from s436m track", offsetof(MXFContext, eia608_extract), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM }, + { "mxf_inspect_mode", "the way to inspect MXF file", + offsetof(MXFContext, mxf_inspect_mode), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, + AV_OPT_FLAG_DECODING_PARAM, .unit = "mxf_inspect_mode" }, + { "rip", "Parse RIP, then every body partition", + 0, AV_OPT_TYPE_CONST, {.i64 = 0}, INT_MIN, INT_MAX, + AV_OPT_FLAG_DECODING_PARAM, .unit = "mxf_inspect_mode" }, + { "header", "Parse Header, first partition and next partitions if needed", + 0, AV_OPT_TYPE_CONST, {.i64 = 1}, INT_MIN, INT_MAX, + AV_OPT_FLAG_DECODING_PARAM, .unit = "mxf_inspect_mode" }, { NULL }, }; -- 2.39.3 (Apple Git-146) --00000000000041cf7c061f6aa6a8 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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". --00000000000041cf7c061f6aa6a8--