Repository: ytdl-org/youtube-dl

Issue:
Opus audio conversion failure
When trying to extract and convert audio from a youtube video into an opus-encoded audio file I get "ERROR: audio conversion failed:" with no further explanation. Both libopus0 and opus-tools are installed and I have no problems with other codecs like vorbis. I'm not sure if this is because of the ffmpeg/avconv issue in Ubuntu or a bug in youtube-dl.

Distribution: Ubuntu 13.04
Version: 2013.08.17

Debug output:

Traceback (most recent call last):
  File "/usr/local/bin/youtube-dl/youtube_dl/YoutubeDL.py", line 589, in post_process
    keep_video_wish,new_info = pp.run(info)
  File "/usr/local/bin/youtube-dl/youtube_dl/PostProcessor.py", line 205, in run
    raise PostProcessingError(msg)
PostProcessingError



Discussion:
I had the same issue and after an hour-long debug session with a friend of mine we found out that the problem was I was missing libmp3lame, which you can aquire by installing libavcodec-extra-53 :)

Hope that fixes it for you too :)

You had me excited with that response, unfortunately the solution isn't as easy for me, as libavcodec-extra-53 is already installed on my system :(

I'm debating trying another distro just to see if it is ubuntu-specific.

Thanks for the report. We should definitely include more debugging information. Can you post the entire output of youtube-dl when called with `-v`? That may give some helpful hints.

Sure, 

[debug] System config: []
[debug] User config: []
[debug] Command-line args: ['-v', '-x', '--audio-format=opus', 'https://www.youtube.com/watch?v=mOA_HBRntyo']
[debug] youtube-dl version 2013.08.17
[debug] Python version 2.7.4 - Linux-3.9.0-030900-generic-x86_64-with-Ubuntu-13.04-raring
[debug] Proxy map: {}
[youtube] Setting language
[youtube] mOA_HBRntyo: Downloading video webpage
[youtube] mOA_HBRntyo: Downloading video info webpage
[youtube] mOA_HBRntyo: Extracting video information
[download] Xan - To The Clouds-mOA_HBRntyo.mp4 has already been downloaded
[avconv] Destination: Xan - To The Clouds-mOA_HBRntyo.opus
ERROR: audio conversion failed: 
Traceback (most recent call last):
  File "/usr/local/bin/youtube-dl/youtube_dl/YoutubeDL.py", line 589, in post_process
    keep_video_wish,new_info = pp.run(info)
  File "/usr/local/bin/youtube-dl/youtube_dl/PostProcessor.py", line 205, in run
    raise PostProcessingError(msg)
PostProcessingError

Tried it here, doesn't work for me either, because of the opus file format. With mp3 works fine.

I've installed ffmpeg with opus support:

```
$ffmpeg -version
ffmpeg version 1.2.4
built on Oct 12 2013 12:40:16 with Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/1.2.4 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=cc --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid --enable-libopus
libavutil      52. 18.100 / 52. 18.100
libavcodec     54. 92.100 / 54. 92.100
libavformat    54. 63.104 / 54. 63.104
libavdevice    54.  3.103 / 54.  3.103
libavfilter     3. 42.103 /  3. 42.103
libswscale      2.  2.100 /  2.  2.100
libswresample   0. 17.102 /  0. 17.102
libpostproc    52.  2.100 / 52.  2.100
```

The error I get is `youtube_dl.utils.PostProcessingError: audio conversion failed: Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height`
If I run the same following ffmpeg command (the one youtube-dl executes):

```
ffmpeg -y -i 'Xan - To The Clouds-mOA_HBRntyo.mp4' -vn -acodec opus -aq 5 'Xan - To The Clouds-mOA_HBRntyo.opus'
ffmpeg version 1.2.4 Copyright (c) 2000-2013 the FFmpeg developers
  built on Oct 12 2013 12:40:16 with Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/1.2.4 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=cc --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid --enable-libopus
  libavutil      52. 18.100 / 52. 18.100
  libavcodec     54. 92.100 / 54. 92.100
  libavformat    54. 63.104 / 54. 63.104
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 42.103 /  3. 42.103
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Xan - To The Clouds-mOA_HBRntyo.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2013-08-17 06:09:54
  Duration: 00:06:01.98, start: 0.000000, bitrate: 1152 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 957 kb/s, 29.97 fps, 29.97 tbr, 60k tbn, 59.94 tbc
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 191 kb/s
    Metadata:
      creation_time   : 2013-08-17 06:09:57
      handler_name    : IsoMedia File Produced by Google, 5-11-2011
[libopus @ 0x7ffedb0e4800] No bit rate set. Defaulting to 96000 bps.
[libopus @ 0x7ffedb0e4800] Quality-based encoding not supported, please specify a bitrate and VBR setting.
Output #0, ogg, to 'Xan - To The Clouds-mOA_HBRntyo.opus':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    Stream #0:0(und): Audio: opus, 48000 Hz, stereo, flt, 96 kb/s
    Metadata:
      creation_time   : 2013-08-17 06:09:57
      handler_name    : IsoMedia File Produced by Google, 5-11-2011
Stream mapping:
  Stream #0:1 -> #0:0 (aac -> libopus)
Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
```

The problem is with the `-aq 5` option, if I drop it everything works fine, according to the [ffmpeg docs](http://www.ffmpeg.org/ffmpeg.html#Audio-Options), it has a codec specific meaning.


Resolving patch:
diff --git a/youtube_dl/PostProcessor.py b/youtube_dl/PostProcessor.py
--- a/youtube_dl/PostProcessor.py
+++ b/youtube_dl/PostProcessor.py
@@ -178,7 +178,8 @@ def run(self, information):
             extension = self._preferredcodec
             more_opts = []
             if self._preferredquality is not None:
-                if int(self._preferredquality) < 10:
+                # The opus codec doesn't support the -aq option
+                if int(self._preferredquality) < 10 and extension != 'opus':
                     more_opts += [self._exes['avconv'] and '-q:a' or '-aq', self._preferredquality]
                 else:
                     more_opts += [self._exes['avconv'] and '-b:a' or '-ab', self._preferredquality + 'k']


Test patch: