- if (s->picture.data[0])
- avctx->release_buffer(avctx, &s->picture);
+ if (sys != s->sys) {
+ ret = ff_dv_init_dynamic_tables(s, sys);
+ if (ret < 0) {
+ av_log(avctx, AV_LOG_ERROR, "Error initializing the work tables.\n");
+ return ret;
+ }
+ s->sys = sys;
+ }
+
+ s->frame = frame;
+ frame->key_frame = 1;
+ frame->pict_type = AV_PICTURE_TYPE_I;
+ avctx->pix_fmt = s->sys->pix_fmt;
+ avctx->framerate = av_inv_q(s->sys->time_base);
+
+ ret = ff_set_dimensions(avctx, s->sys->width, s->sys->height);
+ if (ret < 0)
+ return ret;
+
+ /* Determine the codec's sample_aspect ratio from the packet */
+ vsc_pack = buf + 80 * 5 + 48 + 5;
+ if (*vsc_pack == dv_video_control) {
+ apt = buf[4] & 0x07;
+ is16_9 = (vsc_pack[2] & 0x07) == 0x02 ||
+ (!apt && (vsc_pack[2] & 0x07) == 0x07);
+ ff_set_sar(avctx, s->sys->sar[is16_9]);
+ }