rss

FFMPEG get video file duration: Ruby

3

Category : Ruby on Rails

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
def get_video_file_duration(inputFilename)
            command = "ffmpeg -i "
                             + inputFilename.to_s + " 
                             2>&1 | grep 'Duration' 
                             | cut -d ' ' -f 4 | sed s/,//"
                             output = `#{command}`
 
          if output =~ /([\d][\d]):([\d][\d]):([\d][\d]).([\d]+)/
               duration = (($1.to_i * 60 + $2.to_i) * 60 + $3.to_i) * 10 + $4.to_i
          end
 
          #return duration.to_s
          return "#{$2}:#{$3}"
 end

 

Share

Amit Yadav is Stephen Fry proof thanks to caching by WP Super Cache