[FFmpeg-devel] [PATCH] avoid crashes if input stream size changes without using -r

Reimar Döffinger Reimar.Doeffinger
Sun Jul 5 14:56:44 CEST 2009


On Sun, Jul 05, 2009 at 02:41:51PM +0200, Reimar D?ffinger wrote:
> On Sun, Jul 05, 2009 at 01:45:45PM +0200, Reimar D?ffinger wrote:
> > I don't know why, but currently FFmpeg only checks for an input stream
> > size change when it is using resizing.
> > Which means when you not use resizing it passes incorrectly size frames
> > to the encoder and just crashes, as demonstrated by
> > vp62/smclockvp62hsp.avi.1.0 from issue 1240.
> > Here the container resolution is 32x65568 but the codec changes it to
> > 32x32 - passing that 32x32 frame to e.g. the raw encoder (for framecrc)
> > initialized for 32x65568 obviously crashes.
> > Attached patch mostly just moves some code around to avoid this and
> > print an error instead.
> 
> Sorry, that's of course nonsense, resample_width/resample_height etc.
> are never set when resampling is not used so this just breaks things
> completely.
> I still think that something _similar_ to that is needed, I just don't
> know which are the right variables...

Ok, this one _seems_ to work for me (and passes make test).
I admit I have no idea if padding (the *Band stuff) is taken into account when
ost->video_resample is not set, I assumed that yes...
I have to say that during make test the constant "[NULL @
0x1a764b0]Unknown option 'sws_flags'" is quite annoying, it seems this
is printed by some option parser but then it is passed on to another one
that accepts it?
-------------- next part --------------
Index: ffmpeg.c
===================================================================
--- ffmpeg.c	(revision 19346)
+++ ffmpeg.c	(working copy)
@@ -935,7 +935,16 @@
         }
     }
 
-    if (ost->video_resample) {
+    if (!ost->video_resample) {
+        if(  (ost->st->codec->height != (ist->st->codec->height - (ost->topBand  + ost->bottomBand)))
+          || (ost->st->codec->width  != (ist->st->codec->width  - (ost->leftBand + ost->rightBand)))
+          || (ost->st->codec->pix_fmt!= ist->st->codec->pix_fmt) ) {
+            fprintf(stderr,"Input Stream #%d.%d frame size changed to %dx%d, %s, can not encode frame\n", ist->file_index, ist->index, ist->st->codec->width, ist->st->codec->height,avcodec_get_pix_fmt_name(ist->st->codec->pix_fmt));
+            if (exit_on_error)
+                av_exit(1);
+            return;
+        }
+    } else {
         padding_src = NULL;
         final_picture = &ost->pict_tmp;
         if(  (ost->resample_height != (ist->st->codec->height - (ost->topBand  + ost->bottomBand)))



More information about the ffmpeg-devel mailing list