From: Marc-Antoine ARNAUD <marc-antoine.arnaud@luminvent.com> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Cc: Robert Nagy <robert.nagy@nxtedition.com> Subject: [FFmpeg-devel] avformat/mxf: improve parsing Date: Sun, 11 Aug 2024 18:12:45 +0200 Message-ID: <CA+NTGJ1zNshCErWWAj2bTVjEtmJsuDcX5-xvnj09adY-P5Ch7w@mail.gmail.com> (raw) [-- Attachment #1: Type: text/plain, Size: 135 bytes --] -- Marc-Antoine ARNAUD CEO & Founder mobile: +33 6 84 71 84 45 email: arnaud.marc-antoine@luminvent.com website: luminvent.com [-- Attachment #2: 0002-avformat-mxf-stop-parsing-if-index-table-is-coherent.eml --] [-- Type: message/rfc822, Size: 3097 bytes --] From: Marc-Antoine Arnaud <marc-antoine.arnaud@luminvent.com> To: ffmpeg-devel@ffmpeg.org Subject: [PATCH 2/2] avformat/mxf: stop parsing if index table is coherent Date: Sat, 13 Jul 2024 18:26:15 +0200 sponsored by nxtedition Signed-off-by: Marc-Antoine Arnaud <marc-antoine.arnaud@luminvent.com> --- 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) [-- Attachment #3: 0001-avformat-mxf-start-to-add-mxf_inspect_mode-and-skip-RI.eml --] [-- Type: message/rfc822, Size: 2029 bytes --] From: Marc-Antoine Arnaud <marc-antoine.arnaud@luminvent.com> To: ffmpeg-devel@ffmpeg.org Subject: [PATCH 1/2] avformat/mxf: start to add mxf_inspect_mode and skip RIP if needed sponsored by nxtedition Date: Fri, 12 Jul 2024 17:24:05 +0200 Signed-off-by: Marc-Antoine Arnaud <marc-antoine.arnaud@luminvent.com> --- 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) [-- Attachment #4: Type: text/plain, Size: 251 bytes --] _______________________________________________ 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".
next reply other threads:[~2024-08-11 16:13 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-08-11 16:12 Marc-Antoine ARNAUD [this message] -- strict thread matches above, loose matches on Subject: below -- 2024-08-11 15:47 Marc-Antoine ARNAUD [not found] ` <CAKhGax6h1s-fpsVrk9GRqEM=GO5FgNhH-o6t5wfeH8oM0ZEM6A@mail.gmail.com> 2024-08-11 16:04 ` Marc-Antoine ARNAUD
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=CA+NTGJ1zNshCErWWAj2bTVjEtmJsuDcX5-xvnj09adY-P5Ch7w@mail.gmail.com \ --to=marc-antoine.arnaud@luminvent.com \ --cc=ffmpeg-devel@ffmpeg.org \ --cc=robert.nagy@nxtedition.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git