-
-
Save astrataro/4145836 to your computer and use it in GitHub Desktop.
sox ffmpeg support fix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/m4/ffmpeg.m4 b/m4/ffmpeg.m4 | |
index 11c8623..40e5ac4 100644 | |
--- a/m4/ffmpeg.m4 | |
+++ b/m4/ffmpeg.m4 | |
@@ -49,7 +49,7 @@ then | |
LIBS="$LIBS $FFMPEG_LIBS" | |
have_ffmpeg="no" | |
AC_CHECK_HEADERS([libavformat/avformat.h ffmpeg/avformat.h], | |
- [AC_CHECK_LIB(avformat, av_open_input_file, | |
+ [AC_CHECK_LIB(avformat, avformat_open_input, | |
[AC_CHECK_HEADERS([libavcodec/avcodec.h ffmpeg/avcodec.h], | |
[AC_CHECK_LIB(avcodec, avcodec_decode_audio3, have_ffmpeg=yes)])]) | |
break]) | |
diff --git a/src/ffmpeg.c b/src/ffmpeg.c | |
index 09bfc26..5f29e14 100644 | |
--- a/src/ffmpeg.c | |
+++ b/src/ffmpeg.c | |
@@ -90,13 +90,9 @@ static int stream_component_open(priv_t * ffmpeg, int stream_index) | |
codec = avcodec_find_decoder(enc->codec_id); | |
enc->workaround_bugs = 1; | |
-#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0) | |
- enc->error_resilience = 1; | |
-#else | |
- enc->error_recognition = 1; | |
-#endif | |
+ enc->err_recognition = 1; | |
- if (!codec || avcodec_open(enc, codec) < 0) | |
+ if (!codec || avcodec_open2(enc, codec, 0) < 0) | |
return -1; | |
if (enc->codec_type != AVMEDIA_TYPE_AUDIO) { | |
lsx_fail("ffmpeg CODEC %x is not an audio CODEC", enc->codec_type); | |
@@ -157,7 +153,7 @@ static int audio_decode_frame(priv_t * ffmpeg, uint8_t *audio_buf, int buf_size) | |
static int startread(sox_format_t * ft) | |
{ | |
priv_t * ffmpeg = (priv_t *)ft->priv; | |
- AVFormatParameters params; | |
+ AVDictionary *opts = 0; | |
int ret; | |
int i; | |
@@ -171,14 +167,13 @@ static int startread(sox_format_t * ft) | |
av_register_all(); | |
/* Open file and get format */ | |
- memset(¶ms, 0, sizeof(params)); | |
- if ((ret = av_open_input_file(&ffmpeg->ctxt, ft->filename, NULL, 0, ¶ms)) < 0) { | |
+ if ((ret = avformat_open_input(&ffmpeg->ctxt, ft->filename, 0, &opts)) < 0) { | |
lsx_fail("ffmpeg cannot open file for reading: %s (code %d)", ft->filename, ret); | |
return SOX_EOF; | |
} | |
/* Get CODEC parameters */ | |
- if ((ret = av_find_stream_info(ffmpeg->ctxt)) < 0) { | |
+ if ((ret = avformat_find_stream_info(ffmpeg->ctxt, 0)) < 0) { | |
lsx_fail("ffmpeg could not find CODEC parameters for %s", ft->filename); | |
return SOX_EOF; | |
} | |
@@ -231,7 +226,7 @@ static size_t read_samples(sox_format_t * ft, sox_sample_t *buf, size_t len) | |
/* If input buffer empty, read more data */ | |
if (ffmpeg->audio_buf_index * 2 >= ffmpeg->audio_buf_size) { | |
if ((ret = av_read_frame(ffmpeg->ctxt, pkt)) < 0 && | |
- (ret == AVERROR_EOF || url_ferror(ffmpeg->ctxt->pb))) | |
+ (ret == AVERROR_EOF || ffmpeg->ctxt->pb->error)) | |
break; | |
ffmpeg->audio_buf_size = audio_decode_frame(ffmpeg, ffmpeg->audio_buf_aligned, AVCODEC_MAX_AUDIO_FRAME_SIZE); | |
ffmpeg->audio_buf_index = 0; | |
@@ -256,7 +251,7 @@ static int stopread(sox_format_t * ft) | |
if (ffmpeg->audio_stream >= 0) | |
stream_component_close(ffmpeg, ffmpeg->audio_stream); | |
if (ffmpeg->ctxt) { | |
- av_close_input_file(ffmpeg->ctxt); | |
+ avformat_close_input(&ffmpeg->ctxt); | |
ffmpeg->ctxt = NULL; /* safety */ | |
} | |
@@ -272,7 +267,7 @@ static AVStream *add_audio_stream(sox_format_t * ft, AVFormatContext *oc, enum C | |
AVCodecContext *c; | |
AVStream *st; | |
- st = av_new_stream(oc, 1); | |
+ st = avformat_new_stream(oc, 0); | |
if (!st) { | |
lsx_fail("ffmpeg could not alloc stream"); | |
return NULL; | |
@@ -306,7 +301,7 @@ static int open_audio(priv_t * ffmpeg, AVStream *st) | |
} | |
/* open it */ | |
- if (avcodec_open(c, codec) < 0) { | |
+ if (avcodec_open2(c, codec, 0) < 0) { | |
lsx_fail("ffmpeg could not open CODEC"); | |
return SOX_EOF; | |
} | |
@@ -373,13 +368,6 @@ static int startwrite(sox_format_t * ft) | |
return SOX_EOF; | |
} | |
- /* set the output parameters (must be done even if no | |
- parameters). */ | |
- if (av_set_parameters(ffmpeg->ctxt, NULL) < 0) { | |
- lsx_fail("ffmpeg invalid output format parameters"); | |
- return SOX_EOF; | |
- } | |
- | |
/* Next line for debugging */ | |
/* dump_format(ffmpeg->ctxt, 0, ft->filename, 1); */ | |
@@ -391,14 +379,14 @@ static int startwrite(sox_format_t * ft) | |
/* open the output file, if needed */ | |
if (!(ffmpeg->fmt->flags & AVFMT_NOFILE)) { | |
- if (url_fopen(&ffmpeg->ctxt->pb, ft->filename, URL_WRONLY) < 0) { | |
+ if (avio_open(&ffmpeg->ctxt->pb, ft->filename, AVIO_FLAG_WRITE) < 0) { | |
lsx_fail("ffmpeg could not open `%s'", ft->filename); | |
return SOX_EOF; | |
} | |
} | |
/* write the stream header, if any */ | |
- av_write_header(ffmpeg->ctxt); | |
+ avformat_write_header(ffmpeg->ctxt, 0); | |
return SOX_SUCCESS; | |
} | |
@@ -475,11 +463,7 @@ static int stopwrite(sox_format_t * ft) | |
if (!(ffmpeg->fmt->flags & AVFMT_NOFILE)) { | |
/* close the output file */ | |
-#if (LIBAVFORMAT_VERSION_INT < 0x340000) | |
- url_fclose(&ffmpeg->ctxt->pb); | |
-#else | |
- url_fclose(ffmpeg->ctxt->pb); | |
-#endif | |
+ avio_close(ffmpeg->ctxt->pb); | |
} | |
/* Free the output context */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment