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

Reimar Döffinger Reimar.Doeffinger
Sun Jul 5 13:45:45 CEST 2009


Hello,
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.
-------------- next part --------------
Index: ffmpeg.c
===================================================================
--- ffmpeg.c	(revision 19346)
+++ ffmpeg.c	(working copy)
@@ -861,6 +861,7 @@
                          int *frame_size)
 {
     int nb_frames, i, ret;
+    int size_change;
     int64_t topBand, bottomBand, leftBand, rightBand;
     AVFrame *final_picture, *formatted_picture, *resampling_dst, *padding_src;
     AVFrame picture_crop_temp, picture_pad_temp;
@@ -935,14 +936,22 @@
         }
     }
 
+    size_change =  (ost->resample_height != (ist->st->codec->height - (ost->topBand  + ost->bottomBand)))
+                || (ost->resample_width  != (ist->st->codec->width  - (ost->leftBand + ost->rightBand)))
+                || (ost->resample_pix_fmt!= ist->st->codec->pix_fmt);
+    if(size_change) {
+        fprintf(stderr,"Input Stream #%d.%d frame size changed to %dx%d, %s\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 (!ost->video_resample) {
+            if (exit_on_error)
+                av_exit(1);
+            return;
+        }
+    }
     if (ost->video_resample) {
         padding_src = NULL;
         final_picture = &ost->pict_tmp;
-        if(  (ost->resample_height != (ist->st->codec->height - (ost->topBand  + ost->bottomBand)))
-          || (ost->resample_width  != (ist->st->codec->width  - (ost->leftBand + ost->rightBand)))
-          || (ost->resample_pix_fmt!= ist->st->codec->pix_fmt) ) {
+        if(size_change) {
 
-            fprintf(stderr,"Input Stream #%d.%d frame size changed to %dx%d, %s\n", ist->file_index, ist->index, ist->st->codec->width, ist->st->codec->height,avcodec_get_pix_fmt_name(ist->st->codec->pix_fmt));
             /* keep bands proportional to the frame size */
             topBand    = ((int64_t)ist->st->codec->height * ost->original_topBand    / ost->original_height) & ~1;
             bottomBand = ((int64_t)ist->st->codec->height * ost->original_bottomBand / ost->original_height) & ~1;



More information about the ffmpeg-devel mailing list