[英]Could not convert video to audio using ffmpeg or moviepy
I want to convert a mp4 video file to mp3/wav audio using python ffmpeg or moviepy.我想使用 python ffmpeg 或 moviepy 将 mp4 视频文件转换为 mp3/wav 音频。 when I run this command
当我运行这个命令
ffmpeg -i vid.mp4 -ar 44100 -vn audio.wav
It returns它返回
Output file #0 does not contain any stream
Here is the full Log这是完整的日志
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
I searched the internet for this but could not find a solution我在互联网上搜索了这个但找不到解决方案
Please tell if there is a way to do this with ffmpeg or another way请告诉是否有办法用 ffmpeg 或其他方式做到这一点
I also tried to use moviepy but it was not successful.我也尝试使用moviepy,但没有成功。
Here is moviepy log这是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'
this is my code for moviepy这是我的电影代码
import moviepy.editor as mp
clip = mp.VideoFileClip('vid.mp4')
clip.audio.write_audiofile(r'audio.mp3')
It must mean that the vid.mp4
files cannot be found by the program.这一定意味着程序找不到
vid.mp4
文件。 Make sure that the vid.py
file is in the same directory as the ffmpeg.exe
(or make sure you cd into the same directory as the vid.mp4
file in your command prompt) and your python file.确保
vid.py
文件与ffmpeg.exe
位于同一目录中(或确保在命令提示符下 cd 到与vid.mp4
文件相同的目录)和 python 文件。
I have been trying out moviepy, and can hopefully help you.我一直在尝试moviepy,希望能对你有所帮助。 Are you able to try this:
你可以试试这个:
import moviepy.editor as mp
clip = mp.VideoFileClip('vid.mp4')
audio = clip.audio
audio.write_audiofile('audio.mp3')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.