audio - Python extract wav from video file -
audio - Python extract wav from video file -
related:
how extract sound video file using python?
extract sound video wav
how rip sound video?
my question how extract wav sound track video file, video.avi
? read many articles , everywhere people suggest utilize (from python) ffmpeg
subprocess (because there no reliable python bindings ffmpeg - hope pyffmpeg
found unmaintaned now). don't know if right solution , looking one. looked gstreamer , found nice unable satisfy needs -- way found accomplish command line looks like
gst-launch-0.10 playbin2 uri=file://`pwd`/ex.mp4 audio-sink='identity single-segment=true ! audioconvert ! audio/x-raw-int, endianness=(int)1234, signed=(boolean)true, width=(int)16, depth=(int)16, rate=(int)16000, channels=(int)1 ! wavenc ! filesink location=foo.wav’
but not efficient because need wait ages while playing video , simultaneously writing wav file.
ffmpeg
much better:
avconv -i foo.mp4 -ab 160k -ac 1 -ar 16000 -vn ffaudio.wav
but unable launch python (not command line subprocess). please point me out pros , cons of launching ffmpeg python command line utility ? (i mean using python multiprocessing
module or similar).
and sec question.
what simple way cutting long wav file pieces don't break words ? mean pieces of 10-20 sec length start , end during pause in sentences/words ?
i know how break them on arbitrary pieces:
import wave win= wave.open('ffaudio.wav', 'rb') wout= wave.open('ffsegment.wav', 'wb') t0, t1= 2418, 2421 # cutting sound between 2413, 2422 seconds s0, s1= int(t0*win.getframerate()), int(t1*win.getframerate()) win.readframes(s0) # discard frames= win.readframes(s1-s0) wout.setparams(win.getparams()) wout.writeframes(frames) win.close() wout.close()
it easy task using ffmpeg python subprocess , there reason why people pointing solution solution.
this basic command extracting sound given video file:
ffmpeg -i test.mp4 -ab 160k -ac 2 -ar 44100 -vn audio.wav
the python code wrapping command:
import subprocess command = "ffmpeg -i c:/test.mp4 -ab 160k -ac 2 -ar 44100 -vn audio.wav" subprocess.call(command, shell=true)
you have create sure ffmpeg known task, in scheme environment variables, under path, path ffmpeg.exe should listed, or can utilize total path exe in python code.
python audio video ffmpeg gstreamer
Comments
Post a Comment