ffmpeg | branch: master | Anton Khirnov <an...@khirnov.net> | Wed Sep 25 12:18:31 2024 +0200| [cde307c78301724b8c917df6e535651682cf2f04] | committer: Anton Khirnov
doc/examples/transcode: switch to avcodec_get_supported_config() > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=cde307c78301724b8c917df6e535651682cf2f04 --- doc/examples/transcode.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c index 7d1e1826a3..54fb315236 100644 --- a/doc/examples/transcode.c +++ b/doc/examples/transcode.c @@ -171,23 +171,38 @@ static int open_output_file(const char *filename) * sample rate etc.). These properties can be changed for output * streams easily using filters */ if (dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO) { + const enum AVPixelFormat *pix_fmts = NULL; + enc_ctx->height = dec_ctx->height; enc_ctx->width = dec_ctx->width; enc_ctx->sample_aspect_ratio = dec_ctx->sample_aspect_ratio; + + ret = avcodec_get_supported_config(dec_ctx, NULL, + AV_CODEC_CONFIG_PIX_FORMAT, 0, + (const void**)&pix_fmts, NULL); + /* take first format from list of supported formats */ - if (encoder->pix_fmts) - enc_ctx->pix_fmt = encoder->pix_fmts[0]; - else - enc_ctx->pix_fmt = dec_ctx->pix_fmt; + enc_ctx->pix_fmt = (ret >= 0 && pix_fmts) ? + pix_fmts[0] : dec_ctx->pix_fmt; + /* video time_base can be set to whatever is handy and supported by encoder */ enc_ctx->time_base = av_inv_q(dec_ctx->framerate); } else { + const enum AVSampleFormat *sample_fmts = NULL; + enc_ctx->sample_rate = dec_ctx->sample_rate; ret = av_channel_layout_copy(&enc_ctx->ch_layout, &dec_ctx->ch_layout); if (ret < 0) return ret; + + ret = avcodec_get_supported_config(dec_ctx, NULL, + AV_CODEC_CONFIG_SAMPLE_FORMAT, 0, + (const void**)&sample_fmts, NULL); + /* take first format from list of supported formats */ - enc_ctx->sample_fmt = encoder->sample_fmts[0]; + enc_ctx->sample_fmt = (ret >= 0 && sample_fmts) ? + sample_fmts[0] : dec_ctx->sample_fmt; + enc_ctx->time_base = (AVRational){1, enc_ctx->sample_rate}; } _______________________________________________ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".