[Ffmpeg-devel] Enforcing "Image Size Must Be Even" rules

Rick Sayre whorfin
Thu Jul 20 23:58:08 CEST 2006


Greetings.

In using ffmpeg, I have found a subtle mistake.  The code goes to great 
lengths
to ensure that any specified resize, crop or pad is an even number of 
pixels.
This can in fact result in an odd-number-of-pixels sized container if
the input images are odd themselves.  Consider a 1920x803 input image
sequence; it needs to be padded or cropped by one pixel in height, but
this is currently impossible.  The patch below [one of many possible
of course, this is just my take on it] defers all "evenness" tests until
we actually have everything are preparing to make an output object.
Thus, "-padheight 1" may be allowed in some circumstances, not in others,
to ensure that the final container size is even.

Cheers

	--Rick

-----------------------------------------

2203a2204,2207
 >     if ((frame_topBand % 2) != 0) {
 >         fprintf(stderr, "Top crop size must be a multiple of 2\n");
 >         exit(1);
 >     }
2217a2222,2225
 >     if ((frame_bottomBand % 2) != 0) {
 >         fprintf(stderr, "Bottom crop size must be a multiple of 2\n");
 >         exit(1);
 >     }
2231a2240,2243
 >     if ((frame_leftBand % 2) != 0) {
 >         fprintf(stderr, "Left crop size must be a multiple of 2\n");
 >         exit(1);
 >     }
2245a2258,2261
 >     if ((frame_rightBand % 2) != 0) {
 >         fprintf(stderr, "Right crop size must be a multiple of 2\n");
 >         exit(1);
 >     }
2258a2275,2278
 >     if ((frame_width % 2) != 0 || (frame_height % 2) != 0) {
 >         fprintf(stderr, "Frame size must be a multiple of 2\n");
 >         exit(1);
 >     }
2299a2320,2323
 >     if ((frame_padtop % 2) != 0) {
 >         fprintf(stderr, "Top pad size must be a multiple of 2\n");
 >         exit(1);
 >     }
2308a2333,2336
 >     if ((frame_padbottom % 2) != 0) {
 >         fprintf(stderr, "Bottom pad size must be a multiple of 2\n");
 >         exit(1);
 >     }
2318a2347,2350
 >     if ((frame_padleft % 2) != 0) {
 >         fprintf(stderr, "Left pad size must be a multiple of 2\n");
 >         exit(1);
 >     }
2328a2361,2364
 >     if ((frame_padright % 2) != 0) {
 >         fprintf(stderr, "Right pad size must be a multiple of 2\n");
 >         exit(1);
 >     }
3012,3019d3047
<
<       if ((video_enc->width % 2) != 0 || (video_enc->height % 2) != 0) {
<           fprintf(stderr,
<               "Error for %s:  Resultant size [%dx%d] not a multiple of 
2\n",
<               oc->filename, video_enc->width, video_enc->height);
<           exit(1);
<       }
<




More information about the ffmpeg-devel mailing list