问题描述
我想使用 python ffmpeg 或 moviepy 将 mp4 视频文件转换为 mp3/wav 音频。 当我运行此命令时
ffmpeg -i vid.mp4 -ar 44100 -vn audio.wav
它回来了
Output file #0 does not contain any stream
这是完整的日志
ffmpeg version N-55702-g920046a copyright (c) 2000-2013 the FFmpeg developers
built on Aug 21 2013 18:10:00 with gcc 4.7.3 (GCC)
configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
libavutil 52. 42.100 / 52. 42.100
libavcodec 55. 29.100 / 55. 29.100
libavformat 55. 14.101 / 55. 14.101
libavdevice 55. 3.100 / 55. 3.100
libavfilter 3. 82.100 / 3. 82.100
libswscale 2. 5.100 / 2. 5.100
libswresample 0. 17.103 / 0. 17.103
libpostproc 52. 3.100 / 52. 3.100
Input #0,mov,mp4,m4a,3gp,3g2,mj2,from 'vid.mp4':
Metadata:
major_brand : dash
minor_version : 0
compatible_brands: iso6avc1mp41
creation_time : 2021-03-12 14:13:58
Duration: 00:07:28.87,start: 0.000000,bitrate: 1199 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661),yuv420p,1920x1080 [SAR 1:1 DAR 16:9],1197 kb/s,23.98 tbr,24k tbn,47.95 tbc
Metadata:
creation_time : 2021-03-12 14:13:58
handler_name : ISO Media file produced by Google Inc.
Output #0,wav,to 'audio.wav':
Metadata:
major_brand : dash
minor_version : 0
compatible_brands: iso6avc1mp41
Output file #0 does not contain any stream
请告诉是否有办法用 ffmpeg 或其他方式来做到这一点
我也尝试过使用moviepy,但没有成功。
这是电影日志
Traceback (most recent call last):
File "path\to\file\script.py",line 3,in <module>
clip.audio.write_audiofile(r'audio.mp3')
AttributeError: 'nonetype' object has no attribute 'write_audiofile'
这是我的moviepy代码
import moviepy.editor as mp
clip = mp.VideoFileClip('vid.mp4')
clip.audio.write_audiofile(r'audio.mp3')
解决方法
这一定意味着程序无法找到 vid.mp4
文件。确保 vid.py
文件与 ffmpeg.exe
位于同一目录中(或确保您 cd 到与命令提示符中的 vid.mp4
文件相同的目录中) 和你的 python 文件。
我一直在尝试moviepy,希望能帮到你。你可以试试这个吗:
import moviepy.editor as mp
clip = mp.VideoFileClip('vid.mp4')
audio = clip.audio
audio.write_audiofile('audio.mp3')