[FFmpeg-devel] [PATCH 3/3] libxvid: encode a dummy frame to get the extradata.
Nicolas George
nicolas.george at normalesup.org
Sun Apr 8 00:58:22 CEST 2012
Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
libavcodec/libxvidff.c | 29 +++++++++++++++++++++++++++++
1 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/libavcodec/libxvidff.c b/libavcodec/libxvidff.c
index e1015d9..d297dfe 100644
--- a/libavcodec/libxvidff.c
+++ b/libavcodec/libxvidff.c
@@ -734,6 +734,35 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) {
xvid_enc_create.bquant_ratio = 100 * avctx->b_quant_factor;
if( avctx->max_b_frames > 0 && !x->quicktime_format ) xvid_enc_create.global |= XVID_GLOBAL_PACKED;
+ /* Encode a dummy frame to get the extradata immediately */
+ if (x->quicktime_format) {
+ AVFrame picture;
+ AVPacket packet;
+ int size, got_packet, ret;
+
+ xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL);
+ if( xerr ) {
+ av_log(avctx, AV_LOG_ERROR, "Xvid: Could not create encoder reference\n");
+ return -1;
+ }
+ x->encoder_handle = xvid_enc_create.handle;
+ avctx->coded_frame = &x->encoded_picture;
+ avcodec_get_frame_defaults(&picture);
+ size = avctx->width * avctx->height;
+ picture.data[0] = av_malloc(size + size / 2);
+ if (!picture.data[0])
+ return AVERROR(ENOMEM);
+ picture.data[1] = picture.data[0] + size;
+ picture.data[2] = picture.data[1] + size / 4;
+ memset(picture.data[0], 0, size);
+ memset(picture.data[1], 128, size / 2);
+ ret = xvid_encode_frame(avctx, &packet, &picture, &got_packet);
+ if (!ret && got_packet)
+ av_free_packet(&packet);
+ av_free(picture.data[0]);
+ xvid_encore(x->encoder_handle, XVID_ENC_DESTROY, NULL, NULL);
+ }
+
/* Create encoder context */
xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL);
if( xerr ) {
--
1.7.9.1
More information about the ffmpeg-devel
mailing list