]> git.pld-linux.org Git - packages/sox.git/blob - sox-ffmpeg.patch
77f742b610c1acac345f5760e4ab574921d49887
[packages/sox.git] / sox-ffmpeg.patch
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
4 @@ -49,7 +49,7 @@
5    LIBS="$LIBS $FFMPEG_LIBS"
6    have_ffmpeg="no"
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)])])
12      break])
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
16 @@ -57,6 +57,11 @@
17  #define PKT_FLAG_KEY AV_PKT_FLAG_KEY
18  #endif
19  
20 +#ifndef AVCODEC_MAX_AUDIO_FRAME_SIZE
21 +#define AVCODEC_MAX_AUDIO_FRAME_SIZE (192000 * 4)
22 +#endif
23 +
24 +
25  /* Private data for ffmpeg files */
26  typedef struct {
27    int audio_index;
28 @@ -92,11 +97,13 @@
29    enc->workaround_bugs = 1;
30  #if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
31    enc->error_resilience = 1;
32 -#else
33 +#elif LIBAVCODEC_VERSION_INT < ((54<<16)+(0<<8)+0)
34    enc->error_recognition = 1;
35 +#else
36 +  ic->error_recognition = 1;
37  #endif
38  
39 -  if (!codec || avcodec_open(enc, codec) < 0)
40 +  if (!codec || avcodec_open2(enc, codec, NULL) < 0)
41      return -1;
42    if (enc->codec_type != AVMEDIA_TYPE_AUDIO) {
43      lsx_fail("ffmpeg CODEC %x is not an audio CODEC", enc->codec_type);
44 @@ -157,7 +164,7 @@
45  static int startread(sox_format_t * ft)
46  {
47    priv_t * ffmpeg = (priv_t *)ft->priv;
48 -  AVFormatParameters params;
49 +  AVDictionary *params;
50    int ret;
51    int i;
52  
53 @@ -172,13 +179,13 @@
54  
55    /* Open file and get format */
56    memset(&params, 0, sizeof(params));
57 -  if ((ret = av_open_input_file(&ffmpeg->ctxt, ft->filename, NULL, 0, &params)) < 0) {
58 +  if ((ret = avformat_open_input(&ffmpeg->ctxt, ft->filename, NULL, &params)) < 0) {
59      lsx_fail("ffmpeg cannot open file for reading: %s (code %d)", ft->filename, ret);
60      return SOX_EOF;
61    }
62  
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);
67      return SOX_EOF;
68    }
69 @@ -231,7 +238,7 @@
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)))
75         break;
76        ffmpeg->audio_buf_size = audio_decode_frame(ffmpeg, ffmpeg->audio_buf_aligned, AVCODEC_MAX_AUDIO_FRAME_SIZE);
77        ffmpeg->audio_buf_index = 0;
78 @@ -256,8 +263,12 @@
79    if (ffmpeg->audio_stream >= 0)
80      stream_component_close(ffmpeg, ffmpeg->audio_stream);
81    if (ffmpeg->ctxt) {
82 +#if LIBAVFORMAT_VERSION_INT > AV_VERSION_INT(53,25,0)
83 +    avformat_close_input(&ffmpeg->ctxt);
84 +#else
85      av_close_input_file(ffmpeg->ctxt);
86      ffmpeg->ctxt = NULL; /* safety */
87 +#endif
88    }
89  
90    free(ffmpeg->audio_buf_raw);
91 @@ -267,12 +278,12 @@
92  /*
93   * add an audio output stream
94   */
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)
97  {
98    AVCodecContext *c;
99    AVStream *st;
100  
101 -  st = av_new_stream(oc, 1);
102 +  st = avformat_new_stream(oc, NULL);
103    if (!st) {
104      lsx_fail("ffmpeg could not alloc stream");
105      return NULL;
106 @@ -306,7 +317,7 @@
107    }
108  
109    /* open it */
110 -  if (avcodec_open(c, codec) < 0) {
111 +  if (avcodec_open2(c, codec, NULL) < 0) {
112      lsx_fail("ffmpeg could not open CODEC");
113      return SOX_EOF;
114    }
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;
128        break;
129      default:
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)
138        return SOX_EOF;
139    }
140  
141 -  /* set the output parameters (must be done even if no
142 -     parameters). */
143 -  if (av_set_parameters(ffmpeg->ctxt, NULL) < 0) {
144 -    lsx_fail("ffmpeg invalid output format parameters");
145 -    return SOX_EOF;
146 -  }
147 -
148    /* Next line for debugging */
149    /* dump_format(ffmpeg->ctxt, 0, ft->filename, 1); */
150  
151 @@ -391,14 +395,14 @@
152  
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);
158        return SOX_EOF;
159      }
160    }
161  
162    /* write the stream header, if any */
163 -  av_write_header(ffmpeg->ctxt);
164 +  avformat_write_header(ffmpeg->ctxt, NULL);
165  
166    return SOX_SUCCESS;
167  }
168 @@ -475,11 +479,7 @@
169  
170    if (!(ffmpeg->fmt->flags & AVFMT_NOFILE)) {
171      /* close the output file */
172 -#if (LIBAVFORMAT_VERSION_INT < 0x340000)
173 -    url_fclose(&ffmpeg->ctxt->pb);
174 -#else
175 -    url_fclose(ffmpeg->ctxt->pb);
176 -#endif
177 +    avio_close(ffmpeg->ctxt->pb);
178    }
179  
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
184 @@ -27,6 +27,8 @@
185  #include <ffmpeg/avformat.h>
186  #endif
187  
188 +#include <libavutil/mathematics.h>
189 +
190  #if defined __SUNPRO_C
191    #pragma enable_warn
192  #elif defined _MSC_VER
This page took 0.077549 seconds and 2 git commands to generate.