if (buf[VAUX_TC61_OFFSET] == 0x61 && ((apt == 0 && (buf[VAUX_TC61_OFFSET + 2] & 0x07) == 0x07) || (apt == 1 && (buf[VAUX_TC61_OFFSET + 2] & 0x07) == 0x02))) avctx->aspect_ratio = 16.0 / 9.0; else avctx->aspect_ratio = 4.0 / 3.0;
static int dvvideo_decode_frame(AVCodecContext *avctx,                                  void *data, int *data_size,                                 uint8_t *buf, int buf_size){    DVVideoDecodeContext *s = avctx->priv_data;    int sct, dsf, apt, ds, nb_dif_segs, vs, width, height, i, packet_size;    uint8_t *buf_ptr;    const uint16_t *mb_pos_ptr;        /* parse id */    init_get_bits(&s->gb, buf, buf_size*8);    sct = get_bits(&s->gb, 3);    if (sct != 0)        return -1;    skip_bits(&s->gb, 5);    get_bits(&s->gb, 4); /* dsn (sequence number */    get_bits(&s->gb, 1); /* fsc (channel number) */    skip_bits(&s->gb, 3);    get_bits(&s->gb, 8); /* dbn (diff block number 0-134) */    dsf = get_bits(&s->gb, 1); /* 0 = NTSC 1 = PAL */    if (get_bits(&s->gb, 1) != 0)        return -1;    skip_bits(&s->gb, 11);    apt = get_bits(&s->gb, 3); /* apt */    get_bits(&s->gb, 1); /* tf1 */    skip_bits(&s->gb, 4);    get_bits(&s->gb, 3); /* ap1 */    get_bits(&s->gb, 1); /* tf2 */    skip_bits(&s->gb, 4);    get_bits(&s->gb, 3); /* ap2 */    get_bits(&s->gb, 1); /* tf3 */    skip_bits(&s->gb, 4);    get_bits(&s->gb, 3); /* ap3 */        /* init size */    width = 720;    if (dsf) {        avctx->frame_rate = 25;        packet_size = PAL_FRAME_SIZE;        height = 576;        nb_dif_segs = 12;    } else {        avctx->frame_rate = 30;        packet_size = NTSC_FRAME_SIZE;        height = 480;        nb_dif_segs = 10;    }    avctx->frame_rate_base= 1;    /* NOTE: we only accept several full frames */    if (buf_size < packet_size)        return -1;        /* NTSC[dsf == 0] is always 720x480, 4:1:1     *  PAL[dsf == 1] is always 720x576, 4:2:0 for IEC 68134[apt == 0]     *  but for the SMPTE 314M[apt == 1] it is 720x576, 4:1:1     */    s->sampling_411 = !dsf || apt;    if (s->sampling_411) {        mb_pos_ptr = dsf ? dv_place_411P : dv_place_411;        avctx->pix_fmt = PIX_FMT_YUV411P;    } else {        mb_pos_ptr = dv_place_420;        avctx->pix_fmt = PIX_FMT_YUV420P;    }    avctx->width = width;    avctx->height = height;    s->picture.reference= 0;    if(avctx->get_buffer(avctx, &s->picture) < 0) {        fprintf(stderr, "get_buffer() failed\n");        return -1;    }    for(i=0;i<3;i++) {        s->current_picture[i] = s->picture.data[i];        s->linesize[i] = s->picture.linesize[i];        if (!s->current_picture[i])            return -1;    }    s->width = width;    s->height = height;    /* for each DIF segment */    buf_ptr = buf;    for (ds = 0; ds < nb_dif_segs; ds++) {        buf_ptr += 6 * 80; /* skip DIF segment header */                for(vs = 0; vs < 27; vs++) {            if ((vs % 3) == 0) {                /* skip audio block */                buf_ptr += 80;            }            dv_decode_video_segment(s, buf_ptr, mb_pos_ptr);            buf_ptr += 5 * 80;            mb_pos_ptr += 5;        }    }    emms_c();    /* return image */    *data_size = sizeof(AVFrame);    *(AVFrame*)data= s->picture;        avctx->release_buffer(avctx, &s->picture);        return packet_size;}