Project

web_video

0.01
No commit activity in last 3 years
No release in over 3 years
WebVideo allows you to inspect, convert and take screenshots from video files
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

WebVideo¶ ↑

WebVideo allows you to inspect and process video files.

Install¶ ↑

gem 'web_video'

Dependencies¶ ↑

You need install ‘ffmpeg’ liblary and it’s dependent’s…

Linux¶ ↑

Install instructions for Ubuntu: ubuntuforums.org/showthread.php?t=786095

sudo apt-get install ffmpeg
sudo apt-get install libfaac-dev libxvidcore4-dev liba52-0.7.4 liba52-0.7.4-dev libx264-dev
sudo apt-get install libavutil49 libavutil-dev libavcodec-dev
sudo apt-get install libavcodec-unstripped-52

MacOS¶ ↑

sudo port install ffmpeg +lame +libogg +vorbis +faac +faad +xvid +x264 +a52

Logger¶ ↑

You can put it in “config/initializers/web_video.rb”.

logfile = File.open(Rails.root.join('log', 'video.log'), 'w')
logfile.sync = true

WebVideo.logger = Logger.new(logfile)

Usage¶ ↑

Read video information

video = WebVideo::Adapters::FfmpegAdapter.new('demo.avi')

video.filename # => "demo.avi"

video.duration # => "00:03:39.90"

video.bitrate  # => "2624 kb/s"

video.duration_in_seconds # => 219

video.streams  # => Array of streams
  # [ #<WebVideo::Stream @codec="mpeg4", @type="Video", @details="yuv420p, 640x480 [PAR 1:1 DAR 4:3], 30 tbr, 30 tbn, 30 tbc">,
  #   #<WebVideo::Stream @codec="mp3", @type="Audio", @details="44100 Hz, stereo, s16, 128 kb/s">]

Video Convertation

transcoder = WebVideo::Transcoder.new("demo.avi")

or

transcoder = WebVideo::Transcoder.new(video)

Transcoder attributes

transcoder.adapter # => :ffmpeg

transcoder.source  # => return WebVideo::Adapters::FfmpegAdapter instance (video)

Generate flv file. Next example will generate “demo.flv” from “demo.avi”.

options = {:resolution => "480x360"}

begin
  transcoder.convert("demo.flv", options) do |command|
    command << "-ar 22050"
    command << "-ab 128k"
    command << "-acodec libmp3lame"
    command << "-vcodec flv"
    command << "-r 25"
    command << "-y"
  end
rescue WebVideo::CommandLineError => e
  WebVideo.logger.error("Unable to transcode video: #{e.class} - #{e.message}")
end

Generate images from video By default screenshot starts at ‘00:00:01’, to change it pass option :at => ‘00:05:00’ (at five minutes) Or you can pass :at => :center, to get screenshot from video center

transcoder.screenshot("demo.jpg", :resolution => "480x360", :at => :center)

Next code will generate five images: demo_01.jpg, demo_02.jpg, demo_03.jpg …

image_files = 'demo_%2d.jpg'
options = {:resolution => "480x360", :count => 5 }

begin
  transcoder.screenshot(image_files, options) do |command|
    command << "-vcodec mjpeg"
    # The duration for which image extraction will take place
    #command << "-t 4"
    command << "-y"
  end
rescue WebVideo::CommandLineError => e
  WebVideo.logger.error("Unable to transcode video: #{e.class} - #{e.message}")
end

TODO¶ ↑

  1. Add adapter for support ‘mencoder’ tool

  2. More information about video file (class Stream must parse details)

  3. Add support for ‘flvtool2’

  4. Write more documentation

  5. Write tests

Copyright © 2012 Fodojo, released under the MIT license