【问题标题】:Could not convert video to audio using ffmpeg or moviepy无法使用 ffmpeg 或 moviepy 将视频转换为音频
【发布时间】:2021-06-29 22:52:18
【问题描述】:

我想使用 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'

这是我的moviepy代码

import moviepy.editor as mp
clip = mp.VideoFileClip('vid.mp4')
clip.audio.write_audiofile(r'audio.mp3')

【问题讨论】:

  • 您的视频似乎缺少音频
  • 是的,我的音频文件有音频
  • 嗯 ffmpeg 不这么认为 :) 你能公开分享视频文件吗?

标签: python ffmpeg moviepy


【解决方案1】:

这一定意味着程序找不到vid.mp4文件。确保vid.py 文件与ffmpeg.exe 位于同一目录中(或确保您在命令提示符下 cd 到与vid.mp4 文件相同的目录) 和您的python 文件.

【讨论】:

    【解决方案2】:

    我一直在尝试moviepy,希望能帮到你。你能试试这个吗:

    import moviepy.editor as mp
    clip = mp.VideoFileClip('vid.mp4')
    audio = clip.audio
    audio.write_audiofile('audio.mp3')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-25
      • 2023-01-26
      • 1970-01-01
      • 2021-08-17
      • 2021-06-30
      • 2016-01-31
      • 2011-03-16
      • 2018-07-22
      相关资源
      最近更新 更多