[FFmpeg-devel] [PATCH][RFC] variable frame sizes

Michael Niedermayer michaelni
Tue Jun 2 13:13:20 CEST 2009


On Thu, May 28, 2009 at 02:28:10AM -0700, Eric Buehl wrote:
> > I would prefer a solution that was free of possible roundof error
> > accumulation
> >
> 
> v5.patch with integer resizing of crop bands.

>  ffmpeg.c |   55 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 53 insertions(+), 2 deletions(-)
> 6405bf53c8b4f65b3a0403710878cf105be9b526  dynamic_frame_height_adjust_v5.patch
> Index: ffmpeg.c
> ===================================================================
> --- ffmpeg.c	(revision 18971)
> +++ ffmpeg.c	(working copy)
> @@ -255,11 +255,22 @@
>      AVFrame pict_tmp;      /* temporary image for resampling */
>      struct SwsContext *img_resample_ctx; /* for image resampling */
>      int resample_height;
> +    int resample_width;
>  
> +    int original_height;     /* full frame size of first frame */
> +    int original_width;

comment should be doxygen compatible


> +
>      int video_crop;
>      int topBand;             /* cropping area sizes */
> +    int bottomBand;
>      int leftBand;
> +    int rightBand;
>  
> +    int original_topBand;    /* cropping area of first frame */
> +    int original_bottomBand;
> +    int original_leftBand;
> +    int original_rightBand;
> +
>      int video_pad;
>      int padtop;              /* padding area sizes */
>      int padbottom;

> @@ -838,6 +849,8 @@
>      }
>  }
>  
> +#define MAKE_EVEN(x) ((x) - ((x) % 2))

x&~1


> +
>  static int bit_buffer_size= 1024*256;
>  static uint8_t *bit_buffer= NULL;
>  
> @@ -924,6 +937,37 @@
>      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)))) {

could be aligned to

if(   (ost->resample_height != (ist->st->codec->height - (ost->topBand  + ost->bottomBand)))
   || (ost->resample_width  != (ist->st->codec->width  - (ost->leftBand + ost->rightBand )))) {


> +
> +
> +            fprintf(stderr,"Input Stream #%d.%d frame size changed to %dx%d\n", ist->file_index, ist->index, ist->st->codec->width, ist->st->codec->height);

> +            /* keep bands proportional to the frame size */
> +            ost->topBand    = MAKE_EVEN(ist->st->codec->height * ost->original_topBand / ost->original_height);
> +            ost->bottomBand = MAKE_EVEN(ist->st->codec->height * ost->original_bottomBand / ost->original_height);
> +            ost->leftBand   = MAKE_EVEN(ist->st->codec->width * ost->original_leftBand / ost->original_width);
> +            ost->rightBand  = MAKE_EVEN(ist->st->codec->width * ost->original_rightBand / ost->original_width);

The multiply can overflow

also its not guranteed that the new *Band values fit in 32bit, one
probably could generate a mallicious stream where this is not the case
(this would even affect float code probably)


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Everything should be made as simple as possible, but not simpler.
-- Albert Einstein
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090602/b79ff115/attachment.pgp>



More information about the ffmpeg-devel mailing list