diff mbox series

[FFmpeg-devel,1/2] avformat/mxf: start to add mxf_inspect_mode and skip RIP if needed sponsored by nxtedition

Message ID 20240814075908.92916-1-marc-antoine.arnaud@luminvent.com
State New
Headers show
Series [FFmpeg-devel,1/2] avformat/mxf: start to add mxf_inspect_mode and skip RIP if needed sponsored by nxtedition | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished

Commit Message

Marc-Antoine ARNAUD Aug. 14, 2024, 7:59 a.m. UTC
---
 libavformat/mxfdec.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

Comments

Marton Balint Aug. 17, 2024, 7:15 p.m. UTC | #1
On Wed, 14 Aug 2024, Marc-Antoine Arnaud wrote:

> ---
> libavformat/mxfdec.c | 14 +++++++++++++-
> 1 file changed, 13 insertions(+), 1 deletion(-)

Why would you want to tune this?

Thanks,
Marton

>
> 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)
>
> _______________________________________________
> 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".
>
Marc-Antoine ARNAUD Aug. 21, 2024, 10:54 a.m. UTC | #2
Le sam. 17 août 2024 à 21:15, Marton Balint <cus@passwd.hu> a écrit :

>
>
> On Wed, 14 Aug 2024, Marc-Antoine Arnaud wrote:
>
> > ---
> > libavformat/mxfdec.c | 14 +++++++++++++-
> > 1 file changed, 13 insertions(+), 1 deletion(-)
>
> Why would you want to tune this?
>

Hi Marton

In some MXF files, index tables are present in the first body partition or
fully in the footer partition.
This patch will skip parsing all body partitions if the index table is
coherent.

Best regards,
Marc-Antoine



> Thanks,
> Marton
>
> >
> > 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)
> >
> > _______________________________________________
> > 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".
> >
> _______________________________________________
> 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".
>
Tomas Härdin Aug. 21, 2024, 4:03 p.m. UTC | #3
ons 2024-08-14 klockan 09:59 +0200 skrev Marc-Antoine Arnaud:
> ---
>  libavformat/mxfdec.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)

Good idea. Could use some documentation.

/Tomas
Marton Balint Aug. 21, 2024, 9:19 p.m. UTC | #4
On Wed, 21 Aug 2024, Marc-Antoine ARNAUD wrote:

> Le sam. 17 août 2024 à 21:15, Marton Balint <cus@passwd.hu> a écrit :
>
>>
>>
>> On Wed, 14 Aug 2024, Marc-Antoine Arnaud wrote:
>>
>> > ---
>> > libavformat/mxfdec.c | 14 +++++++++++++-
>> > 1 file changed, 13 insertions(+), 1 deletion(-)
>>
>> Why would you want to tune this?
>>
>
> Hi Marton
>
> In some MXF files, index tables are present in the first body partition or
> fully in the footer partition.
> This patch will skip parsing all body partitions if the index table is
> coherent.

That still does not answer the "why". You want to avoid reading every 
partition pack when the file is opened? If you ignore reading the RIP 
(and consequentally force the system to do a forward parse and not read all 
partition packs in advance) then I am not sure how seeking will work, 
because even if there is a full index, you won't have a list of partitions 
and the essence body offsets for the partitions.

The quick and dirty way of forcing opening a file without reading all 
partition packs is using -seekable 0 when opening that file... Isn't 
that enough for your use case?

Something more advanced is not trivial, because you'd have to parse the 
partitions packs on demand.

Regards,
Marton


>
> Best regards,
> Marc-Antoine
>
>
>
>> Thanks,
>> Marton
>>
>> >
>> > 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)
>> >
>> > _______________________________________________
>> > 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".
>> >
>> _______________________________________________
>> 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".
>>
> _______________________________________________
> 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".
Tomas Härdin Aug. 26, 2024, 2:16 p.m. UTC | #5
ons 2024-08-21 klockan 23:19 +0200 skrev Marton Balint:
> 
> 
> On Wed, 21 Aug 2024, Marc-Antoine ARNAUD wrote:
> 
> > Le sam. 17 août 2024 à 21:15, Marton Balint <cus@passwd.hu> a écrit
> > :
> > 
> > > 
> > > 
> > > On Wed, 14 Aug 2024, Marc-Antoine Arnaud wrote:
> > > 
> > > > ---
> > > > libavformat/mxfdec.c | 14 +++++++++++++-
> > > > 1 file changed, 13 insertions(+), 1 deletion(-)
> > > 
> > > Why would you want to tune this?
> > > 
> > 
> > Hi Marton
> > 
> > In some MXF files, index tables are present in the first body
> > partition or
> > fully in the footer partition.
> > This patch will skip parsing all body partitions if the index table
> > is
> > coherent.
> 
> That still does not answer the "why". You want to avoid reading every
> partition pack when the file is opened? If you ignore reading the RIP
> (and consequentally force the system to do a forward parse and not
> read all 
> partition packs in advance) then I am not sure how seeking will work,
> because even if there is a full index, you won't have a list of
> partitions 
> and the essence body offsets for the partitions.
> 
> The quick and dirty way of forcing opening a file without reading all
> partition packs is using -seekable 0 when opening that file... Isn't 
> that enough for your use case?
> 
> Something more advanced is not trivial, because you'd have to parse
> the 
> partitions packs on demand.

A feature like this would be really neat. You'd need logic that
guesstimates which partition pack to parse, sees if the desired edit
unit is contained within it and optionally seeks forward/backward as
necessary to find the appropriate partition. That's quite complicated
to implement I suspect (you'd need a sparse range-aware data
structure), but it'd be the best way. That would also take care of some
nasty properties of the current demuxer, which is terribly slow to open
MXF files produced by mxfenc if working over HTTP. It gets even worse
with melt that opens files multiple times

/Tomas
diff mbox series

Patch

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 },
 };