Browse code

RV20: try keeping aspect during resolution changes.

Resolution changes are usually only used to scale with
network bandwidth, the (full) resolution specified in the
RM header really is authoritative.
While I am not sure this is the best solution, it is a
conservative approach that still should fix the most
common cases.
In particular, it fixes aspect with the sample from trac
issue #785 (in MPlayer, ffplay seems to just ignore
sample aspect changes in mid-playback).

Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>

Reimar Döffinger authored on 2012/04/09 21:21:01
Showing 1 changed files
... ...
@@ -371,10 +371,19 @@ static int rv20_decode_picture_header(RVDecContext *rv)
371 371
             new_h= s->orig_height;
372 372
         }
373 373
         if(new_w != s->width || new_h != s->height){
374
+            AVRational old_aspect = s->avctx->sample_aspect_ratio;
374 375
             av_log(s->avctx, AV_LOG_DEBUG, "attempting to change resolution to %dx%d\n", new_w, new_h);
375 376
             if (av_image_check_size(new_w, new_h, 0, s->avctx) < 0)
376 377
                 return -1;
377 378
             ff_MPV_common_end(s);
379
+
380
+            // attempt to keep aspect during typical resolution switches
381
+            if (!old_aspect.num)
382
+                old_aspect = (AVRational){1, 1};
383
+            if (2 * new_w * s->height == new_h * s->width)
384
+                s->avctx->sample_aspect_ratio = av_mul_q(old_aspect, (AVRational){2, 1});
385
+            if (new_w * s->height == 2 * new_h * s->width)
386
+                s->avctx->sample_aspect_ratio = av_mul_q(old_aspect, (AVRational){1, 2});
378 387
             avcodec_set_dimensions(s->avctx, new_w, new_h);
379 388
             s->width  = new_w;
380 389
             s->height = new_h;