[Libav-user] New API and transcoding

Gabriele Greco gabriele.greco at wyscout.com
Fri Nov 25 11:32:57 EET 2016


It's some days I'm trying to figure how to do transcoding in 3.1.x without
triggering warnings for AVStream::codec deprecation.

The ffmpeg examples and ffmpeg itself still use this deprecated field, I
have some code that compiles and run, without using AVStream::codec but it
doesn't work well (it seems that the output file is not compressed at

The problem is the stream creation stage:

this is how transcoding.c, ffmpeg and most online code do:

 out_stream = avformat_new_stream(ofmt_ctx, NULL);
 in_stream = ifmt_ctx->streams[i];
 dec_ctx = in_stream->codec;
 enc_ctx = out_stream->codec;
 encoder = avcodec_find_encoder(CODEC_ID_H264);
[copy stuff from dec to enc and set the stuff you want to change]
 avcodec_open2(enc_ctx, encoder, NULL);

this is how I think it should be now:

 out_stream = avformat_new_stream(ofmt_ctx, NULL);
 in_stream = ifmt_ctx->streams[i];
 auto dec_par = in_stream->codecpar, enc_par = out_stream->codecpar;
 encoder = avcodec_find_encoder(CODEC_ID_H264);
 enc_ctx = avcodec_alloc_context3(encoder);
[copy some dec_par to ctx, set the other ctx parameters]
 avcodec_open2(enc_ctx, encoder, NULL);
 avcodec_parameters_from_context(enc_par, ctx);

Is this correct?

Do I have in some way to set the output stream codec to something?

What do I have to do for streams I simpy want to remux that with the old
api are resolved with:



* Gabry*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20161125/927f0f69/attachment.html>

More information about the Libav-user mailing list