aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2024-09-25 12:18:31 +0200
committerAnton Khirnov <anton@khirnov.net>2024-09-28 17:04:33 +0200
commitcde307c78301724b8c917df6e535651682cf2f04 (patch)
tree03bad1c6e9c4331eca4c78bc235e31dbfe7fd90e
parentd18d119b8fc09023668eaecc33f839ba06e7a1ec (diff)
downloadffmpeg-cde307c78301724b8c917df6e535651682cf2f04.tar.gz
doc/examples/transcode: switch to avcodec_get_supported_config()
-rw-r--r--doc/examples/transcode.c25
1 files 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};
}