[FFmpeg-devel] [PATCH] mxfdec.c: Try TC from Footer if Header TC was < 1

emcodem emcodem at ffastrans.com
Mon May 24 13:30:28 EEST 2021


Added support for reading Start Timecode from Footer (if any). 
Specifically targets Omneon 6.4.3.0 but also works on other Versions and Vendors, e.g. when Header is OpenIncomplete.
Function mxf_resolve_strong_ref_reverse can potentially be re-used for getting other values like Duration and 
Origin from Footer.
---
 libavformat/mxfdec.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index 3bf480a3a6..557e01f8ed 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -1396,6 +1396,19 @@ static const MXFCodecUL *mxf_get_codec_ul(const MXFCodecUL *uls, UID *uid)
     return uls;
 }
 
+static void *mxf_resolve_strong_ref_reverse(MXFContext *mxf, UID *strong_ref, enum MXFMetadataSetType type)
+{
+    int i;
+    if (!strong_ref)
+        return NULL;
+    for (i = mxf->metadata_sets_count-1; i >= 0 ; i--) {
+        if (!memcmp(*strong_ref, mxf->metadata_sets[i]->uid, 16) &&
+            (type == AnyType || mxf->metadata_sets[i]->type == type)) {
+            return mxf->metadata_sets[i];
+        }
+    }
+    return NULL;
+}
 static void *mxf_resolve_strong_ref(MXFContext *mxf, UID *strong_ref, enum MXFMetadataSetType type)
 {
     int i;
@@ -2328,8 +2341,15 @@ static int mxf_parse_structural_metadata(MXFContext *mxf)
                 continue;
 
             mxf_tc = (MXFTimecodeComponent*)component;
+            if (mxf_tc->start_frame <= 0) {
+                    av_log(mxf->fc, AV_LOG_TRACE, "Header Start Timecode was %d, trying reversed parsing\n",mxf_tc->start_frame);
+                    component = mxf_resolve_strong_ref_reverse(mxf, &material_track->sequence->structural_components_refs[j], TimecodeComponent);
+                    mxf_tc = (MXFTimecodeComponent*)component;
+            }
+
             flags = mxf_tc->drop_frame == 1 ? AV_TIMECODE_FLAG_DROPFRAME : 0;
             if (av_timecode_init(&tc, mxf_tc->rate, flags, mxf_tc->start_frame, mxf->fc) == 0) {
+                av_log(mxf->fc, AV_LOG_TRACE, "Setting Start Timecode: %d \n",mxf_tc->start_frame);
                 mxf_add_timecode_metadata(&mxf->fc->metadata, "timecode", &tc);
                 break;
             }
-- 
2.25.1



More information about the ffmpeg-devel mailing list