Export with Custom FFmpeg Export produces zero length files

This is a question and a complaint…

  1. Generate some audio
  2. Choose Export… from the File menu
    ___2a) make sure that you are Saving in: a directory in which you have write permission
  3. Under Save as type: select Custom FFmpeg Export
  4. Choose Options…, the Specify Other Options dialog opens
  5. In the left-hand column of Formats choose wav
  6. In the right-hand column of Codecs choose mp2
  7. (optional?) In the Bit rate: field enter 25600
  8. In the Sample Rate: field enter 48000
  9. Click OK
  10. In File name: enter a memorable name
  11. Click Save

Using Windows Explorer (opened on the directory in which you saved the above file) note that the file was saved but it is of zero length.

First, the question - is there some reason why the combination of wav + mp2 is failing? Note that if in step 6 above I choose libmp3lame the resulting file is a valid audio file.

Second, the complaint - assuming that this combination is in fact “erroneous” - it fails here:

   // Open the codec.
   if (avcodec_open(mEncAudioCodecCtx, codec) < 0 || mEncAudioCodecCtx->frame_size == 0) 
   {
      wxLogError(wxT("FFmpeg : ERROR - Can't open audio codec 0x%x."),mEncAudioCodecCtx->codec_id);
      return false;
   }

and writes an error to the log but never notifies the user of a problem. Even worse than not notifying the user of the problem it actually creates a zero length file even though it knows that it has errored out. All the error checking code is in place backwards through the chain of code calls but the fact that it has thrown an error is ignored.

There is a bug open for this, including the failure to notify or prevent a zero length file:
http://bugzilla.audacityteam.org/show_bug.cgi?id=59

so make a patch if you want.

However I can export a valid file using your steps (30 seconds mono or stereo tone) and FFmpeg 0.6.2. Is that the version you are using?

What happens if you use (external program) and:

ffmpeg -i - -acodec mp2 -ab 256000 "%f"

That custom export dialogue does produce an invalid file (a few kb) if I leave bit rate on zero (automatic). This is not a problem using FFmpeg standalone or with Audacity command-line export, so that is likely a problem with this dialogue.

Note that the hover tooltip for sample rate in that dialogue does say to not enter a sample rate - you are better to set the sample rate in project rate in my experience, even though in this case it does actually produce a 48000 Hz file for me with project rate on 44100 Hz.


Gale

I just tried again with a 30 sec Chirp and failed with a zero length file (I entered zero as the tooltip suggested).

10:36:37: Audacity 2.0.4-alpha-Jun 28 2013
10:36:38: Trying to load FFmpeg libraries...
10:36:38: mLibAVFormatPath ('D:MyAudacityFFmpeg for Audacityavformat-52.dll') is not empty. Loading from it.
10:36:38: Looking up PATH environment variable...
10:36:38: PATH = 'C:Program Files (x86)AMD APPbinx86_64;C:Program Files (x86)AMD APPbinx86;C:Program FilesCommon FilesMicrosoft SharedWindows Live;C:Program Files (x86)Common FilesMicrosoft SharedWindows Live;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;C:Program Files (x86)ATI TechnologiesATI.ACECore-Static;C:Python26;C:MyAudacity;C:Program Files (x86)Microsoft SQL Server100ToolsBinn;C:Program FilesMicrosoft SQL Server100ToolsBinn;C:Program FilesMicrosoft SQL Server100DTSBinn;C:Program Files (x86)Microsoft Visual Studio 8Common7IDE;C:Program Files (x86)Microsoft Visual Studio 9.0Team ToolsPerformance Toolsx64;C:Program Files (x86)Windows LiveShared;C:Program FilesMicrosoft Windows Performance Toolkit;C:MyAudacityFFmpeg for Audacity;C:MyAudacityLame for Audacity;D:ProgramsTortoiseSVNbin;D:ProgramsLuxRender;C:Program Files (x86)Calibre2;C:Program FilesMicrosoft SQL Server110ToolsBinn;D:ProgramsUnzip6.0;D:ProgramsZip3.0;C:Program Files (x86)QuickTimeQTSystem'
10:36:38: Checking that 'D:MyAudacityFFmpeg for Audacity' is in PATH...
10:36:38: Warning: FFmpeg directory is not in PATH.
10:36:38: Temporarily appending ';D:MyAudacityFFmpeg for Audacity' to PATH...
10:36:38: Checking for monolithic avformat from 'D:MyAudacityFFmpeg for Audacityavformat-52.dll'.
10:36:38: Error: Couldn't find symbol 'avutil_version' in a dynamic library (error 127: the specified procedure could not be found.)
10:36:38: avformat not monolithic
10:36:38: Loading avutil from 'D:MyAudacityFFmpeg for Audacityavutil-50.dll'.
10:36:38: Loading avcodec from 'D:MyAudacityFFmpeg for Audacityavcodec-52.dll'.
10:36:38: Loading avformat from 'D:MyAudacityFFmpeg for Audacityavformat-52.dll'.
10:36:38: Returning PATH to previous setting...
10:36:38: Actual avutil path D:MyAudacityFFmpeg for Audacityavutil-50.dll
10:36:38: Actual avcodec path D:MyAudacityFFmpeg for Audacityavcodec-52.dll
10:36:38: Actual avformat path D:MyAudacityFFmpeg for Audacityavformat-52.dll
10:36:38: Importing symbols...
10:36:38: All symbols loaded successfully. Initializing the library.
10:36:38: Retrieving FFmpeg library version numbers:
10:36:38:    AVCodec version 0x344802 - 52.72.2 (built against 0x344802 - 52.72.2)
10:36:38:    AVFormat version 0x344002 - 52.64.2 (built against 0x344002 - 52.64.2)
10:36:38:    AVUtil version 0x320f01 - 50.15.1 (built against 0x320f01 - 50.15.1)
10:36:38: FFmpeg libraries loaded successfully.
10:36:42: Attempting to load LAME from previously defined path
10:36:42: Loading LAME from D:AudacityLame for Audacitylame_enc.dll
10:36:42: Actual LAME path D:AudacityLame for Audacitylame_enc.dll
10:36:42: LAME library successfully loaded
10:38:54: Error: FFmpeg : ERROR - Can't open audio codec 0x15000.

ffm.png
Not sure if I have the correct FFMpeg version and have no clue how to use it from the commandline.

I don’t know why our results are different Ed , the only difference seems to be that I have FFmpeg installed in the standard location. Do I take it normal export to AAC in Audacity is OK?

If you have a file called “a.wav” in D:AudacityFFmpeg for Audacity then open a command prompt there and type:

ffmpeg -i a.wav -acodec mp2 -ab 256000 mp2.wav

what happens?


Gale

Seems to work fine (note however that the sample rate is 41,800 not 48,000):

D:AudacityFFmpeg for Audacity>ffmpeg -i a.wav -acodec mp2 -ab 256000 mp2.wav
FFmpeg version 0.6.2, Copyright (c) 2000-2010 the FFmpeg developers
  built on Apr  4 2011 10:07:47 with gcc 4.5.2
  configuration: --disable-ffplay --disable-ffprobe --disable-ffserver --disable-avdevice --disable-debug --disable-encoder=aac --disable-static --disable-doc -
-enable-gpl --enable-nonfree --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-w32threads --enable-avisynth --enable-libfaac --en
able-libspeex --enable-libgsm --enable-libmp3lame --enable-memalign-hack --enable-shared --extra-cflags='-I../local/include -fno-common' --extra-ldflags=-L../lo
cal/lib
  libavutil     50.15. 1 / 50.15. 1
  libavcodec    52.72. 2 / 52.72. 2
  libavformat   52.64. 2 / 52.64. 2
  libswscale     0.11. 0 /  0.11. 0
[wav @ 009fc800]max_analyze_duration reached
[wav @ 009fc800]Estimating duration from bitrate, this may be inaccurate
Input #0, wav, from 'a.wav':
  Duration: 00:01:55.80, bitrate: 1411 kb/s
    Stream #0.0: Audio: pcm_s16le, 44100 Hz, 2 channels, s16, 1411 kb/s
Output #0, wav, to 'mp2.wav':
  Metadata:
    encoder         : Lavf52.64.2
    Stream #0.0: Audio: mp2, 44100 Hz, 2 channels, s16, 256 kb/s
Stream mapping:
  Stream #0.0 -> #0.0
Press [q] to stop encoding
size=    3619kB time=115.80 bitrate= 256.0kbits/s
video:0kB audio:3619kB global headers:0kB muxing overhead 0.002159%

D:AudacityFFmpeg for Audacity>

Sorry I am not seeing where the “41,800” occurs. Your input “a.wav” and output “mp2.wav” both seem to be 44100 Hz.


Gale

The 41,800 was a typo - it was meant to be 44,100. I created a new 48,000 Hz wave and tried again with that and that also works just fine. I will have to look into the Audacity code little more closely maybe we are sending a badly formatted string to FFmpeg.