diff mbox series

[FFmpeg-devel,3/6] doc/examples/transcode: factorize codec_type definition

Message ID 20230901231447.1486347-3-stefasab@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/6] libavcodec/avcodec.h: fix typos in AVCodecContext.pkt_timebase description | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Stefano Sabatini Sept. 1, 2023, 11:14 p.m. UTC
---
 doc/examples/transcode.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c
index 9af5674953..1ec4a3c230 100644
--- a/doc/examples/transcode.c
+++ b/doc/examples/transcode.c
@@ -82,6 +82,7 @@  static int open_input_file(const char *filename)
         AVStream *stream = ifmt_ctx->streams[i];
         const AVCodec *dec = avcodec_find_decoder(stream->codecpar->codec_id);
         AVCodecContext *codec_ctx;
+        enum AVMediaType codec_type;
 
         if (!dec) {
             av_log(NULL, AV_LOG_ERROR, "Failed to find decoder for stream #%u\n", i);
@@ -105,11 +106,13 @@  static int open_input_file(const char *filename)
         /* Inform the decoder about the timebase for the packet timestamps.
          * This is highly recommended, but not mandatory. */
         codec_ctx->pkt_timebase = stream->time_base;
+        codec_type = codec_ctx->codec_type;
 
         /* Reencode video & audio and remux subtitles etc. */
-        if (codec_ctx->codec_type == AVMEDIA_TYPE_VIDEO || codec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
-            if (codec_ctx->codec_type == AVMEDIA_TYPE_VIDEO)
+        if (codec_type == AVMEDIA_TYPE_VIDEO || codec_type == AVMEDIA_TYPE_AUDIO) {
+            if (codec_type == AVMEDIA_TYPE_VIDEO)
                 codec_ctx->framerate = av_guess_frame_rate(ifmt_ctx, stream, NULL);
+
             /* Open decoder */
             ret = avcodec_open2(codec_ctx, dec, NULL);
             if (ret < 0) {