[FFmpeg-devel] [PATCH 7/7] lavf/mxfdec: add -field_rate option

Matthieu Bouron matthieu.bouron at gmail.com
Thu Mar 28 15:41:51 CET 2013


Interpret sample rate as field rate for j2k codec with separate fields
or segmented frame layout.

This option is required to obtain a correct frame rate since S422M
specifies that the track sample rate could either be the frame rate
or the field rate for separate field layout.

For segmented frame layout, the track sample rate is supposed to be the
frame rate however some sample seems to use it as the field rate.
---
 libavformat/mxfdec.c | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index 171d32e..dddebf4 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -48,6 +48,7 @@
 #include "libavutil/aes.h"
 #include "libavutil/avassert.h"
 #include "libavutil/mathematics.h"
+#include "libavutil/opt.h"
 #include "libavcodec/bytestream.h"
 #include "libavutil/timecode.h"
 #include "avformat.h"
@@ -206,6 +207,7 @@ typedef struct {
 } MXFIndexTable;
 
 typedef struct {
+    const AVClass *class;
     MXFPartition *partitions;
     unsigned partitions_count;
     MXFOP op;
@@ -229,6 +231,7 @@ typedef struct {
     int nb_index_tables;
     MXFIndexTable *index_tables;
     int edit_units_per_packet;      ///< how many edit units to read at a time (PCM, OPAtom)
+    int field_rate;
 } MXFContext;
 
 enum MXFWrappingScheme {
@@ -1553,8 +1556,12 @@ static int mxf_parse_structural_metadata(MXFContext *mxf)
             case AV_CODEC_ID_JPEG2000:
                 if (descriptor->frame_layout == SegmentedFrame ||
                     descriptor->frame_layout == SeparateFields) {
-                    st->codec->time_base = st->time_base;
-                    st->time_base = (AVRational) { st->time_base.num, st->time_base.den * 2};
+                    if (mxf->field_rate) {
+                        st->codec->time_base = (AVRational) { st->time_base.num, st->time_base.den / 2 };
+                    } else {
+                        st->codec->time_base = st->time_base;
+                        st->time_base = (AVRational) { st->time_base.num, st->time_base.den * 2};
+                    }
                     st->codec->extradata_size = 2;
                     st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
                     if (!st->codec->extradata)
@@ -2419,6 +2426,22 @@ static int mxf_read_seek(AVFormatContext *s, int stream_index, int64_t sample_ti
     return 0;
 }
 
+
+#define OFFSET(x) offsetof(MXFContext, x)
+#define DEC AV_OPT_FLAG_DECODING_PARAM
+static const AVOption options[] = {
+    { "field_rate", "Interpret sample rate as field rate.",
+      OFFSET(field_rate), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, DEC },
+    { NULL },
+};
+
+static const AVClass mxf_demuxer_class = {
+    .class_name     = "MXF demuxer",
+    .item_name      = av_default_item_name,
+    .option         = options,
+    .version        = LIBAVUTIL_VERSION_INT,
+};
+
 AVInputFormat ff_mxf_demuxer = {
     .name           = "mxf",
     .long_name      = NULL_IF_CONFIG_SMALL("MXF (Material eXchange Format)"),
@@ -2428,4 +2451,5 @@ AVInputFormat ff_mxf_demuxer = {
     .read_packet    = mxf_read_packet,
     .read_close     = mxf_read_close,
     .read_seek      = mxf_read_seek,
+    .priv_class     = &mxf_demuxer_class,
 };
-- 
1.8.2



More information about the ffmpeg-devel mailing list