add av_dv_codec_profile2 : uses framerate to select best matching profile. default...
[ffmpeg.git] / libavcodec / dv_profile.c
index b301cbf..e336e08 100644 (file)
@@ -314,16 +314,36 @@ const AVDVProfile *av_dv_frame_profile(const AVDVProfile *sys,
 const AVDVProfile *av_dv_codec_profile(int width, int height,
                                        enum AVPixelFormat pix_fmt)
 {
+#if CONFIG_DVPROFILE
+    return av_dv_codec_profile2(width, height, pix_fmt, (AVRational){0, 0});
+#endif
+
+    return NULL;
+}
+
+const AVDVProfile *av_dv_codec_profile2(int width, int height,
+                                       enum AVPixelFormat pix_fmt,
+                                       AVRational frame_rate)
+{
+    const AVDVProfile *p = NULL;
 #if CONFIG_DVPROFILE
     int i;
+    /* frame rate is necessary to select between 720p50 and 720p60 profiles */
+    int invalid_framerate = frame_rate.num == 0 || frame_rate.den == 0;
 
     for (i = 0; i < FF_ARRAY_ELEMS(dv_profiles); i++)
         if (height  == dv_profiles[i].height  &&
             pix_fmt == dv_profiles[i].pix_fmt &&
             width   == dv_profiles[i].width)
-            return &dv_profiles[i];
+        {
+            if( invalid_framerate || av_div_q(dv_profiles[i].time_base, frame_rate).num == 1 )
+                return &dv_profiles[i];
+
+            if(!p)
+                p = &dv_profiles[i];
+        }
 #endif
 
-    return NULL;
+    return p;
 }