【问题标题】:ffmpeg to rip mp3 from mp4 in rubyffmpeg 在 ruby​​ 中从 mp4 翻录 mp3
【发布时间】:2014-09-11 04:47:16
【问题描述】:

尝试制作基本的 Ruby 脚本,利用 ffmpeg 从 Youtube 下载视频,然后从该视频中翻录 mp3。 问题是每次脚本在尝试将两者分开时失败,即使命令本身在外部运行良好。 我认为问题在于 Ruby 将视频视为字符串,但我不确定。

def input
    #print "Enter Video URL: "
    #@target_video = gets
    #@target_video ||= ''
    #@target_video.chomp
    @target_video = 'https://www.youtube.com/watch?v=bYG1qccSUAw'
end

def grab
    #@video = `viddl-rb #{@target_video}`
    `viddl-rb #{@target_video}`
end

def rip
    `ffmpeg -i #{grab} new.mp3`
end

input
rip

我在 irb 中对其进行了测试,当我尝试 @video.class 时,它返回了 string,我认为这是出错的地方,但我不确定。 视频下载成功,但翻录失败。

输出和错误:

ruby youtube_downloader.rb 
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 30.4M  100 30.4M    0     0  2580k      0  0:00:12  0:00:12 --:--:-- 2683k
ffmpeg version 2.3.3 Copyright (c) 2000-2014 the FFmpeg developers
  built on Aug 25 2014 19:47:15 with Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/2.3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid
  libavutil      52. 92.100 / 52. 92.100
  libavcodec     55. 69.100 / 55. 69.100
  libavformat    55. 48.100 / 55. 48.100
  libavdevice    55. 13.102 / 55. 13.102
  libavfilter     4. 11.100 /  4. 11.100
  libavresample   1.  3.  0 /  1.  3.  0
  libswscale      2.  6.100 /  2.  6.100
  libswresample   0. 19.100 /  0. 19.100
  libpostproc    52.  3.100 / 52.  3.100
Loading: No such file or directory
sh: line 1: Plugins: command not found
sh: line 2: Will: command not found
sh: line 3: Analyzing: command not found
sh: line 4: Using: command not found
sh: line 5: [YOUTUBE]: command not found
sh: line 6: [YOUTUBE]: command not found
sh: line 7: Using: command not found
sh: line 8: Download: command not found
sh: line 9: Error:: command not found
sh: line 11: Backtrace:: command not found
sh: -c: line 12: syntax error near unexpected token `:27:in'
sh: -c: line 12: `(eval):27:in `initialize''

【问题讨论】:

    标签: ruby ffmpeg mp3 system mp4


    【解决方案1】:

    你确定这是正确的吗?

    def rip
        `ffmpeg -i #{grab} new.mp3`
    end
    

    您将方法名称#{grab}(而不是#{@video} 文件名)传递给您的 rip 方法。

    【讨论】:

    • 是的,抱歉,我忘记更改了。现在编辑它,没有将viddl系统命令分配给@video变量显示相同的错误
    • 嗯,好的@RichardC,但是ffmpeg -i 选项不需要文件名,看来你传递了其他东西?顺便说一句,viddl-rb 也像 gem 一样存在,尝试去这里 [link]github.com/rb2k/viddl-rb
    猜你喜欢
    • 1970-01-01
    • 2022-01-02
    • 2014-11-04
    • 2010-12-25
    • 1970-01-01
    • 2021-09-25
    • 1970-01-01
    • 2016-10-19
    • 2019-07-12
    相关资源
    最近更新 更多