Skip to content

Instantly share code, notes, and snippets.

@ilovezfs
Last active April 27, 2018 10:53
Show Gist options
  • Save ilovezfs/ca653f1cb191d8b11c3265d3f57b76bc to your computer and use it in GitHub Desktop.
Save ilovezfs/ca653f1cb191d8b11c3265d3f57b76bc to your computer and use it in GitHub Desktop.
diff --git a/decoder_plugins/ffmpeg/ffmpeg.c b/decoder_plugins/ffmpeg/ffmpeg.c
index f1db552..93ac7e7 100644
--- a/decoder_plugins/ffmpeg/ffmpeg.c
+++ b/decoder_plugins/ffmpeg/ffmpeg.c
@@ -309,11 +309,15 @@ static unsigned int find_first_audio (AVFormatContext *ic)
assert (ic);
for (result = 0; result < ic->nb_streams; result += 1) {
-#if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(50,15,1)
- if (ic->streams[result]->codec->codec_type == CODEC_TYPE_AUDIO)
+ enum AVMediaType codec_type;
+
+#ifdef HAVE_STRUCT_AVSTREAM_CODECPAR
+ codec_type = ic->streams[result]->codecpar->codec_type;
#else
- if (ic->streams[result]->codec->codec_type == AVMEDIA_TYPE_AUDIO)
+ codec_type = ic->streams[result]->codec->codec_type;
#endif
+
+ if (codec_type == AVMEDIA_TYPE_AUDIO)
{
break;
}
@@ -973,12 +977,21 @@ static void *ffmpeg_open (const char *file)
goto end;
}
+#ifdef HAVE_STRUCT_AVSTREAM_CODECPAR
+ err = avcodec_parameters_to_context (data->enc, data->stream->codecpar);
+ if (err < 0) {
+ decoder_error (&data->error, ERROR_FATAL, 0,
+ "Failed to copy codec parameters");
+ goto end;
+ }
+#else
err = avcodec_copy_context (data->enc, data->stream->codec);
if (err < 0) {
decoder_error (&data->error, ERROR_FATAL, 0,
"Failed to copy codec context");
goto end;
}
+#endif
data->codec = avcodec_find_decoder (data->enc->codec_id);
if (!data->codec) {
diff --git a/decoder_plugins/ffmpeg/ffmpeg.m4 b/decoder_plugins/ffmpeg/ffmpeg.m4
index 2c60d4a..cf818d3 100644
--- a/decoder_plugins/ffmpeg/ffmpeg.m4
+++ b/decoder_plugins/ffmpeg/ffmpeg.m4
@@ -140,6 +140,8 @@ then
AC_SEARCH_LIBS(avcodec_free_context, avcodec,
[AC_DEFINE([HAVE_AVCODEC_FREE_CONTEXT], 1,
[Define to 1 if you have the `avcodec_free_context' function.])])
+ AC_CHECK_MEMBERS([struct AVStream.codecpar], [], [],
+ [#include <libavformat/avformat.h>])
AC_CHECK_DECLS([CODEC_ID_PCM_S8], , ,
[#include <libavcodec/avcodec.h>])
AC_CHECK_DECLS([CODEC_ID_PCM_S8_PLANAR], , ,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment