簡體   English   中英

無法使用 ffmpeg 或 moviepy 將視頻轉換為音頻

[英]Could not convert video to audio using ffmpeg or moviepy

我想使用 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,但沒有成功。

這是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'

這是我的電影代碼

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')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM