Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract audio from a video file using python?

I want to write a python program that could extract audio from a video file (e.g. video.avi). Is there any good library for it? And where should I start from? I tried to use PyMedia, but I couldn't install it on my MacOSX(Mountain Lion).

EDIT: The problem is video.avi is not completely available. Someone is writing on it and adding some frames to it every second. So I wanted to write a code in python to get the video as it comes and extract the audio from it and write it to a file (e.g. audio.mp3, audio.wav). I don't know if ffmpeg can wait for the video to be copied to video.avi.

And I cannot wait for the video to be copied completely and then do the audio extraction. I have to do it as it comes.

like image 643
Mehran Avatar asked Oct 07 '13 03:10

Mehran


1 Answers

I don't have a complete solution, but from the ffmpeg docs, it looks like ffmpeg can read an incomplete file by piping to stdin. Example from the docs:

cat test.wav | ffmpeg -i pipe:0

If you must use python, you can always call ffmpeg using subprocess.

like image 103
u55 Avatar answered Sep 29 '22 17:09

u55