Revision abf8342a ffmpeg.c

View differences:

ffmpeg.c
151 151
static int frame_width  = 0;
152 152
static int frame_height = 0;
153 153
static float frame_aspect_ratio = 0;
154
static int frame_aspect_ratio_override = 0;
155 154
static enum PixelFormat frame_pix_fmt = PIX_FMT_NONE;
156 155
static int frame_bits_per_raw_sample = 0;
157 156
static enum AVSampleFormat audio_sample_fmt = AV_SAMPLE_FMT_NONE;
......
287 286
    int resample_width;
288 287
    int resample_pix_fmt;
289 288

  
289
    float frame_aspect_ratio;
290

  
290 291
    /* full frame size of first frame */
291 292
    int original_height;
292 293
    int original_width;
......
431 432
    codec->width  = ost->output_video_filter->inputs[0]->w;
432 433
    codec->height = ost->output_video_filter->inputs[0]->h;
433 434
    codec->sample_aspect_ratio = ost->st->sample_aspect_ratio =
435
        ost->frame_aspect_ratio ? // overriden by the -aspect cli option
436
        av_d2q(ost->frame_aspect_ratio*codec->height/codec->width, 255) :
434 437
        ost->output_video_filter->inputs[0]->sample_aspect_ratio;
435 438

  
436 439
    return 0;
......
1696 1699
                            break;
1697 1700
                        case AVMEDIA_TYPE_VIDEO:
1698 1701
#if CONFIG_AVFILTER
1699
                            if (ost->picref->video)
1702
                            if (ost->picref->video && !ost->frame_aspect_ratio)
1700 1703
                                ost->st->codec->sample_aspect_ratio = ost->picref->video->pixel_aspect;
1701 1704
#endif
1702 1705
                            do_video_out(os, ost, ist, &picture, &frame_size);
......
2243 2246
                codec->width = icodec->width;
2244 2247
                codec->height = icodec->height;
2245 2248
                codec->has_b_frames = icodec->has_b_frames;
2249
                if (!codec->sample_aspect_ratio.num) {
2250
                    codec->sample_aspect_ratio =
2251
                    ost->st->sample_aspect_ratio =
2252
                        ist->st->sample_aspect_ratio.num ? ist->st->sample_aspect_ratio :
2253
                        ist->st->codec->sample_aspect_ratio.num ?
2254
                        ist->st->codec->sample_aspect_ratio : (AVRational){0, 1};
2255
                }
2246 2256
                break;
2247 2257
            case AVMEDIA_TYPE_SUBTITLE:
2248 2258
                codec->width = icodec->width;
......
2904 2914
        ffmpeg_exit(1);
2905 2915
    }
2906 2916
    frame_aspect_ratio = ar;
2907
    frame_aspect_ratio_override = 1;
2908 2917
}
2909 2918

  
2910 2919
static int opt_metadata(const char *opt, const char *arg)
......
3342 3351
            set_context_opts(dec, avcodec_opts[AVMEDIA_TYPE_VIDEO], AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM, input_codecs[nb_input_codecs-1]);
3343 3352
            frame_height = dec->height;
3344 3353
            frame_width  = dec->width;
3345
            if(ic->streams[i]->sample_aspect_ratio.num)
3346
                frame_aspect_ratio=av_q2d(ic->streams[i]->sample_aspect_ratio);
3347
            else
3348
                frame_aspect_ratio=av_q2d(dec->sample_aspect_ratio);
3349
            frame_aspect_ratio *= (float) dec->width / dec->height;
3350
            frame_aspect_ratio_override = 0;
3351 3354
            frame_pix_fmt = dec->pix_fmt;
3352 3355
            rfps      = ic->streams[i]->r_frame_rate.num;
3353 3356
            rfps_base = ic->streams[i]->r_frame_rate.den;
......
3452 3455
    AVCodecContext *video_enc;
3453 3456
    enum CodecID codec_id = CODEC_ID_NONE;
3454 3457
    AVCodec *codec= NULL;
3455
    int i;
3456 3458

  
3457 3459
    st = av_new_stream(oc, oc->nb_streams < nb_streamid_map ? streamid_map[oc->nb_streams] : 0);
3458 3460
    if (!st) {
......
3472 3474
            codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, AVMEDIA_TYPE_VIDEO);
3473 3475
            codec = avcodec_find_encoder(codec_id);
3474 3476
        }
3477
        ost->frame_aspect_ratio = frame_aspect_ratio;
3478
        frame_aspect_ratio = 0;
3475 3479
#if CONFIG_AVFILTER
3476
        if(frame_aspect_ratio_override){
3477
            i = vfilters ? strlen(vfilters) : 0;
3478
            vfilters = av_realloc(vfilters, i+100);
3479
            snprintf(vfilters+i, 100, "%csetdar=%f\n", i?',':' ', frame_aspect_ratio);
3480
            frame_aspect_ratio=0;
3481
            frame_aspect_ratio_override=0;
3482
        }
3483

  
3484 3480
        ost->avfilter= vfilters;
3485 3481
        vfilters= NULL;
3486 3482
#endif
......
3527 3523

  
3528 3524
        video_enc->width = frame_width;
3529 3525
        video_enc->height = frame_height;
3530
        video_enc->sample_aspect_ratio = av_d2q(frame_aspect_ratio*video_enc->height/video_enc->width, 255);
3531 3526
        video_enc->pix_fmt = frame_pix_fmt;
3532 3527
        video_enc->bits_per_raw_sample = frame_bits_per_raw_sample;
3533 3528
        st->sample_aspect_ratio = video_enc->sample_aspect_ratio;

Also available in: Unified diff