2014-09-11 2 views
0

ffmpeg를 사용하여 기본 Ruby 스크립트를 작성하여 Youtube에서 비디오를 다운로드 한 다음 해당 비디오에서 mp3를 추출하려고합니다. 문제는 두 명령을 분리하려고 시도 할 때마다 스크립트가 실패 할 때마다 발생합니다. Ruby가 비디오를 문자열로 취급한다는 것이 문제라고 생각하지만 확실하지 않습니다.루비에서 mp4로 mp3를 추출하는 ffmpeg

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

답변

0

당신이 정확한지 확인 있습니까?

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

# {@ video} 파일 이름 대신 메서드 이름 인 # {grab}를 rip 메서드에 전달합니다.

+0

죄송합니다. 변경하는 것을 잊어 버렸습니다. 지금 편집하여 viddl 시스템 명령어를'@ video' 변수에 할당하지 않고 같은 오류를 보여줍니다. –

+0

Ah ok @RichardC, 'ffmpeg -i' 옵션은 파일 이름을 기대하지 않습니다. ? BTW viddl-rb도 보석처럼 존재합니다. 여기에 가십시오. [link] https://github.com/rb2k/viddl-rb – MonkTools

관련 문제