[FFmpeg-devel] [PATCH] lavu/ffmpeg_opt: Check return value of avcodec_find_encoder().

Thilo Borgmann thilo.borgmann at mail.de
Thu Sep 25 16:15:56 CEST 2014


Hi,

this was found when an ffserver is configured to output libvpx encoded video but
the feeding ffmpeg has no libvpx support compiled in.

-Thilo
-------------- next part --------------
>From 30adcf74e5eff6e48bd6fee7ad5d9bd68e5429ca Mon Sep 17 00:00:00 2001
From: Thilo Borgmann <thilo.borgmann at mail.de>
Date: Thu, 25 Sep 2014 16:10:58 +0200
Subject: [PATCH] lavu/ffmpeg_opt: Check return value of
 avcodec_find_encoder().

Prevents a segfault if a stream featuring a known but unavailable codec (like external lib codec) should be opened.

Bug found by: Jonas Geistert <j.geistert at yahoo.de>
---
 ffmpeg_opt.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c
index 05ab652..4fb6fa3 100644
--- a/ffmpeg_opt.c
+++ b/ffmpeg_opt.c
@@ -1623,6 +1623,10 @@ static int read_ffserver_streams(OptionsContext *o, AVFormatContext *s, const ch
         AVCodecContext *avctx;
 
         codec = avcodec_find_encoder(ic->streams[i]->codec->codec_id);
+        if (!codec) {
+            av_log(s, AV_LOG_ERROR, "no encoder found for codec id %i\n", ic->streams[i]->codec->codec_id);
+            return AVERROR(EINVAL);
+        }
         ost   = new_output_stream(o, s, codec->type, -1);
         st    = ost->st;
         avctx = st->codec;
-- 
1.8.5.2 (Apple Git-48)



More information about the ffmpeg-devel mailing list