Pydub can't find ffmpeg although it's installed and in path - macos

I'm attempting to open some MP3 files to find their lengths (as part of a larger project). I've installed pydub and ffmpeg has been installed via brew. ffmpeg is available in my path, and typing ffmpeg in a terminal launches it successfully - the audio file I'm referencing is present and I can run ffmpeg -i on it to get information about it. The program can open and play the audio file (using pygame), so I'm sure it's not a file issue.
However, attempting to open any files with AudioSegment leads to 'Couldn't find ffmpeg or avconv - defaulting to ffmpeg but may not work' being displayed, and any attempt to open a file using AudioSegment leads to an exception.
I've tried setting the path to ffmpeg explicitly using AudioSegment.converter - both trying to point to '/usr/local/bin/ffmpeg' and also to the true location (the previous one is a symlink).
from pydub import AudioSegment
AudioSegment.converter = '/usr/local/bin/ffmpeg' # tried with and without
print(len(AudioSegment.from_mp3('mp3_audio.mp3')))
I get FileNotFoundError: [Errno 2] No such file or directory: 'ffprobe': 'ffprobe'

This was hard work to figure out. But here it is.
On Mac, run brew install ffmpeg
Then you need to find where it has written the binary to. It will be buried in /usr/local/Cellar directory and will be based on the version number of the install. In my case it was
/usr/local/Cellar/ffmpeg/4.2.1_2/bin/ffmpeg
You then need to add this path into your Python script as follows
from pydub import AudioSegment
AudioSegment.converter = '/usr/local/Cellar/ffmpeg/4.2.1_2/bin/ffmpeg'

Related

Where is the location of homebrew installed youtube-dl configuration? [macOS]

I am new to youtube-dl and programming in general so this has been a lot for me to get even this far. So homebrew is installed on my Macbook and homebrew was used to install youtube-dl and ffmpeg. I read somewhere about a configuration file located at ~/.config/youtube-dl/config on
https://github.com/ytdl-org/youtube-dl/blob/master/README.md#options
So on the user directory I opened .config (found out it was hidden) and no youtube-dl folder found let alone the config file mentioned in the link.
Why is that?
How do I make a configuration file to use?
Like written on the Guthub page:
Note that by default configuration file may not exist so you may need to create it yourself.
You can simply create the directory ~/.config/youtube-dl yourself and then use your favorite text editor, place your options in a new file and save it at ~/.config/youtube-dl/config

Use ffmpeg on OSX Xcode Project for Mac

I am planning to create a new app for personal use on my Mac that uses FFMPEG library, to store a feed from a RTSP IP camera.
Following this official installation procedure from FFMPEG I have manage to successfully achieve the following 2 steps:
To get ffmpeg for OS X, you first have to install ​Homebrew. If you don't want to use Homebrew, see the section below.
ruby -e "$(curl -fsSL
https://raw.githubusercontent.com/Homebrew/install/master/install)"
Then:
- brew install automake fdk-aac git lame libass libtool libvorbis
libvpx \ opus sdl shtool texi2html theora wget x264 xvid yasm
Question:
My question here because I am confused, is how to import a library into Xcode so I can use it in the application I am about to build for my Mac. I can see plenty of GitHub projects related to FFMPEG with IOS/Android, but none for OSX.
All the FFMPEG commands under terminal are working fine, such as converting a video etc.
If you look in /usr/local/Cellar/ffmpeg you will find the actual ffmpeg package and everything in homebrew is just symbolic links to that. For example:
/usr/local/bin/ffmpeg -> ../Cellar/ffmpeg/3.0.2/bin/ffmpeg
Now, if you stay in that directory and do this, you will find all the pkgconfig configuration settings for the constituent parts of ffmpeg:
find . -name \*.pc
./lib/pkgconfig/libavcodec.pc
./lib/pkgconfig/libavdevice.pc
./lib/pkgconfig/libavfilter.pc
./lib/pkgconfig/libavformat.pc
./lib/pkgconfig/libavresample.pc
./lib/pkgconfig/libavutil.pc
./lib/pkgconfig/libpostproc.pc
./lib/pkgconfig/libswresample.pc
./lib/pkgconfig/libswscale.pc
That means you can now find the include path and library paths that you need to put in the Xcode settings. So, for example, if you want the includes for libavutil, you can do:
pkg-config --cflags libavutil
and it will tell you:
-I/usr/local/Cellar/ffmpeg/3.0.2/include
If you want the library settings for libavfilter, you can do:
pkg-config --libs libavfilter
and it will tell you
-L/usr/local/Cellar/ffmpeg/3.0.2/lib -lavfilter
So that is how you get the settings for the compiler/linker. Then you need to put them into Xcode, and I have described that here - look at the bit with the yellow, red and blue boxes.
Hope that helps. Oh, you need to do:
brew install pkg-config
first to get the pkgconfig binary.
In general, you need to configure the Xcode target build settings to add /usr/local/include to the Header Search Path.
Then your #include <ffmpeg.h> (or whatever it's called) will start to work.
Then for linking to libffmpeg.a (or whatever it's called), you can do one of two things:
Add the file to the Additional Libraries and Frameworks of the build settings (selecting it via a file open dialog).
Add /usr/local/lib to the Library Search Paths and -lffmpeg to the Other Linker Flags.
(1. is better if you ask me).
I use Macports, so for me the paths are /opt/local/{include,lib} however with Homebrew there might be an additional level of directory (like /usr/local/ffmpeg/{include,lib}, but you should be able to work that out yourself.
I won't go into details of how to actually use FFMPEG as that is way too involved (and I know nothing about it).
Although this does not answer the specific question here ("how to import such and such libraries"),
for anyone googling here, these days to use FFmpeg in OSX you just
Use the famous import script of Kewlbear
which you can easily find here
https://github.com/kewlbear/FFmpeg-iOS-build-script
and which does everything.
It is a huge amount of non-trivial work maintaining such a build script, and fortunately there's someone who does that work on an ongoing basis.

compile/make ffmpeg without man pags

I am installing ffmpeg on heroku (ubuntu) with enable-ssl via a build-pack. I am able to build it all the way up to these errors:
install: cannot create regular file `/usr/local/share/man/man1/ffmpeg.1': Read-only file system
...
install: cannot create regular file `/usr/local/share/man/man1/ffmpeg-filters.1': Read-only file system
make: *** [install-man] Error 1
I do not have write access to any directory outside of /app. I have tried compiling with --mandir=/app/vendor/ but that seems to be ignored.
Is there any way to build ffmpeg without the man pages or just have them installed else where?
Actually if your build has gotten to the install step, you should already have the binary for ffmpeg. Build process makes it in the local directory before attempting to move the binary and manuals to the system locations.

Full installation instruction of youtube-dl in windows

I have just downloaded the youtube-dl-2014.07.15.tar_2.gz in my windows. At first I want to tell I don't know anything about python. And I already have installed python 2.7. Can anyone give me instruction to execute these scripts?
I have already tried to run...but there is some error like these. "No mudule named youtube-dl"
I want a fresh start. Now I am using windows 8.1 and I have also tried youtube-dl.exe. And there is also problem like screenshot
If I want to get worked both script and program what will I do?Any helps will be appreciated. If you give me instruction from scratch that will be better.
To install youtube_dl in Python on Windows (command from their github):
Tested with Python 3.9 on Windows 10
pip install --upgrade youtube-dl
Now when using it, notice that the name of the Python module is with an underscore.
Because it is a Python module, use it like so:
py -m youtube_dl <video url>
Of course video url is the video you want to download
This seems to be caused by a limitation of py2exe. You may want to file a youtube-dl bug report for moving to a cxfreeze, which should not have that problem. In any case, simply moving the youtube-dl.exe file into another directory such as C:\Users\Shamim should fix the problem.
you need just to put the youtube-dl.exe file in in your home directory or any other location on your PATH.
You can see your PATH in your "Envirenment Variables"

how to link ffmpeg to php.ini

hi i am using mac osx with mamp and i was wondering how i can link ffmpeg to php.ini so that i can use it with php exec() ?
the directory that ffmpeg got installed in is /users/sarmenhb/ffmpeg although i wish it didnt get installed here and got installed somewhere more appropriate, i sadly have no clue how to change the system to know where the new location is.
i read a few articles telling me to put something like extensions = /users/sarmenhb/ffmpeg/ffmpeg.so but looking in the directory i dont see a so file. i do see ffmpeg as a console app is that an so file itself?
thanks
ps: i did a test of ffmpeg in console from a flv file to a mp4 file and the audio didnt work on the new file. do i have to install something?
You can use the full path when executing ffmpeg:
exec("/users/sarmenhb/ffmpeg");

Resources