[Libav-user] Updated libav/ffmpeg tutorial

wm4 nfxjfg at googlemail.com
Tue Feb 17 11:44:04 CET 2015


On Mon, 16 Feb 2015 02:24:38 -0600
Stephen Dranger <dranger at gmail.com> wrote:

> I finally dusted off the old HTML, incorporated chelyaev's code changes,
> and updated my tutorial at:
> 
> http://dranger.com/ffmpeg/
> 
> to represent all of the API changes that have happened over the years. Big
> thanks to chelyaev who kept it up to date. I suspect that there is a lot of
> work to be done to really update the tutorial to keep up with modern
> techniques, but at the very least this tutorial's code is no longer
> rotting.
> 
> All code was compiled and tested on LAVC 54.59.100, LAVF 54.29.104, SWS
> 2.1.101, SDL 1.2.15 on GCC 4.7.2 in Debian.

There are still problems left... I hope I didn't miss anything.

> if(avformat_open_input(&pFormatCtx, argv[1], NULL, 0, NULL)!=0)

Normally, all functions return >= 0 on success, and < 0 on error. The doxygen
says "returns 0 on success", but that doesn't mean much. The API is pretty
consistent about this part.

> if(avcodec_open2(pCodecCtx, pCodec)<0)

You must not use the AVStream's codec context for decoding. Use
avcodec_copy_context().

> numBytes=avpicture_get_size(PIX_FMT_RGB24, pCodecCtx->width,

Don't use AVPicture. Use AVFrame. The AVPicture API is overcomplicated,
and I hope it's deprecated at some point.

> sws_ctx = sws_getContext(pCodecCtx->width,

This doesn't set colorspace information and such. The API is way too
complicated; maybe I'll finish that patch that does it all in 1 API call.

> av_free(pFrameRGB);

No. AVFrame has its own free function.

> if(is->video_st->codec->sample_aspect_ratio.num == 0) {

Not necessarily invalid, but a rather bad idea if the video changes
configuration during decoding. It's better to strictly use AVFrame
fields only. This way you can't run into race conditions either.

> int our_get_buffer(struct AVCodecContext *c, AVFrame *pic) {

Jesus Christ, this is the most broken part about the tutorial (even
uses deprecated functions!), and it's still there. Use
AVFrame.best_effort_timestamp and remove all this code.



More information about the Libav-user mailing list