FFMpeg

This section is now closed.
Forum rules
Audacity 1.3.x is now obsolete. Please use the current Audacity 2.x.x package for your distribution or compile Audacity from the source code.
Locked
steve
Site Admin
Posts: 81653
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

FFMpeg

Post by steve » Sun Feb 06, 2011 6:56 pm

What patches, workarounds and jumping through blazing hoops are currently required to make Audacity svn trunk work with FFmpeg on Linux?
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Gale Andrews
Quality Assurance
Posts: 41761
Joined: Fri Jul 27, 2007 12:02 am
Operating System: Windows 10

Re: FFmpeg

Post by Gale Andrews » Mon Feb 07, 2011 2:13 am

steve wrote:What patches, workarounds and jumping through blazing hoops are currently required to make Audacity svn trunk work with FFmpeg on Linux?
Have you tried looking at previous posts? It's certainly confusing.

You need "ffmpeg-av-match-ext.patch" from http://forum.audacityteam.org/viewtopic ... 55#p107655 to make Audacity trunk work with the FFmpeg installed with Ubuntu 10.x. "Work" means YMMV - some people get segfaults importing or exporting most FFmpeg formats from time to time, but having tested I now believe WMA export crashes on completion of export with just about any recent Audacity Beta and any compatible version of FFmpeg (Bug 274.).

To use latest svn FFmpeg from the above state of play you could in addition change src/FFmpeg.cpp line 207 from

Code: Select all

static int ufile_write(URLContext *h, unsigned char *buf, int size)
to

Code: Select all

static int ufile_write(URLContext *h, const unsigned char *buf, int size)
but then latest FFmpeg as used in Audacity does not (for some people ) recognise legitimate FFmpeg-supported files on import, showing "av_open_input_file() failed" in Help > Show Log. See http://forum.audacityteam.org/viewtopic ... 18&t=39251.

For (a few) others, the files *are* recognised but Audacity usually segfaults on just about any FFmpeg task.

For others including myself who tried self-compiling latest FFmpeg, then compiling Audacity with default ./configure against the "runtime detect" patch from bug 176, Audacity does not recognise FFmpeg. You get the "undefined symbol:match_ext" error when loading FFmpeg from Preferences, the fix for which is actually included in that patch.

So next up, we have the patch which Benjamin did for Bug 233 which runtime-detects the version of FFmpeg, and (if USE_SYSTEM_FFMPEG is set) allows automatic linking against system FFmpeg then greys out the "Locate" and "Download" buttons in the FFmpeg section of the "Libraries" Preferences.

That Bug 233 patch was tested by you (Steve) and me with default Audacity ./configure on Ubuntu 10.10. which picks up the Ubuntu-distributed FFmpeg. We both got the Bug 274 WMA export crashes. There were also problems with AAC export (which files then crash on import) but I understand these issues only occur with the native FFmpeg AAC encoder. So FFmpeg should be configured with:

Code: Select all

--disable-encoder=aac 
to use the older AAC encoder and (hopefully) avoid those crashes. I've asked Benjamin whether the Ubuntu system FFmpeg uses the native AAC encoder.

All this still leaves the issue of whether self-compiling FFmpeg means that FFmpeg files aren't recognised. I would assume "yes", but I've asked Benjamin that too.




Gale
Last edited by Gale Andrews on Fri Apr 24, 2015 3:37 pm, edited 2 times in total.
Reason: The bug 233 patch greys out the "Locate" and "Download" buttons in FFmpeg Preferences, not remove those Prefs.
________________________________________FOR INSTANT HELP: (Click on Link below)
* * * * * Tips * * * * * Tutorials * * * * * Quick Start Guide * * * * * Audacity Manual

steve
Site Admin
Posts: 81653
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: FFMpeg

Post by steve » Mon Feb 07, 2011 6:15 pm

Gale Andrews wrote:Have you tried looking at previous posts? It's certainly confusing
Yes I have and yes it is :P

With an un-patched svn build I'm not getting Audacity to recognise FFmpeg at all (thought that might have changed by now). I'll give the "ffmpeg-av-match-ext.patch" a go, see what mileage I get with that, then take it from there.
Gale Andrews wrote:So next up, we have the patch which Benjamin did for Bug 233 which runtime-detects the version of FFmpeg, and (if USE_SYSTEM_FFMPEG is set) allows automatic linking against system FFmpeg then greys out the "Locate" and "Download" buttons in the FFmpeg section of the "Libraries" Preferences..
And that patch supersedes the other patches and code changes? That is, it should be applies to a "clean" svn source?
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Gale Andrews
Quality Assurance
Posts: 41761
Joined: Fri Jul 27, 2007 12:02 am
Operating System: Windows 10

Re: FFMpeg

Post by Gale Andrews » Mon Feb 07, 2011 7:23 pm

steve wrote:With an un-patched svn build I'm not getting Audacity to recognise FFmpeg at all (thought that might have changed by now).
An unpatched svn build of Audacity should recognise FFmpeg 0.5 from Spring 2009, or a later library or package from that year (as it says in the Manual). The FFmpeg version supplied with Ubuntu 10.x is too late to work with unpatched Audacity.
steve wrote:
Gale Andrews wrote:So next up, we have the patch which Benjamin did for Bug 233 which runtime-detects the version of FFmpeg, and (if USE_SYSTEM_FFMPEG is set) allows automatic linking against system FFmpeg then greys out the "Locate" and "Download" buttons in the FFmpeg section of the "Libraries" Preferences..
And that patch supersedes the other patches and code changes? That is, it should be applies to a "clean" svn source?
That patch should essentially be the patch from bug 176 (which "theoretically" works with SVN FFmpeg) with the addition of allowing automatic linking against system FFmpeg without using Preferences (if USE_SYSTEM_FFMPEG is set).

But it's untested what happens with that patch if user self-compiles SVN FFmpeg then sets USE_SYSTEM_FFMPEG to try and use that SVN FFmpeg (or doesn't, trying to load it through Preferences). Apart from that, there are possible licensing issues with using build-time linkage against an optional library without asking FFmpeg if they agree to it.



Gale
________________________________________FOR INSTANT HELP: (Click on Link below)
* * * * * Tips * * * * * Tutorials * * * * * Quick Start Guide * * * * * Audacity Manual

bdrung
Posts: 9
Joined: Wed Dec 01, 2010 12:01 am
Operating System: Please select

Re: FFMpeg

Post by bdrung » Tue Feb 08, 2011 11:24 pm

I have compiled SVN FFmpeg and then Audacity with USE_SYSTEM_FFMPEG. Here's how I've done it. First we need all build dependencies:

Code: Select all

sudo apt-get build-dep ffmpeg audacity
Then we can get FFmpeg:

Code: Select all

git clone git://git.ffmpeg.org/ffmpeg.git
cd ffmpeg
./configure --enable-gpl --enable-shared --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-vaapi --enable-libvpx --enable-runtime-cpudetect
make
sudo make install
sudo ldconfig
cd ..
I assume that only --enable-shared is an important configure flag.

Now we can check, if Audacity will find the correct FFmpeg library:

Code: Select all

pkg-config --libs libavcodec
For the system FFmpeg this command returns "-L/usr/lib -lavcodec", for the self-compiled FFmpeg it returns "-L/usr/local/lib -lavcodec"

Now we can checkout Audacity, apply my patch, and compile it:

Code: Select all

svn checkout http://audacity.googlecode.com/svn/audacity-src/trunk/ audacity
wget -O audacity-system-ffmpeg6.patch http://bugzilla.audacityteam.org/attachment.cgi?id=71
cd audacity
patch -p0 < ../audacity-system-ffmpeg6.patch
chmod +x ./autogen.sh
./autogen.sh
# cp /usr/share/automake*/{install-sh,config.sub,config.guess} .
./configure --disable-dynamic-loading
make
Once compiled, you can check against which FFmpeg library Audacity is linked:

Code: Select all

ldd audacity | grep av
It should point to the FFmpeg libraries in /usr/local/lib.

Now you can launch audacity and try your luck:

Code: Select all

export UBUNTU_MENUPROXY=0
./audacity
Export an ac3 file fails:

Code: Select all

Error: can't open file '/' (error 21: is a directory)
Error: FFmpeg: ERROR - Can't open output file "/home/foo/bar/baz.ac3" to write.
Error code is -2.
Import a mp4 file fails:

Code: Select all

Opening with libav
Error: can't read from file descriptor 20 (error 21: is a directory)
Error: av_open_input_file() failed for file /home/foo/bar/baz.mp4
Error: Importer::Import: Opening failed.

Gale Andrews
Quality Assurance
Posts: 41761
Joined: Fri Jul 27, 2007 12:02 am
Operating System: Windows 10

Re: FFMpeg

Post by Gale Andrews » Wed Feb 09, 2011 4:14 pm

Thanks, Benjamin. I'm glad (in a way) that you can replicate the problem. Sad that it seems to be with export as well as import. So are you satisfied this is to do with the version of FFmpeg and not to do with configuring/compiling Audacity? I already tested patching Audacity for the av-match-ext and const issues, then locating and using SVN FFMPEG from the Libraries Prefs. and the errors were the same (but I had not linked Audacity against any particular version of FFmpeg).

Several things still slightly confuse me with your steps, so it may possibly help others if I seek clarification here. I think --disable-dynamic-loading means the Locate/Download buttons for FFmpeg will be greyed out in Libraries Prefs. And I think USE_SYSTEM_FFMPEG and --disable-dynamic-loading are not mutually exclusive - you can set USE_SYSTEM_FFMPEG but not configure with --disable-dynamic-loading, which gives user the opportunity to use an alternative (compatible) version of FFmpeg instead?

And I think USE_SYSTEM_FFMPEG is lacking from your code snippets below because the patch sets the USE_SYSTEM_FFMPEG configure flag. But when the patch is applied, will the user have to set this flag using the terminal?

You say that pkg-config --libs libavcodec returns -L/usr/lib -lavcodec for what you describe as "system FFmpeg" (the Ubuntu supplied libraries) and for the self-compiled FFmpeg it returns -L/usr/local/lib -lavcodec". OK so far. But if we are setting USE_SYSTEM_FFMPEG why does Audacity link to -L/usr/local/lib (which looks like a local library) instead of the Ubuntu libs? I assume this is because we did:

Code: Select all

sudo apt-get build-dep ffmpeg audacity
and then compiled git ffmpeg, but the term "system FFmpeg " seems to mean different things in different places.


Thanks



Gale
________________________________________FOR INSTANT HELP: (Click on Link below)
* * * * * Tips * * * * * Tutorials * * * * * Quick Start Guide * * * * * Audacity Manual

bdrung
Posts: 9
Joined: Wed Dec 01, 2010 12:01 am
Operating System: Please select

Re: FFMpeg

Post by bdrung » Wed Feb 09, 2011 5:16 pm

Gale Andrews wrote:Thanks, Benjamin. I'm glad (in a way) that you can replicate the problem. Sad that it seems to be with export as well as import. So are you satisfied this is to do with the version of FFmpeg and not to do with configuring/compiling Audacity?
Yes, it's a problem between Audacity and the recent FFmpeg version. I assume that it's audacity's fault.
Gale Andrews wrote:I already tested patching Audacity for the av-match-ext and const issues, then locating and using SVN FFMPEG from the Libraries Prefs. and the errors were the same (but I had not linked Audacity against any particular version of FFmpeg).
Yes and that should be the same case if you apply my patch and use configure without --disable-dynamic-loading.
Gale Andrews wrote:I think --disable-dynamic-loading means the Locate/Download buttons for FFmpeg will be greyed out in Libraries Prefs.
... and disable dlopen.
Gale Andrews wrote:And I think USE_SYSTEM_FFMPEG and --disable-dynamic-loading are not mutually exclusive - you can set USE_SYSTEM_FFMPEG but not configure with --disable-dynamic-loading, which gives user the opportunity to use an alternative (compatible) version of FFmpeg instead?
They are the same. --disable-dynamic-loading sets USE_SYSTEM_FFMPEG. Should I rename USE_SYSTEM_FFMPEG to something better like DISABLE_DYNAMIC_LOADING_FFMPEG?
Gale Andrews wrote:And I think USE_SYSTEM_FFMPEG is lacking from your code snippets below because the patch sets the USE_SYSTEM_FFMPEG configure flag. But when the patch is applied, will the user have to set this flag using the terminal?
USE_SYSTEM_FFMPEG is neither a environment variable, nor a configure flag. It's a C/C++ macro. It's a compile time decision.
Gale Andrews wrote:You say that pkg-config --libs libavcodec returns -L/usr/lib -lavcodec for what you describe as "system FFmpeg" (the Ubuntu supplied libraries) and for the self-compiled FFmpeg it returns -L/usr/local/lib -lavcodec". OK so far. But if we are setting USE_SYSTEM_FFMPEG why does Audacity link to -L/usr/local/lib (which looks like a local library) instead of the Ubuntu libs?
[...]
and then compiled git ffmpeg, but the term "system FFmpeg " seems to mean different things in different places.
Yes, it's used with different meanings. Sometimes it means the Ubuntu FFmpeg package and sometimes it means the FFmpeg version that can be found on the system (in /usr/local or /usr).
Gale Andrews wrote: I assume this is because we did:

Code: Select all

sudo apt-get build-dep ffmpeg audacity
This command just installs the build dependencies for FFmpeg and Audacity.

Gale Andrews
Quality Assurance
Posts: 41761
Joined: Fri Jul 27, 2007 12:02 am
Operating System: Windows 10

Re: FFMpeg

Post by Gale Andrews » Thu Feb 10, 2011 3:01 am

bdrung wrote:
Gale Andrews wrote:And I think USE_SYSTEM_FFMPEG and --disable-dynamic-loading are not mutually exclusive - you can set USE_SYSTEM_FFMPEG but not configure with --disable-dynamic-loading, which gives user the opportunity to use an alternative (compatible) version of FFmpeg instead?
They are the same. --disable-dynamic-loading sets USE_SYSTEM_FFMPEG. Should I rename USE_SYSTEM_FFMPEG to something better like DISABLE_DYNAMIC_LOADING_FFMPEG?
I would say yes, particularly as "System FFmpeg" can sometimes mean the Ubuntu FFmpeg package and sometimes mean the the self-compiled FFmpeg at /usr/local or /usr.
bdrung wrote:USE_SYSTEM_FFMPEG is neither a environment variable, nor a configure flag. It's a C/C++ macro. It's a compile time decision.
I assumed it was a configure flag because Bug 233 says in your words "there should be a configure flag for setting USE_SYSTEM_FFMPEG", but I couldn't see it in your configure step. You've now explained above that --disable-dynamic-loading sets USE_SYSTEM_FFMPEG.

So do I have it correct now that setting USE_SYSTEM_FFMPEG makes Audacity link to FFmpeg in /usr/local/lib?

Given you now have two versions of FFmpeg, how would you configure Audacity if you now wanted to link to the Ubuntu FFmpeg library in /usr/lib? Is that now termed a "local" library? I'm asking because in that position you obviously would not want SVN FFmpeg for Audacity purposes.


Thanks


Gale
________________________________________FOR INSTANT HELP: (Click on Link below)
* * * * * Tips * * * * * Tutorials * * * * * Quick Start Guide * * * * * Audacity Manual

bdrung
Posts: 9
Joined: Wed Dec 01, 2010 12:01 am
Operating System: Please select

Re: FFMpeg

Post by bdrung » Thu Feb 24, 2011 7:13 pm

Gale Andrews wrote:
bdrung wrote:
Gale Andrews wrote:And I think USE_SYSTEM_FFMPEG and --disable-dynamic-loading are not mutually exclusive - you can set USE_SYSTEM_FFMPEG but not configure with --disable-dynamic-loading, which gives user the opportunity to use an alternative (compatible) version of FFmpeg instead?
They are the same. --disable-dynamic-loading sets USE_SYSTEM_FFMPEG. Should I rename USE_SYSTEM_FFMPEG to something better like DISABLE_DYNAMIC_LOADING_FFMPEG?
I would say yes, particularly as "System FFmpeg" can sometimes mean the Ubuntu FFmpeg package and sometimes mean the the self-compiled FFmpeg at /usr/local or /usr.
Ok, I have renamed it in version 7 of this patch.
Gale Andrews wrote:So do I have it correct now that setting USE_SYSTEM_FFMPEG makes Audacity link to FFmpeg in /usr/local/lib?
Yes, it will link against the FFmpeg version found by pkg-config. If you have only the Debian FFmpeg package installed, it will link against the Debian FFmpeg package. If you have the Debian FFmpeg package installed and a manual installed FFmpeg in /usr/local, pkg-config will probably find the library in /usr/local first and link against the /usr/local library.
Gale Andrews wrote:Given you now have two versions of FFmpeg, how would you configure Audacity if you now wanted to link to the Ubuntu FFmpeg library in /usr/lib?
Either you adjust the pkg-config search path to not look at /usr/include/ or you set AVCODEC_CFLAGS, AVCODEC_LIBS, AVFORMAT_CFLAGS, AVFORMAT_LIBS, AVUTIL_CFLAGS, and AVUTIL_LIBS via configure.
Gale Andrews wrote:Is that now termed a "local" library? I'm asking because in that position you obviously would not want SVN FFmpeg for Audacity purposes.
System library = every library that is available in the system (/usr/lib, /usr/local/lib, ...). local = the library in the lib-src subdirectory of audacity.

Locked