[FFmpeg-cvslog] timecode: better input checks in init function.

Clément Bœsch git at videolan.org
Mon Dec 12 17:53:42 CET 2011


ffmpeg | branch: master | Clément Bœsch <clement.boesch at smartjog.com> | Tue Dec  6 11:17:37 2011 +0100| [98aca4bbef6818bbc8209a801425c3a6f1ff41a9] | committer: Clément Bœsch

timecode: better input checks in init function.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=98aca4bbef6818bbc8209a801425c3a6f1ff41a9
---

 libavcodec/timecode.c |   38 +++++++++++++++++++++++++++++++-------
 1 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/libavcodec/timecode.c b/libavcodec/timecode.c
index 7f3b1d5..8cd1bec 100644
--- a/libavcodec/timecode.c
+++ b/libavcodec/timecode.c
@@ -55,9 +55,33 @@ uint32_t ff_framenum_to_smtpe_timecode(unsigned frame, int fps, int drop)
            (  (frame / (fps * 3600) % 24)) % 10;          // units of hours
 }
 
+static int check_timecode_rate(void *avcl, AVRational rate, int drop)
+{
+    int fps;
+
+    if (!rate.num || !rate.den) {
+        av_log(avcl, AV_LOG_ERROR, "Timecode frame rate must be specified\n");
+        return -1;
+    }
+    fps = (rate.num + rate.den/2) / rate.den;
+    if (drop && (rate.den != 1001 || fps != 30)) {
+        av_log(avcl, AV_LOG_ERROR, "Drop frame is only allowed with 30000/1001 FPS\n");
+        return -2;
+    }
+    switch (fps) {
+    case 24:
+    case 25:
+    case 30: return  0;
+
+    default:
+        av_log(avcl, AV_LOG_ERROR, "Timecode frame rate not supported\n");
+        return -3;
+    }
+}
+
 int ff_init_smtpe_timecode(void *avcl, struct ff_timecode *tc)
 {
-    int hh, mm, ss, ff, fps;
+    int hh, mm, ss, ff, fps, ret;
     char c;
 
     if (sscanf(tc->str, "%d:%d:%d%c%d", &hh, &mm, &ss, &c, &ff) != 5) {
@@ -66,17 +90,17 @@ int ff_init_smtpe_timecode(void *avcl, struct ff_timecode *tc)
         return -1;
     }
 
+    tc->drop  = c != ':'; // drop if ';', '.', ...
+
+    ret = check_timecode_rate(avcl, tc->rate, tc->drop);
+    if (ret < 0)
+        return ret;
+
     fps       = (tc->rate.num + tc->rate.den/2) / tc->rate.den;
     tc->start = (hh*3600 + mm*60 + ss) * fps + ff;
-    tc->drop  = c != ':'; // drop if ';', '.', ...
 
     if (tc->drop) { /* adjust frame number */
         int tmins = 60*hh + mm;
-        if (tc->rate.den != 1001 || fps != 30) {
-            av_log(avcl, AV_LOG_ERROR, "error: drop frame is only allowed with"
-                                       "30000/1001 FPS");
-            return -2;
-        }
         tc->start -= 2 * (tmins - tmins/10);
     }
     return 0;



More information about the ffmpeg-cvslog mailing list