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

Michael Niedermayer michaelni
Wed May 27 14:20:45 CEST 2009


On Mon, May 25, 2009 at 07:07:29PM -0700, Eric Buehl wrote:
> Here is a simple implementation of option #2.  I have changed the
> top/left/right/bottomBand variables to floats in order to not loose rounding
> factors whenever a band scaling takes place.  The only remaining global
> variable that I see is the sws_flags and sws_opts.

>  ffmpeg.c |   51 ++++++++++++++++++++++++++++++++++++++++++++++++---
>  1 file changed, 48 insertions(+), 3 deletions(-)
> ca2340673e201a7091001c42fbecd4af5b1998dd  dynamic_frame_height_adjust_v4.patch
> Index: ffmpeg.c
> ===================================================================
> --- ffmpeg.c	(revision 18951)
> +++ ffmpeg.c	(working copy)
> @@ -236,6 +236,8 @@
>  
>  #define DEFAULT_PASS_LOGFILENAME_PREFIX "ffmpeg2pass"
>  
> +#define NORM_BAND(b) FFMAX(((int)(b) - ((int)(b) % 2)), 0)
> +
>  struct AVInputStream;
>  
>  typedef struct AVOutputStream {
> @@ -255,10 +257,13 @@
>      AVFrame pict_tmp;      /* temporary image for resampling */
>      struct SwsContext *img_resample_ctx; /* for image resampling */
>      int resample_height;
> +    int resample_width;
>  
>      int video_crop;
> -    int topBand;             /* cropping area sizes */
> -    int leftBand;
> +    float topBand;             /* cropping area sizes */
> +    float bottomBand;          /* to be used with NORM_BAND() macro */
> +    float leftBand;
> +    float rightBand;
>  
>      int video_pad;
>      int padtop;              /* padding area sizes */
> @@ -848,6 +853,8 @@
>                           int *frame_size)
>  {
>      int nb_frames, i, ret;
> +    int original_height, original_width;
> +    float height_change_ratio, width_change_ratio;
>      AVFrame *final_picture, *formatted_picture, *resampling_dst, *padding_src;
>      AVFrame picture_crop_temp, picture_pad_temp;
>      AVCodecContext *enc, *dec;
> @@ -894,7 +901,7 @@
>          return;
>  
>      if (ost->video_crop) {
> -        if (av_picture_crop((AVPicture *)&picture_crop_temp, (AVPicture *)in_picture, dec->pix_fmt, ost->topBand, ost->leftBand) < 0) {
> +        if (av_picture_crop((AVPicture *)&picture_crop_temp, (AVPicture *)in_picture, dec->pix_fmt, NORM_BAND(ost->topBand), NORM_BAND(ost->leftBand)) < 0) {
>              fprintf(stderr, "error cropping picture\n");
>              if (exit_on_error)
>                  av_exit(1);
> @@ -924,6 +931,41 @@
>      if (ost->video_resample) {
>          padding_src = NULL;
>          final_picture = &ost->pict_tmp;
> +        if(   (ost->resample_height != (ist->st->codec->height - (NORM_BAND(ost->topBand) + NORM_BAND(ost->bottomBand))))
> +           || (ost->resample_width != (ist->st->codec->width - (NORM_BAND(ost->leftBand) + NORM_BAND(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 */
> +            original_height = ost->resample_height + NORM_BAND(ost->topBand) + NORM_BAND(ost->bottomBand);
> +            original_width = ost->resample_width + NORM_BAND(ost->leftBand) + NORM_BAND(ost->rightBand);

> +            height_change_ratio = (float)(ist->st->codec->height) / (float)original_height;
> +            width_change_ratio = (float)(ist->st->codec->width) / (float)original_width;

vertical align:(looks prettier)

height_change_ratio = (float)(ist->st->codec->height) / (float)original_height;
width_change_ratio  = (float)(ist->st->codec-> width) / (float)original_width;

there are also redundant casts and () in there


> +            ost->topBand *= height_change_ratio;
> +            ost->bottomBand *= height_change_ratio;
> +            ost->leftBand *= width_change_ratio;
> +            ost->rightBand *= width_change_ratio;

I would prefer a solution that was free of possible roundof error
accumulation


> +            ost->resample_height = ist->st->codec->height - (NORM_BAND(ost->topBand) + NORM_BAND(ost->bottomBand));
> +            ost->resample_width = ist->st->codec->width -  (NORM_BAND(ost->leftBand) + NORM_BAND(ost->rightBand));

i see nothing that gurantees resample_width to stay > 0

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

He who knows, does not speak. He who speaks, does not know. -- Lao Tsu
-------------- 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/20090527/9cc1c570/attachment.pgp>



More information about the ffmpeg-devel mailing list