1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-11-23 21:54:53 +02:00

doc/examples/transcode: switch to avcodec_get_supported_config()

This commit is contained in:
Anton Khirnov
2024-09-25 12:18:31 +02:00
parent d18d119b8f
commit cde307c783

View File

@@ -171,23 +171,38 @@ static int open_output_file(const char *filename)
* sample rate etc.). These properties can be changed for output * sample rate etc.). These properties can be changed for output
* streams easily using filters */ * streams easily using filters */
if (dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO) { if (dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO) {
const enum AVPixelFormat *pix_fmts = NULL;
enc_ctx->height = dec_ctx->height; enc_ctx->height = dec_ctx->height;
enc_ctx->width = dec_ctx->width; enc_ctx->width = dec_ctx->width;
enc_ctx->sample_aspect_ratio = dec_ctx->sample_aspect_ratio; 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 */ /* take first format from list of supported formats */
if (encoder->pix_fmts) enc_ctx->pix_fmt = (ret >= 0 && pix_fmts) ?
enc_ctx->pix_fmt = encoder->pix_fmts[0]; pix_fmts[0] : dec_ctx->pix_fmt;
else
enc_ctx->pix_fmt = dec_ctx->pix_fmt;
/* video time_base can be set to whatever is handy and supported by encoder */ /* video time_base can be set to whatever is handy and supported by encoder */
enc_ctx->time_base = av_inv_q(dec_ctx->framerate); enc_ctx->time_base = av_inv_q(dec_ctx->framerate);
} else { } else {
const enum AVSampleFormat *sample_fmts = NULL;
enc_ctx->sample_rate = dec_ctx->sample_rate; enc_ctx->sample_rate = dec_ctx->sample_rate;
ret = av_channel_layout_copy(&enc_ctx->ch_layout, &dec_ctx->ch_layout); ret = av_channel_layout_copy(&enc_ctx->ch_layout, &dec_ctx->ch_layout);
if (ret < 0) if (ret < 0)
return ret; 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 */ /* 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}; enc_ctx->time_base = (AVRational){1, enc_ctx->sample_rate};
} }