diff mbox series

[FFmpeg-devel,v2,1/6] avutil/timecode: allow drop frame timecodes for multiples of 30000/1001 fps

Message ID 20201128184021.17608-1-cus@passwd.hu
State Accepted
Commit 2d90d51c561c2e4c36a00d1ba666adee5028663c
Headers show
Series [FFmpeg-devel,v2,1/6] avutil/timecode: allow drop frame timecodes for multiples of 30000/1001 fps | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished

Commit Message

Marton Balint Nov. 28, 2020, 6:40 p.m. UTC
Signed-off-by: Marton Balint <cus@passwd.hu>
---
 libavutil/timecode.c | 17 +++++++----------
 libavutil/timecode.h |  4 ++--
 2 files changed, 9 insertions(+), 12 deletions(-)

Comments

Marton Balint Dec. 3, 2020, 5:57 p.m. UTC | #1
On Sat, 28 Nov 2020, Marton Balint wrote:

> Signed-off-by: Marton Balint <cus@passwd.hu>
> ---
> libavutil/timecode.c | 17 +++++++----------
> libavutil/timecode.h |  4 ++--
> 2 files changed, 9 insertions(+), 12 deletions(-)

Applied the series.

Regards,
Marton

>
> diff --git a/libavutil/timecode.c b/libavutil/timecode.c
> index f2db21c52c..7caa6c64f5 100644
> --- a/libavutil/timecode.c
> +++ b/libavutil/timecode.c
> @@ -33,16 +33,13 @@
> 
> int av_timecode_adjust_ntsc_framenum2(int framenum, int fps)
> {
> -    /* only works for NTSC 29.97 and 59.94 */
> +    /* only works for multiples of NTSC 29.97 */
>     int drop_frames = 0;
>     int d, m, frames_per_10mins;
> 
> -    if (fps == 30) {
> -        drop_frames = 2;
> -        frames_per_10mins = 17982;
> -    } else if (fps == 60) {
> -        drop_frames = 4;
> -        frames_per_10mins = 35964;
> +    if (fps && fps % 30 == 0) {
> +        drop_frames = fps / 30 * 2;
> +        frames_per_10mins = fps / 30 * 17982;
>     } else
>         return framenum;
> 
> @@ -196,8 +193,8 @@ static int check_timecode(void *log_ctx, AVTimecode *tc)
>         av_log(log_ctx, AV_LOG_ERROR, "Valid timecode frame rate must be specified. Minimum value is 1\n");
>         return AVERROR(EINVAL);
>     }
> -    if ((tc->flags & AV_TIMECODE_FLAG_DROPFRAME) && tc->fps != 30 && tc->fps != 60) {
> -        av_log(log_ctx, AV_LOG_ERROR, "Drop frame is only allowed with 30000/1001 or 60000/1001 FPS\n");
> +    if ((tc->flags & AV_TIMECODE_FLAG_DROPFRAME) && tc->fps % 30 != 0) {
> +        av_log(log_ctx, AV_LOG_ERROR, "Drop frame is only allowed with multiples of 30000/1001 FPS\n");
>         return AVERROR(EINVAL);
>     }
>     if (check_fps(tc->fps) < 0) {
> @@ -252,7 +249,7 @@ int av_timecode_init_from_string(AVTimecode *tc, AVRational rate, const char *st
>     tc->start = (hh*3600 + mm*60 + ss) * tc->fps + ff;
>     if (tc->flags & AV_TIMECODE_FLAG_DROPFRAME) { /* adjust frame number */
>         int tmins = 60*hh + mm;
> -        tc->start -= (tc->fps == 30 ? 2 : 4) * (tmins - tmins/10);
> +        tc->start -= (tc->fps / 30 * 2) * (tmins - tmins/10);
>     }
>     return 0;
> }
> diff --git a/libavutil/timecode.h b/libavutil/timecode.h
> index f9471a6e38..697e61180b 100644
> --- a/libavutil/timecode.h
> +++ b/libavutil/timecode.h
> @@ -49,9 +49,9 @@ typedef struct {
>  * Adjust frame number for NTSC drop frame time code.
>  *
>  * @param framenum frame number to adjust
> - * @param fps      frame per second, 30 or 60
> + * @param fps      frame per second, multiples of 30
>  * @return         adjusted frame number
> - * @warning        adjustment is only valid in NTSC 29.97 and 59.94
> + * @warning        adjustment is only valid for multiples of NTSC 29.97
>  */
> int av_timecode_adjust_ntsc_framenum2(int framenum, int fps);
> 
> -- 
> 2.26.2
>
> _______________________________________________
> 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".
diff mbox series

Patch

diff --git a/libavutil/timecode.c b/libavutil/timecode.c
index f2db21c52c..7caa6c64f5 100644
--- a/libavutil/timecode.c
+++ b/libavutil/timecode.c
@@ -33,16 +33,13 @@ 
 
 int av_timecode_adjust_ntsc_framenum2(int framenum, int fps)
 {
-    /* only works for NTSC 29.97 and 59.94 */
+    /* only works for multiples of NTSC 29.97 */
     int drop_frames = 0;
     int d, m, frames_per_10mins;
 
-    if (fps == 30) {
-        drop_frames = 2;
-        frames_per_10mins = 17982;
-    } else if (fps == 60) {
-        drop_frames = 4;
-        frames_per_10mins = 35964;
+    if (fps && fps % 30 == 0) {
+        drop_frames = fps / 30 * 2;
+        frames_per_10mins = fps / 30 * 17982;
     } else
         return framenum;
 
@@ -196,8 +193,8 @@  static int check_timecode(void *log_ctx, AVTimecode *tc)
         av_log(log_ctx, AV_LOG_ERROR, "Valid timecode frame rate must be specified. Minimum value is 1\n");
         return AVERROR(EINVAL);
     }
-    if ((tc->flags & AV_TIMECODE_FLAG_DROPFRAME) && tc->fps != 30 && tc->fps != 60) {
-        av_log(log_ctx, AV_LOG_ERROR, "Drop frame is only allowed with 30000/1001 or 60000/1001 FPS\n");
+    if ((tc->flags & AV_TIMECODE_FLAG_DROPFRAME) && tc->fps % 30 != 0) {
+        av_log(log_ctx, AV_LOG_ERROR, "Drop frame is only allowed with multiples of 30000/1001 FPS\n");
         return AVERROR(EINVAL);
     }
     if (check_fps(tc->fps) < 0) {
@@ -252,7 +249,7 @@  int av_timecode_init_from_string(AVTimecode *tc, AVRational rate, const char *st
     tc->start = (hh*3600 + mm*60 + ss) * tc->fps + ff;
     if (tc->flags & AV_TIMECODE_FLAG_DROPFRAME) { /* adjust frame number */
         int tmins = 60*hh + mm;
-        tc->start -= (tc->fps == 30 ? 2 : 4) * (tmins - tmins/10);
+        tc->start -= (tc->fps / 30 * 2) * (tmins - tmins/10);
     }
     return 0;
 }
diff --git a/libavutil/timecode.h b/libavutil/timecode.h
index f9471a6e38..697e61180b 100644
--- a/libavutil/timecode.h
+++ b/libavutil/timecode.h
@@ -49,9 +49,9 @@  typedef struct {
  * Adjust frame number for NTSC drop frame time code.
  *
  * @param framenum frame number to adjust
- * @param fps      frame per second, 30 or 60
+ * @param fps      frame per second, multiples of 30
  * @return         adjusted frame number
- * @warning        adjustment is only valid in NTSC 29.97 and 59.94
+ * @warning        adjustment is only valid for multiples of NTSC 29.97
  */
 int av_timecode_adjust_ntsc_framenum2(int framenum, int fps);