The patch quoted below requires quite non-trivial changes to applications. Consider amide's http://amide.sourceforge.net/ mpeg_encode_frame() function:
gboolean mpeg_encode_frame(gpointer data, GdkPixbuf * pixbuf) { encode_t * encode = data; gint out_size; convert_rgb_pixbuf_to_yuv(encode->yuv, pixbuf); /* encode the image */ out_size = avcodec_encode_video(encode->context, encode->output_buffer, encode->output_buffer_size, encode->picture); fwrite(encode->output_buffer, 1, out_size, encode->output_file); return TRUE; }; This application so far has successfully used libavcodec without the use of AVPackets. Can someone help with explaining to amide developers why exactly their code improves by using of avcodec_encode_video2 instead? I'm not even sure if I got this patch right: --- amide-1.0.4.orig/src/mpeg_encode.c +++ amide-1.0.4/src/mpeg_encode.c @@ -268,7 +269,7 @@ gpointer mpeg_encode_setup(gchar * outpu return NULL; } - encode->picture= avcodec_alloc_frame(); + encode->picture= av_frame_alloc(); if (!encode->picture) { g_warning("couldn't allocate memory for encode->picture"); encode_free(encode); @@ -360,14 +361,37 @@ gpointer mpeg_encode_setup(gchar * outpu gboolean mpeg_encode_frame(gpointer data, GdkPixbuf * pixbuf) { encode_t * encode = data; gint out_size; + AVPacket pkt; + int ret, got_packet = 0; convert_rgb_pixbuf_to_yuv(encode->yuv, pixbuf); - /* encode the image */ - out_size = avcodec_encode_video(encode->context, encode->output_buffer, encode->output_buffer_size, encode->picture); - fwrite(encode->output_buffer, 1, out_size, encode->output_file); + av_init_packet(&pkt); + pkt.data = encode->output_buffer; + pkt.size = encode->output_buffer_size; - return TRUE; + /* encode the image */ + ret = avcodec_encode_video2(encode->context, &pkt, encode->picture, &got_packet); + if (!ret && got_packet && encode->context->coded_frame) { + encode->context->coded_frame->pts = pkt.pts; + encode->context->coded_frame->key_frame = !!(pkt.flags & AV_PKT_FLAG_KEY); + } + + /* free any side data since we cannot return it */ + if (pkt.side_data_elems > 0) { + int i; + for (i = 0; i < pkt.side_data_elems; i++) + av_free(pkt.side_data[i].data); + av_freep(&pkt.side_data); + pkt.side_data_elems = 0; + } + + if (!ret) { + fwrite(encode->output_buffer, 1, pkt.size, encode->output_file); + return TRUE; + } else { + return FALSE; + } }; /* close everything up */ It seems to me that the old avcodec_encode_frame api was much easier to use, because it requires less boilerplate and book-keeping. Can't we just revert the patch below, un-deprecate this function and declare it as convenience helper? On Fri, Mar 8, 2013 at 2:17 AM, Anton Khirnov <an...@khirnov.net> wrote: > --- > libavcodec/avcodec.h | 20 -------------------- > libavcodec/utils.c | 36 ------------------------------------ > libavcodec/version.h | 3 --- > 3 files changed, 59 deletions(-) > > diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h > index 0d4ac31..c926d5b 100644 > --- a/libavcodec/avcodec.h > +++ b/libavcodec/avcodec.h > @@ -3726,26 +3726,6 @@ AVCodec *avcodec_find_encoder_by_name(const char > *name); > int avcodec_encode_audio2(AVCodecContext *avctx, AVPacket *avpkt, > const AVFrame *frame, int *got_packet_ptr); > > -#if FF_API_OLD_ENCODE_VIDEO > -/** > - * @deprecated use avcodec_encode_video2() instead. > - * > - * Encode a video frame from pict into buf. > - * The input picture should be > - * stored using a specific format, namely avctx.pix_fmt. > - * > - * @param avctx the codec context > - * @param[out] buf the output buffer for the bitstream of encoded frame > - * @param[in] buf_size the size of the output buffer in bytes > - * @param[in] pict the input picture to encode > - * @return On error a negative value is returned, on success zero or the > number > - * of bytes used from the output buffer. > - */ > -attribute_deprecated > -int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size, > - const AVFrame *pict); > -#endif > - > /** > * Encode a frame of video. > * > diff --git a/libavcodec/utils.c b/libavcodec/utils.c > index 813a133..05aa1df 100644 > --- a/libavcodec/utils.c > +++ b/libavcodec/utils.c > @@ -1245,42 +1245,6 @@ end: > return ret; > } > > -#if FF_API_OLD_ENCODE_VIDEO > -int attribute_align_arg avcodec_encode_video(AVCodecContext *avctx, uint8_t > *buf, int buf_size, > - const AVFrame *pict) > -{ > - AVPacket pkt; > - int ret, got_packet = 0; > - > - if (buf_size < FF_MIN_BUFFER_SIZE) { > - av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n"); > - return -1; > - } > - > - av_init_packet(&pkt); > - pkt.data = buf; > - pkt.size = buf_size; > - > - ret = avcodec_encode_video2(avctx, &pkt, pict, &got_packet); > - if (!ret && got_packet && avctx->coded_frame) { > - avctx->coded_frame->pts = pkt.pts; > - avctx->coded_frame->key_frame = !!(pkt.flags & AV_PKT_FLAG_KEY); > - } > - > - /* free any side data since we cannot return it */ > - if (pkt.side_data_elems > 0) { > - int i; > - for (i = 0; i < pkt.side_data_elems; i++) > - av_free(pkt.side_data[i].data); > - av_freep(&pkt.side_data); > - pkt.side_data_elems = 0; > - } > - > - return ret ? ret : pkt.size; > -} > - > -#endif > - > int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx, > AVPacket *avpkt, > const AVFrame *frame, > diff --git a/libavcodec/version.h b/libavcodec/version.h > index efd5d34..4f92814 100644 > --- a/libavcodec/version.h > +++ b/libavcodec/version.h > @@ -49,9 +49,6 @@ > #ifndef FF_API_REQUEST_CHANNELS > #define FF_API_REQUEST_CHANNELS (LIBAVCODEC_VERSION_MAJOR < 56) > #endif > -#ifndef FF_API_OLD_ENCODE_VIDEO > -#define FF_API_OLD_ENCODE_VIDEO (LIBAVCODEC_VERSION_MAJOR < 55) > -#endif > #ifndef FF_API_MPV_GLOBAL_OPTS > #define FF_API_MPV_GLOBAL_OPTS (LIBAVCODEC_VERSION_MAJOR < 55) > #endif > -- > 1.7.10.4 > > _______________________________________________ > libav-devel mailing list > libav-devel@libav.org > https://lists.libav.org/mailman/listinfo/libav-devel -- regards, Reinhard _______________________________________________ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel