1 diff -urN sox-14.4.1.org/m4/ffmpeg.m4 sox-14.4.1/m4/ffmpeg.m4
2 --- sox-14.4.1.org/m4/ffmpeg.m4 2011-03-02 23:10:27.000000000 +0100
3 +++ sox-14.4.1/m4/ffmpeg.m4 2014-10-13 07:11:31.825357581 +0200
5 LIBS="$LIBS $FFMPEG_LIBS"
7 AC_CHECK_HEADERS([libavformat/avformat.h ffmpeg/avformat.h],
8 - [AC_CHECK_LIB(avformat, av_open_input_file,
9 + [AC_CHECK_LIB(avformat, avformat_open_input,
10 [AC_CHECK_HEADERS([libavcodec/avcodec.h ffmpeg/avcodec.h],
11 [AC_CHECK_LIB(avcodec, avcodec_decode_audio3, have_ffmpeg=yes)])])
13 diff -urN sox-14.4.1.org/src/ffmpeg.c sox-14.4.1/src/ffmpeg.c
14 --- sox-14.4.1.org/src/ffmpeg.c 2012-01-23 23:27:33.000000000 +0100
15 +++ sox-14.4.1/src/ffmpeg.c 2014-10-13 07:12:27.294541928 +0200
17 #define PKT_FLAG_KEY AV_PKT_FLAG_KEY
20 +#ifndef AVCODEC_MAX_AUDIO_FRAME_SIZE
21 +#define AVCODEC_MAX_AUDIO_FRAME_SIZE (192000 * 4)
25 /* Private data for ffmpeg files */
29 enc->workaround_bugs = 1;
30 #if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
31 enc->error_resilience = 1;
33 +#elif LIBAVCODEC_VERSION_INT < ((54<<16)+(0<<8)+0)
34 enc->error_recognition = 1;
36 + ic->error_recognition = 1;
39 - if (!codec || avcodec_open(enc, codec) < 0)
40 + if (!codec || avcodec_open2(enc, codec, NULL) < 0)
42 if (enc->codec_type != AVMEDIA_TYPE_AUDIO) {
43 lsx_fail("ffmpeg CODEC %x is not an audio CODEC", enc->codec_type);
45 static int startread(sox_format_t * ft)
47 priv_t * ffmpeg = (priv_t *)ft->priv;
48 - AVFormatParameters params;
49 + AVDictionary *params;
55 /* Open file and get format */
56 memset(¶ms, 0, sizeof(params));
57 - if ((ret = av_open_input_file(&ffmpeg->ctxt, ft->filename, NULL, 0, ¶ms)) < 0) {
58 + if ((ret = avformat_open_input(&ffmpeg->ctxt, ft->filename, NULL, ¶ms)) < 0) {
59 lsx_fail("ffmpeg cannot open file for reading: %s (code %d)", ft->filename, ret);
63 /* Get CODEC parameters */
64 - if ((ret = av_find_stream_info(ffmpeg->ctxt)) < 0) {
65 + if ((ret = avformat_find_stream_info(ffmpeg->ctxt, NULL)) < 0) {
66 lsx_fail("ffmpeg could not find CODEC parameters for %s", ft->filename);
70 /* If input buffer empty, read more data */
71 if (ffmpeg->audio_buf_index * 2 >= ffmpeg->audio_buf_size) {
72 if ((ret = av_read_frame(ffmpeg->ctxt, pkt)) < 0 &&
73 - (ret == AVERROR_EOF || url_ferror(ffmpeg->ctxt->pb)))
74 + (ret == AVERROR_EOF || ( ffmpeg->ctxt->pb && ffmpeg->ctxt->pb->error)))
76 ffmpeg->audio_buf_size = audio_decode_frame(ffmpeg, ffmpeg->audio_buf_aligned, AVCODEC_MAX_AUDIO_FRAME_SIZE);
77 ffmpeg->audio_buf_index = 0;
79 if (ffmpeg->audio_stream >= 0)
80 stream_component_close(ffmpeg, ffmpeg->audio_stream);
82 +#if LIBAVFORMAT_VERSION_INT > AV_VERSION_INT(53,25,0)
83 + avformat_close_input(&ffmpeg->ctxt);
85 av_close_input_file(ffmpeg->ctxt);
86 ffmpeg->ctxt = NULL; /* safety */
90 free(ffmpeg->audio_buf_raw);
93 * add an audio output stream
95 -static AVStream *add_audio_stream(sox_format_t * ft, AVFormatContext *oc, enum CodecID codec_id)
96 +static AVStream *add_audio_stream(sox_format_t * ft, AVFormatContext *oc, enum AVCodecID codec_id)
101 - st = av_new_stream(oc, 1);
102 + st = avformat_new_stream(oc, NULL);
104 lsx_fail("ffmpeg could not alloc stream");
110 - if (avcodec_open(c, codec) < 0) {
111 + if (avcodec_open2(c, codec, NULL) < 0) {
112 lsx_fail("ffmpeg could not open CODEC");
115 @@ -319,10 +330,10 @@
116 if (c->frame_size <= 1) {
117 ffmpeg->audio_input_frame_size = AVCODEC_MAX_AUDIO_FRAME_SIZE / c->channels;
118 switch(st->codec->codec_id) {
119 - case CODEC_ID_PCM_S16LE:
120 - case CODEC_ID_PCM_S16BE:
121 - case CODEC_ID_PCM_U16LE:
122 - case CODEC_ID_PCM_U16BE:
123 + case AV_CODEC_ID_PCM_S16LE:
124 + case AV_CODEC_ID_PCM_S16BE:
125 + case AV_CODEC_ID_PCM_U16LE:
126 + case AV_CODEC_ID_PCM_U16BE:
127 ffmpeg->audio_input_frame_size >>= 1;
130 @@ -367,19 +378,12 @@
131 /* add the audio stream using the default format codecs
132 and initialize the codecs */
133 ffmpeg->audio_st = NULL;
134 - if (ffmpeg->fmt->audio_codec != CODEC_ID_NONE) {
135 + if (ffmpeg->fmt->audio_codec != AV_CODEC_ID_NONE) {
136 ffmpeg->audio_st = add_audio_stream(ft, ffmpeg->ctxt, ffmpeg->fmt->audio_codec);
137 if (ffmpeg->audio_st == NULL)
141 - /* set the output parameters (must be done even if no
143 - if (av_set_parameters(ffmpeg->ctxt, NULL) < 0) {
144 - lsx_fail("ffmpeg invalid output format parameters");
148 /* Next line for debugging */
149 /* dump_format(ffmpeg->ctxt, 0, ft->filename, 1); */
151 @@ -391,14 +395,14 @@
153 /* open the output file, if needed */
154 if (!(ffmpeg->fmt->flags & AVFMT_NOFILE)) {
155 - if (url_fopen(&ffmpeg->ctxt->pb, ft->filename, URL_WRONLY) < 0) {
156 + if (avio_open(&ffmpeg->ctxt->pb, ft->filename, AVIO_FLAG_WRITE) < 0) {
157 lsx_fail("ffmpeg could not open `%s'", ft->filename);
162 /* write the stream header, if any */
163 - av_write_header(ffmpeg->ctxt);
164 + avformat_write_header(ffmpeg->ctxt, NULL);
170 if (!(ffmpeg->fmt->flags & AVFMT_NOFILE)) {
171 /* close the output file */
172 -#if (LIBAVFORMAT_VERSION_INT < 0x340000)
173 - url_fclose(&ffmpeg->ctxt->pb);
175 - url_fclose(ffmpeg->ctxt->pb);
177 + avio_close(ffmpeg->ctxt->pb);
180 /* Free the output context */
181 diff -urN sox-14.4.1.org/src/ffmpeg.h sox-14.4.1/src/ffmpeg.h
182 --- sox-14.4.1.org/src/ffmpeg.h 2012-01-23 23:27:33.000000000 +0100
183 +++ sox-14.4.1/src/ffmpeg.h 2014-10-13 07:11:27.848510903 +0200
185 #include <ffmpeg/avformat.h>
188 +#include <libavutil/mathematics.h>
190 #if defined __SUNPRO_C
192 #elif defined _MSC_VER