
The one which truly fits our need is the subprocess library. There are many modules available in the standard library python offers. Even a beginner in coding can follow, understand and run the codes being shared through this article.įire up a python shell using the following command on your terminal: python2.7 One does not need to be a python expert to follow this tutorial or utilize other Python codes. Python is a high level computer programming language perfect for scripting stuff one likes to automate. Start using python to interact with ffmpeg
#Python ffmpeg example how to
This is where ffprobe becomes really useful!įinding the correct extension for saving the audio file which is being copied is as easy as taking a look at the codec_name value inside the audio stream information that comes from probing the file with the following ffprobe command line utility: įor more information on how to use the ffmpeg command line utility read our article on practical commands that can be used in real situations. Copying the audio stream needs the right extension which in the above case is. However, there is one big problem with it. The above command is really useful when it comes to extracting the audio stream. The perfect command from my experience is the one which copies the audio stream without re-encoding it: ffmpeg -i video.mp4 -vn -acodec copy audio.aac Suppose one wants to extract just the audio stream from a music video. The first stream has an index of 0, but for the purpose of this article not all the streams probed by ffprobe are displayed here. The output produced by this command gives us a lot of information on the streams of the file. TAG:handler_name=IsoMedia File Produced by Google, 5-11-2011

Ĭodec_long_name=AAC (Advanced Audio Coding) The output displayed on console by this command is very lengthy, as shown below.

The above command probes the ‘test.mp4’ video for format tags and streams. It can be used to get information about an audio or video file such as the streams, format or both using the following code: ffprobe -show_format -show_streams test.mp4

Included in the installation of the FFmpeg box is the ffprobe utility.
#Python ffmpeg example download
Open the terminal and download the right python package using the wget utility, as shown here:
#Python ffmpeg example install
The python version being used through this article is Python 2.7.x so make sure to install it on your own linux machine before going any further as a different version may give you all kind of errors when running the code in the python interactive shell.Ĭompiling code from source is a little bit tricky, but since it is needed to cover this installation for almost any kind of linux distribution going through all the package managers is not possible. Setting up python and ffmpeg on your linux box Through this tutorial you are going to learn how to use the python programming language for interacting with this open source tool in order to automate some simple tasks. It is written mostly in C programming language and the best part is that FFmpeg is open source. There are many cool things you can do with this tool. What do I mean by this? Well, you can easily convert from one format to another, extract audio from a video, compress a video and even extract pictures from a video. FFmpeg is a great multimedia framework that helps you deal with your audio and video files.
