python提取视频中的音频 代码_如何使用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.

解决方案

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值