[Ffmpeg-devel] [PATCH] a fix in ffmpeg.c

Limin Wang lance.lmwang
Tue Jan 23 04:06:53 CET 2007


Hi,

> this looks better but it still has problems
> first it overrides the demuxer timebase blindly, which breaks some
> h264 in avi/mov, also it breaks user specified timebases 
> (ffmpeg -r 12 myfile.h264 out.abc)
> 
> so the check should not be for CODEC_ID_H264 but rather for the lack of
> a set timebase (this needs some change to libavformat/raw.c more specifically
> the hardcoded 1/25 timebase there should be changed to 0/0) then utils.c
> somewhere should check for this and set it to the codec timebase
> st->codec->time_base with av_set_pts_info or if that also is 0/0 then 
> use some random default like 1/25

I have fixed by your suggestion, please review the attached patch. One problem
is it'll cause av_rescale_q() in utils.c floating point exception, I don't know
what's the background. After comment it out, I can pass the test without
problem.(my test case, h264->yuv, h264->yuv(-r fps), mov->yuv, mp4->yuv).


(gdb) bt
#0  0x0843fa27 in __divdi3 ()
#1  0x0843d1f5 in av_rescale_rnd (a=0, b=0, c=0, rnd=AV_ROUND_NEAR_INF) at
mathematics.c:65
#2  0x0843d2a4 in av_rescale_q (a=1, bq={num = 0, den = 0}, cq={num = 1, den =
1000000}) at mathematics.c:111
#3  0x080659eb in av_find_stream_info (ic=0x8546f90) at utils.c:1945
#4  0x08057a09 in opt_input_file (filename=0xbfc5d89e "/tmp/akiyo_cif.h264")
at ffmpeg.c:2596
#5  0x0806042c in parse_options (argc=6, argv=0xbfc5d364, options=0x8442900)
at cmdutils.c:105
#6  0x0805d51a in main (argc=6, argv=0xbfc5d364) at ffmpeg.c:3921



Thanks,
Limin
-------------- next part --------------
Index: ffmpeg.c
===================================================================
--- ffmpeg.c	(revision 7639)
+++ ffmpeg.c	(working copy)
@@ -107,8 +107,8 @@
 static int frame_leftBand  = 0;
 static int frame_rightBand = 0;
 static int max_frames[4] = {INT_MAX, INT_MAX, INT_MAX, INT_MAX};
-static int frame_rate = 25;
-static int frame_rate_base = 1;
+static int frame_rate = 0;
+static int frame_rate_base = 0;
 static float video_qscale = 0;
 static int video_qdiff = 3;
 static uint16_t *intra_matrix = NULL;
Index: libavformat/utils.c
===================================================================
--- libavformat/utils.c	(revision 7639)
+++ libavformat/utils.c	(working copy)
@@ -1941,10 +1941,11 @@
              st->codec->codec_id == CODEC_ID_SHORTEN ||
              (st->codec->codec_id == CODEC_ID_MPEG4 && !st->need_parsing))*/)
             try_decode_frame(st, pkt->data, pkt->size);
-
+#if 0
         if (av_rescale_q(st->codec_info_duration, st->time_base, AV_TIME_BASE_Q) >= MAX_STREAM_DURATION) {
             break;
         }
+#endif		
         count++;
     }
 
@@ -1988,6 +1989,12 @@
                     st->r_frame_rate.den = st->time_base.num;
                 }
             }
+			
+            /* update with real frame rate if user didn't force it */
+            if( !st->time_base.num )
+                av_set_pts_info(st, 64, st->r_frame_rate.num, st->r_frame_rate.den);
+            else	
+                av_set_pts_info(st, 64, 1, 25);
         }
     }
 
Index: libavformat/raw.c
===================================================================
--- libavformat/raw.c	(revision 7639)
+++ libavformat/raw.c	(working copy)
@@ -304,11 +304,13 @@
     /* for mjpeg, specify frame rate */
     /* for mpeg4 specify it too (most mpeg4 streams dont have the fixed_vop_rate set ...)*/
     if (ap->time_base.num) {
+        /* user force fps */
         av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
     } else if ( st->codec->codec_id == CODEC_ID_MJPEG ||
                 st->codec->codec_id == CODEC_ID_MPEG4 ||
                 st->codec->codec_id == CODEC_ID_H264) {
-        av_set_pts_info(st, 64, 1, 25);
+        /* default is 0/0 */
+        av_set_pts_info(st, 64, 0, 0);
     }
 
     return 0;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 481 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070123/97e17109/attachment.pgp>



More information about the ffmpeg-devel mailing list