voyeur 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -9,6 +9,8 @@ pkg/*
9
9
  bin
10
10
  test_data/*
11
11
  *.mp4
12
+ *.webm
13
+ *.3gp
12
14
  *.swp
13
15
  *.swo
14
16
  *.box
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # Voyeur
2
- Voyeur is a ruby library that will take your video files and convert
2
+ Voyeur is a ruby library that will take your video and audio files and convert
3
3
  them to common HTML5 formats exposing an easy to use API. Seriously
4
4
  it's like falling out of a tree then climbing back.
5
5
 
@@ -23,35 +23,49 @@ You can also try out automated [setup scripts](https://github.com/devthenet/ffmp
23
23
  ## Usage
24
24
  Simple conversions may be done by simply:
25
25
 
26
- Voyeur::Video.new( filename: path_to_file ).convert( to: :mp4 )
26
+ Voyeur::Media.new( filename: path_to_file ).convert( to: :mp4 )
27
27
 
28
28
  This will convert the video into Mp4 and save it in the same directory
29
29
  as the original video.
30
30
 
31
+ This will also work for audio using the same API by simply:
32
+
33
+ Voyeur::Media.new( filename: path_to_file ).convert( to: :acc )
34
+
35
+ This will convert the sound file into acc and save it in the same directory as the original video
36
+
37
+ You can call convert with a block, this will return a MediaTime object.
38
+
39
+ Voyeur::Media.new( filename: path_to_file ).convert( to: :mp4 ) do |time|
40
+ puts time.to_seconds
41
+ end
42
+ This will output how far along the video the conversion process is, it can be used to display percentage completed.
43
+ See bin/voyuer.rb for an example.
44
+
31
45
  Alternatively you can convert to all 3 types at once:
32
46
 
33
- Voyeur::Video.new( filename: path_to_file ).convert_to_html5
47
+ Voyeur::Media.new( filename: path_to_file ).convert_to_html5
34
48
  This will convert the video into 3 formats. Mp4, Ogv and Webm and place
35
49
  them in the same folder as the parent.
36
50
 
37
51
  I have allowed the user to specify an output filename. (Note: if no
38
52
  output filename the file is just named after the original file):
39
53
 
40
- Voyeur::Video.new( filename: path_to_file ).convert( to: :mp4, output_filename: "my_cool_video" )
54
+ Voyeur::Media.new( filename: path_to_file ).convert( to: :mp4, output_filename: "my_cool_video" )
41
55
 
42
56
  This will give you a converted video called "my_cool_video.mp4".
43
57
 
44
58
  You can also convert to all with the following:
45
59
 
46
- Voyeur::Video.new( filename: path_to_file ).convert_to_html5( output_filename: "my_cool_video" )
60
+ Voyeur::Media.new( filename: path_to_file ).convert_to_html5( output_filename: "my_cool_video" )
47
61
 
48
62
  It is also possible to place the formatted video in a custom folder:
49
63
 
50
- Voyeur::Video.new( filename: path_to_file ).convert( to: :mp4, output_path: "my/cool/file/path" )
64
+ Voyeur::Media.new( filename: path_to_file ).convert( to: :mp4, output_path: "my/cool/file/path" )
51
65
 
52
66
  or
53
67
 
54
- Voyeur::Video.new( filename: path_to_file ).convert_to_html5( output_path: "my/cool/file/path" )
68
+ Voyeur::Media.new( filename: path_to_file ).convert_to_html5( output_path: "my/cool/file/path" )
55
69
 
56
70
  ## Extendibility
57
71
 
@@ -0,0 +1,13 @@
1
+ module Voyeur
2
+ class Aac < Converter
3
+
4
+ def file_extension
5
+ "aac"
6
+ end
7
+
8
+ def convert_options
9
+ "-acodec libfaac -ac 2 -ar 44100 -ab 128k"
10
+ end
11
+ end
12
+
13
+ end
@@ -0,0 +1,13 @@
1
+ module Voyeur
2
+ class Ogg < Converter
3
+
4
+ def file_extension
5
+ "ogg"
6
+ end
7
+
8
+ def convert_options
9
+ "-strict -2 -acodec vorbis -aq 60"
10
+ end
11
+ end
12
+
13
+ end
@@ -1,23 +1,30 @@
1
1
  module Voyeur
2
2
  class Converter
3
- attr_accessor :input_video
4
- attr_reader :output_video
3
+ attr_accessor :input_media
4
+ attr_reader :output_media
5
5
  attr_reader :status
6
6
 
7
7
  def self.create(options)
8
8
  constant = Voyeur
9
- klass = "#{options[:format].capitalize}"
10
- raise Voyeur::Exceptions::InvalidFormat unless constant.const_defined? klass
11
- klass = constant.const_get klass
9
+ klass = if options[:format].is_a?(Symbol)
10
+ klass_name = "#{options[:format].capitalize}"
11
+ raise Voyeur::Exceptions::InvalidFormat unless constant.const_defined? klass_name
12
+ constant.const_get(klass_name)
13
+ else
14
+ options[:format]
15
+ end
12
16
  klass.new
13
17
  end
14
18
 
15
19
  def convert(options)
16
- @input_video = options[:video]
17
- raise Voyeur::Exceptions::NoVideoPresent unless @input_video
18
- output_filename = self.output_path( options[:output_path] )
19
- @output_video = Video.new(filename: output_file(options[:output_path], options[:output_filename]))
20
- self.call_external_converter
20
+ @input_media = options[:media]
21
+ raise Voyeur::Exceptions::NoMediaPresent unless @input_media
22
+ @output_media = Media.new(filename: output_file(options[:output_path], options[:output_filename]))
23
+ if block_given?
24
+ self.call_external_converter{ |time| yield time }
25
+ else
26
+ self.call_external_converter
27
+ end
21
28
  end
22
29
 
23
30
  protected
@@ -28,27 +35,33 @@ module Voyeur
28
35
 
29
36
  def output_path(output_path = nil)
30
37
  raise Voyeur::Exceptions::InvalidLocation if output_path && !File.directory?(output_path)
31
- output_path ? output_path : File.dirname(@input_video.filename)
38
+ output_path ? output_path : File.dirname(@input_media.filename)
32
39
  end
33
40
 
34
41
  def output_filename(input_filename = nil)
35
- filename = input_filename.nil? ? @input_video.filename : input_filename
42
+ filename = input_filename.nil? ? @input_media.filename : input_filename
36
43
  File.basename(filename, '.*') + ".#{self.file_extension}"
37
44
  end
38
45
 
39
46
  def call_external_converter
40
- command = "ffmpeg -i #{@input_video.filename} #{self.convert_options} #{@output_video.filename}"
47
+ command = "ffmpeg -y -i #{@input_media.filename} #{self.convert_options} #{@output_media.filename}"
41
48
  out, err = ""
42
49
 
43
50
  status = Open4::popen4(command) do |pid, stdin, stdout, stderr|
44
- out = stdout.read.strip
45
- err = stderr.read.strip
51
+ err = ''
52
+ out = ''
53
+ stderr.each("r") do |line|
54
+ err += line
55
+ if line =~ /time=(\d+:\d+:\d+.\d+)/
56
+ yield $1 if block_given?
57
+ end
58
+ end
46
59
  end
47
60
 
48
61
  error_message = err.split('\n').last
49
62
 
50
63
  @status = { status: status.exitstatus, stdout: out, stderr: err,
51
- error_message: error_message, video: @output_video }
64
+ error_message: error_message, media: @output_media }
52
65
  return @status
53
66
  end
54
67
  end
@@ -1,6 +1,6 @@
1
1
  module Voyeur
2
2
  module Exceptions
3
- class NoVideoPresent < StandardError; end
3
+ class NoMediaPresent < StandardError; end
4
4
  class InvalidFormat < StandardError; end
5
5
  class InvalidLocation < StandardError; end
6
6
  end
@@ -0,0 +1,41 @@
1
+ module Voyeur
2
+ class Media
3
+ attr_reader :filename
4
+ attr_reader :raw_duration
5
+
6
+ def initialize(options)
7
+ @filename = options[:filename]
8
+ self.get_info
9
+ end
10
+
11
+ def get_info
12
+ output = ''
13
+ status = Open4::popen4("ffmpeg -i #{@filename}") do |pid, stdin, stdout, stderr|
14
+ output = stderr.read.strip
15
+ end
16
+ @raw_duration = $1 if output =~ /Duration: (\d+:\d+:\d+.\d+)/
17
+ end
18
+
19
+ def convert(options)
20
+ converter = Voyeur::Converter.create(format: options[:to])
21
+
22
+ if block_given?
23
+ converter.convert(media: self,
24
+ output_filename: options[:output_filename],
25
+ output_path: options[:output_path]){ |time| yield time }
26
+ else
27
+ converter.convert(media: self,
28
+ output_filename: options[:output_filename],
29
+ output_path: options[:output_path])
30
+ end
31
+ end
32
+
33
+ def convert_to_html5(options = nil)
34
+ [:mp4, :ogv, :webm].each do |f|
35
+ options_hash = {to: f}
36
+ options_hash.merge!(options) if options
37
+ convert(options_hash)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,17 @@
1
+ module Voyeur
2
+ class MediaTime
3
+ attr_accessor :raw_time
4
+ attr_accessor :hours, :minutes, :seconds
5
+
6
+ def initialize(raw_time)
7
+ @hours, @minutes, @seconds = raw_time.split(":")
8
+ @hours = @hours.to_i
9
+ @minutes = @minutes.to_i
10
+ @seconds = @seconds.to_i
11
+ end
12
+
13
+ def to_seconds
14
+ @seconds + (@minutes * 60) + (@hours * 60 * 60)
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module Voyeur
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -0,0 +1,14 @@
1
+ #H.264 for iphone
2
+ module Voyeur
3
+ class Iphone < Converter
4
+
5
+ def file_extension
6
+ "mp4"
7
+ end
8
+
9
+ def convert_options
10
+ "-s 320x240 -r 30000/1001 -b 200k -bt 240k -vcodec libx264 -vpre ipod320 -acodec libfaac -ac 2 -ar 48000 -ab 192k"
11
+ end
12
+ end
13
+
14
+ end
data/lib/voyeur.rb CHANGED
@@ -1,8 +1,12 @@
1
1
  require "Voyeur/version"
2
- require "Voyeur/video"
2
+ require "Voyeur/media"
3
3
  require "Voyeur/exceptions"
4
4
  require "Voyeur/converter"
5
5
  require "Voyeur/video_converters/ogv"
6
6
  require "Voyeur/video_converters/mp4"
7
7
  require "Voyeur/video_converters/webm"
8
- require 'open4'
8
+ require "Voyeur/video_converters/iphone"
9
+ require "Voyeur/audio_converters/aac"
10
+ require "Voyeur/audio_converters/ogg"
11
+ require "Voyeur/media_time"
12
+ require 'open4'
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe Voyeur::Aac do
4
+ let(:converter) { Voyeur::Converter.create(format: :aac) }
5
+ let(:audio) { Voyeur::Media.new(filename: valid_mpeg_file_path) }
6
+
7
+ it "should use the correct factory" do
8
+ converter.class.to_s.should == "Voyeur::Aac"
9
+ end
10
+
11
+ it "default convert string" do
12
+ converter.convert_options.should == "-acodec libfaac -ac 2 -ar 44100 -ab 128k"
13
+ end
14
+
15
+ context "A valid audio files" do
16
+ after :each do
17
+ File.delete(valid_mpeg_file_path.gsub(/mpeg/, "aac")) if File.exists?(valid_mpeg_file_path.gsub(/mpeg/, "aac"))
18
+ end
19
+
20
+ context "#convert_options: " do
21
+ it "names the file correctly" do
22
+ converter.convert(media: audio)
23
+ output_file = valid_mpeg_file_path.gsub(/mpeg/, "aac")
24
+ converter.output_media.filename.should == output_file
25
+ end
26
+
27
+ it "returns an audio file" do
28
+ converter.convert(media: audio)
29
+ converter.input_media.should == audio
30
+ end
31
+
32
+ context "audio file - " do
33
+ it "returns conversion status indicating success" do
34
+ result = converter.convert(media: audio)
35
+ result[:status].should == 0
36
+ result[:media].should == converter.output_media
37
+ end
38
+
39
+ it "allows it to be named" do
40
+ result = converter.convert(media: audio)
41
+ result[:status].should == 0
42
+ result[:media].should == converter.output_media
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ context "An invalid audio file" do
49
+ let(:audio) { Voyeur::Media.new(filename: 'test_media.mpeg') }
50
+
51
+ it "returns conversion status indicating failure" do
52
+ result = converter.convert(media: audio)
53
+ result[:status].should == 1
54
+ result[:media].should == converter.output_media
55
+ result[:error_message].should match(/test_media.mpeg: No such file or directory/)
56
+ result[:stderr].nil?.should == false
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe Voyeur::Ogg do
4
+ let(:converter) { Voyeur::Converter.create(format: :ogg) }
5
+ let(:audio) { Voyeur::Media.new(filename: valid_mpeg_file_path) }
6
+
7
+ it "uses the correct factory" do
8
+ converter.class.to_s.should == "Voyeur::Ogg"
9
+ end
10
+
11
+ it "default convert string" do
12
+ converter.convert_options.should == "-strict -2 -acodec vorbis -aq 60"
13
+ end
14
+
15
+ context "A valid audio files" do
16
+ after :each do
17
+ File.delete(valid_mpeg_file_path.gsub(/mpeg/, "ogg")) if File.exists?(valid_mpeg_file_path.gsub(/mpeg/, "ogg"))
18
+ end
19
+
20
+ context "#convert_options: " do
21
+ it "names the media correctly" do
22
+ converter.convert(media: audio)
23
+ output_file = valid_mpeg_file_path.gsub(/mpeg/, "ogg")
24
+ converter.output_media.filename.should == output_file
25
+ end
26
+
27
+ it "returns an audio file" do
28
+ converter.convert(media: audio)
29
+ converter.input_media.should == audio
30
+ end
31
+
32
+ context "audio file - " do
33
+ it "returns conversion status indicating success" do
34
+ result = converter.convert(media: audio)
35
+ result[:status].should == 0
36
+ result[:media].should == converter.output_media
37
+ end
38
+
39
+ it "allows it to be named" do
40
+ result = converter.convert(media: audio)
41
+ result[:status].should == 0
42
+ result[:media].should == converter.output_media
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ context "An invalid audio file" do
49
+ let(:audio) { Voyeur::Media.new(filename: 'test_media.mpeg') }
50
+
51
+ it "returns conversion status indicating failure" do
52
+ result = converter.convert(media: audio)
53
+ result[:status].should == 1
54
+ result[:media].should == converter.output_media
55
+ result[:error_message].should match(/test_media.mpeg: No such file or directory/)
56
+ result[:stderr].nil?.should == false
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ describe Voyeur::Iphone do
4
+ let(:converter) { Voyeur::Converter.create(format: :iphone) }
5
+ let(:media) { Voyeur::Media.new(filename: valid_mpeg_file_path) }
6
+
7
+ it "uses the correct factory" do
8
+ converter.class.to_s.should == "Voyeur::Iphone"
9
+ end
10
+
11
+ it "default convert string" do
12
+ converter.convert_options.should == "-s 320x240 -r 30000/1001 -b 200k -bt 240k -vcodec libx264 -vpre ipod320 -acodec libfaac -ac 2 -ar 48000 -ab 192k"
13
+ end
14
+
15
+ context "A valid Media" do
16
+ after :each do
17
+ File.delete(valid_mpeg_file_path.gsub(/mpeg/, "mp4")) if File.exists?(valid_mpeg_file_path.gsub(/mpeg/, "mp4"))
18
+ end
19
+
20
+ context "#convert_options" do
21
+ it "names the media correctly" do
22
+ converter.convert(media: media)
23
+ output_file = valid_mpeg_file_path.gsub(/mpeg/, "mp4")
24
+ converter.output_media.filename.should == output_file
25
+ end
26
+
27
+ it "returns a media" do
28
+ converter.convert(media: media)
29
+ converter.input_media.should == media
30
+ end
31
+
32
+ context "real media" do
33
+ it "returns conversion status indicating success" do
34
+ result = converter.convert(media: media)
35
+ result[:status].should == 0
36
+ result[:media].should == converter.output_media
37
+ end
38
+
39
+ it "allows them to name the media" do
40
+ result = converter.convert(media: media)
41
+ result[:status].should == 0
42
+ result[:media].should == converter.output_media
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ context "An invalid Media" do
49
+ let(:converter) { Voyeur::Converter.create(format: :iphone) }
50
+ let(:media) { Voyeur::Media.new(filename: 'test_media.mpeg') }
51
+
52
+ context "File does not exist" do
53
+ it "returns conversion status indicating failure" do
54
+ result = converter.convert(media: media)
55
+ result[:status].should == 1
56
+ result[:media].should == converter.output_media
57
+ result[:error_message].should match(/test_media.mpeg: No such file or directory/)
58
+ result[:stderr].nil?.should == false
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ describe Voyeur::Mp4 do
4
+ let(:converter) { Voyeur::Converter.create(format: :mp4) }
5
+ let(:media) { Voyeur::Media.new(filename: valid_mpeg_file_path) }
6
+
7
+ it "uses the correct factory" do
8
+ converter.class.to_s.should == "Voyeur::Mp4"
9
+ end
10
+
11
+ it "default convert string" do
12
+ converter.convert_options.should == "-b 1500k -vcodec libx264 -g 30"
13
+ end
14
+
15
+ context "A valid Media" do
16
+ after :each do
17
+ File.delete(valid_mpeg_file_path.gsub(/mpeg/, "mp4")) if File.exists?(valid_mpeg_file_path.gsub(/mpeg/, "mp4"))
18
+ end
19
+
20
+ context "#convert_options" do
21
+ it "names the media correctly" do
22
+ converter.convert(media: media)
23
+ output_file = valid_mpeg_file_path.gsub(/mpeg/, "mp4")
24
+ converter.output_media.filename.should == output_file
25
+ end
26
+
27
+ it "returns a media" do
28
+ converter.convert(media: media)
29
+ converter.input_media.should == media
30
+ end
31
+
32
+ context "real media" do
33
+ it "returns conversion status indicating success" do
34
+ result = converter.convert(media: media)
35
+ result[:status].should == 0
36
+ result[:media].should == converter.output_media
37
+ end
38
+
39
+ it "allows them to name the media" do
40
+ result = converter.convert(media: media)
41
+ result[:status].should == 0
42
+ result[:media].should == converter.output_media
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ context "An invalid Media" do
49
+ let(:converter) { Voyeur::Converter.create(format: :mp4) }
50
+ let(:media) { Voyeur::Media.new(filename: 'test_media.mpeg') }
51
+
52
+ context "File does not exist" do
53
+ it "returns conversion status indicating failure" do
54
+ result = converter.convert(media: media)
55
+ result[:status].should == 1
56
+ result[:media].should == converter.output_media
57
+ result[:error_message].should match(/test_media.mpeg: No such file or directory/)
58
+ result[:stderr].nil?.should == false
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe Voyeur::Ogv do
4
+ context "New Video" do
5
+ let(:converter) { Voyeur::Converter.create(format: :ogv) }
6
+ let(:media) { Voyeur::Media.new(filename: 'test_media.ogv') }
7
+
8
+ it "uses the correct factory" do
9
+ converter.class.to_s.should == "Voyeur::Ogv"
10
+ end
11
+
12
+ context "#convert_options" do
13
+ it "default convert string" do
14
+ converter.convert_options.should == "-b 1500k -vcodec libtheora -acodec libvorbis -ab 160000 -g 30"
15
+ end
16
+
17
+ it "raises an exception if no media is passed" do
18
+ media = nil
19
+ -> { converter.convert(media: media) }.should raise_error Voyeur::Exceptions::NoMediaPresent
20
+ end
21
+
22
+ it "should return a media" do
23
+ converter.convert(media: media)
24
+ converter.input_media.should == media
25
+ end
26
+ end
27
+ end
28
+
29
+ context "An invalid Video" do
30
+ let(:converter) { Voyeur::Converter.create(format: :ogv) }
31
+ let(:media) { Voyeur::Media.new(filename: 'test_media.mpeg') }
32
+
33
+ context "File does not exist" do
34
+ it "returns conversion status indicating failure" do
35
+ result = converter.convert(media: media)
36
+ result[:status].should == 1
37
+ result[:media].should == converter.output_media
38
+ result[:error_message].should match(/test_media.mpeg: No such file or directory/)
39
+ result[:stderr].nil?.should == false
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe Voyeur::Webm do
4
+ context "New Media" do
5
+ let(:converter) { Voyeur::Converter.create(format: :webm) }
6
+ let(:media) { Voyeur::Media.new(filename: 'test_media.webm') }
7
+
8
+ it "uses the correct factory" do
9
+ converter.class.to_s.should == "Voyeur::Webm"
10
+ end
11
+
12
+ context "#convert_options" do
13
+ it "default convert string" do
14
+ converter.convert_options.should == "-b 1500k -vcodec libvpx -acodec libvorbis -ab 160000 -f webm -g 30"
15
+ end
16
+
17
+ it "raises an exception if no media is passed" do
18
+ media = nil
19
+ -> { converter.convert(media: media) }.should raise_error Voyeur::Exceptions::NoMediaPresent
20
+ end
21
+
22
+ it "returns a media" do
23
+ converter.convert(media: media)
24
+ converter.input_media.should == media
25
+ end
26
+ end
27
+ end
28
+
29
+ context "An invalid Media" do
30
+ let(:converter) { Voyeur::Converter.create(format: :webm) }
31
+ let(:media) { Voyeur::Media.new(filename: 'test_media.mpeg') }
32
+
33
+ context "File does not exist" do
34
+ it "returns conversion status indicating failure" do
35
+ result = converter.convert(media: media)
36
+ result[:status].should == 1
37
+ result[:media].should == converter.output_media
38
+ result[:error_message].should match(/test_media.mpeg: No such file or directory/)
39
+ result[:stderr].nil?.should == false
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe Voyeur::MediaTime do
4
+ context "When passing a valid 0 time string in" do
5
+ let(:raw_time) { "00:00:00.00" }
6
+ let(:media_time) { Voyeur::MediaTime.new(raw_time) }
7
+
8
+ it "hours minutes and seconds should be 0" do
9
+ media_time.hours.should == 0
10
+ media_time.minutes.should == 0
11
+ media_time.seconds.should == 0
12
+ end
13
+
14
+ it "returns 0 seconds" do
15
+ media_time.to_seconds.should == 0
16
+ end
17
+ end
18
+
19
+ context "When passing a a valid 1 minutes long time string in" do
20
+ let(:raw_time) { "00:01:00.00" }
21
+ let(:media_time) { Voyeur::MediaTime.new(raw_time) }
22
+
23
+ it "haves minutes as one" do
24
+ media_time.hours.should == 0
25
+ media_time.minutes.should == 1
26
+ media_time.seconds.should == 0
27
+ end
28
+
29
+ it "returns 60 seconds" do
30
+ media_time.to_seconds.should == 60
31
+ end
32
+ end
33
+
34
+ context "When passing a valid string with 1 hour 10 minute and 20 seconds" do
35
+ let(:raw_time) { "01:10:20.00" }
36
+ let(:media_time) { Voyeur::MediaTime.new(raw_time) }
37
+
38
+ it "haves hour as one, minutes as 10 and seconds as 20" do
39
+ media_time.hours.should == 1
40
+ media_time.minutes.should == 10
41
+ media_time.seconds.should == 20
42
+ end
43
+
44
+ it "returns 4220 seconds" do
45
+ media_time.to_seconds.should == 4220
46
+ end
47
+ end
48
+ end
data/spec/video_spec.rb CHANGED
@@ -1,78 +1,119 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Voyeur::Video do
4
- it 'should create a new video object from a filename' do
3
+ describe Voyeur::Media do
4
+ it 'creates a new video object from a filename' do
5
5
  video_input_name = 'test_file.mpeg'
6
- video = Voyeur::Video.new filename: video_input_name
6
+ video = Voyeur::Media.new filename: video_input_name
7
7
  video.filename.should == video_input_name
8
8
  end
9
9
 
10
- it "should convert a video to ogv" do
11
- Voyeur::Video.new( filename: valid_mpeg_file_path ).convert(to: :ogv)
12
- File.exist?(valid_mpeg_file_path.gsub(/mpeg/, "ogv")).should be_true
13
- File.delete(valid_mpeg_file_path.gsub(/mpeg/, "ogv"))
10
+ it 'gets duration of a media object from a filename' do
11
+ video = Voyeur::Media.new( filename: valid_mpeg_file_path )
12
+ video.raw_duration.should_not be_nil
13
+ video.raw_duration.should_not == ''
14
14
  end
15
15
 
16
- it "should convert a video to mp4" do
17
- Voyeur::Video.new( filename: valid_mpeg_file_path ).convert(to: :mp4)
18
- File.exist?(valid_mpeg_file_path.gsub(/mpeg/, "mp4")).should be_true
19
- File.delete(valid_mpeg_file_path.gsub(/mpeg/, "mp4"))
16
+ it "converts a video to ogv" do
17
+ Voyeur::Media.new( filename: valid_mpeg_file_path ).convert(to: :ogv)
18
+ ogv_file = valid_mpeg_file_path.gsub(/mpeg/, "ogv")
19
+ File.should exist(ogv_file)
20
+ File.delete(ogv_file)
20
21
  end
21
22
 
22
- it "should convert a video to webm" do
23
- Voyeur::Video.new( filename: valid_mpeg_file_path ).convert(to: :webm)
24
- File.exist?(valid_mpeg_file_path.gsub(/mpeg/, "webm")).should be_true
25
- File.delete(valid_mpeg_file_path.gsub(/mpeg/, "webm"))
23
+ it "converts a video to mp4" do
24
+ Voyeur::Media.new( filename: valid_mpeg_file_path ).convert(to: :mp4)
25
+ mp4_file = valid_mpeg_file_path.gsub(/mpeg/, "mp4")
26
+ File.should exist(mp4_file)
27
+ File.delete(mp4_file)
26
28
  end
27
29
 
28
- it "should convert a video to all HTML5 video formats" do
29
- Voyeur::Video.new( filename: valid_mpeg_file_path ).convert_to_html5
30
- File.exists?(valid_mpeg_file_path.gsub(/mpeg/, "mp4")).should be_true
31
- File.delete(valid_mpeg_file_path.gsub(/mpeg/, "mp4"))
32
- File.exists?(valid_mpeg_file_path.gsub(/mpeg/, "ogv")).should be_true
33
- File.delete(valid_mpeg_file_path.gsub(/mpeg/, "ogv"))
34
- File.exists?(valid_mpeg_file_path.gsub(/mpeg/, "webm")).should be_true
35
- File.delete(valid_mpeg_file_path.gsub(/mpeg/, "webm"))
30
+ it "converts a video to webm" do
31
+ Voyeur::Media.new( filename: valid_mpeg_file_path ).convert(to: :webm)
32
+ webm_file = valid_mpeg_file_path.gsub(/mpeg/, "webm")
33
+ File.should exist(webm_file)
34
+ File.delete(webm_file)
36
35
  end
37
36
 
38
- it "should allow the user to name the video" do
39
- Voyeur::Video.new( filename: valid_mpeg_file_path ).
37
+ it "converts a video to all HTML5 video formats" do
38
+ Voyeur::Media.new( filename: valid_mpeg_file_path ).convert_to_html5
39
+
40
+ mp4_file = valid_mpeg_file_path.gsub(/mpeg/, "mp4")
41
+ File.should exist(mp4_file)
42
+ File.delete(mp4_file)
43
+
44
+ ogv_file = valid_mpeg_file_path.gsub(/mpeg/, "ogv")
45
+ File.should exist(ogv_file)
46
+ File.delete(ogv_file)
47
+
48
+ webm_path = valid_mpeg_file_path.gsub(/mpeg/, "webm")
49
+ File.should exist(webm_path)
50
+ File.delete(webm_path)
51
+ end
52
+
53
+ it "allows the user to name the video" do
54
+ Voyeur::Media.new( filename: valid_mpeg_file_path ).
40
55
  convert(to: :webm, output_filename: "sexypants")
41
- File.exists?("#{fixture_file_path}/sexypants.webm").should be_true
42
- File.delete("#{fixture_file_path}/sexypants.webm")
56
+ webm_file = "#{fixture_file_path}/sexypants.webm"
57
+ File.should exist(webm_file)
58
+ File.delete(webm_file)
43
59
  end
44
60
 
45
- it "should allow the user to specify a video path" do
61
+ it "allows the user to specify a video path" do
46
62
  output_path = "#{fixture_file_path}/converted"
47
- Voyeur::Video.new( filename: valid_mpeg_file_path ).
63
+ Voyeur::Media.new( filename: valid_mpeg_file_path ).
48
64
  convert(to: :ogv, output_path: output_path)
49
- File.exists?("#{output_path}/test.ogv").should be_true
50
- File.delete("#{output_path}/test.ogv")
65
+ test_file = "#{output_path}/test.ogv"
66
+ File.should exist(test_file)
67
+ File.delete(test_file)
51
68
  end
52
69
 
53
- it "should allow a user to specify a video path and filename" do
70
+ it "allows a user to specify a video path and filename" do
54
71
  output_path = "#{fixture_file_path}/converted"
55
- Voyeur::Video.new( filename: valid_mpeg_file_path ).
72
+ Voyeur::Media.new( filename: valid_mpeg_file_path ).
56
73
  convert(to: :ogv, output_path: output_path, output_filename: "supersexypants")
57
- File.exists?("#{output_path}/supersexypants.ogv").should be_true
58
- File.delete("#{output_path}/supersexypants.ogv")
74
+ supersexypants_file = "#{output_path}/supersexypants.ogv"
75
+ File.should exist(supersexypants_file)
76
+ File.delete(supersexypants_file)
59
77
  end
60
78
 
61
- it "should allow a user to specify a video path and filename when converting all formats" do
79
+ it "allows user to convert given to a format given a class name" do
80
+ Voyeur::Media.new( filename: valid_mpeg_file_path ).convert(to: Voyeur::Webm)
81
+ webm_file = valid_mpeg_file_path.gsub(/mpeg/, "webm")
82
+ File.should exist(webm_file)
83
+ File.delete(webm_file)
84
+ end
85
+
86
+ it "allows a user to specify a video path and filename when converting all formats" do
62
87
  output_path = "#{fixture_file_path}/converted"
63
- Voyeur::Video.new( filename: valid_mpeg_file_path ).
88
+ Voyeur::Media.new( filename: valid_mpeg_file_path ).
64
89
  convert_to_html5(output_path: output_path, output_filename: "supersexypants")
65
- File.exists?("#{output_path}/supersexypants.ogv").should be_true
66
- File.delete("#{output_path}/supersexypants.ogv")
67
- File.exists?("#{output_path}/supersexypants.mp4").should be_true
68
- File.delete("#{output_path}/supersexypants.mp4")
69
- File.exists?("#{output_path}/supersexypants.webm").should be_true
70
- File.delete("#{output_path}/supersexypants.webm")
90
+ ogv_file = "#{output_path}/supersexypants.ogv"
91
+ File.should exist(ogv_file)
92
+ File.delete(ogv_file)
93
+
94
+ mp4_file = "#{output_path}/supersexypants.mp4"
95
+ File.should exist(mp4_file)
96
+ File.delete(mp4_file)
97
+
98
+ webm_file = "#{output_path}/supersexypants.webm"
99
+ File.should exist(webm_file)
100
+ File.delete(webm_file)
71
101
  end
72
102
 
73
- it "should not allow the user to specify a folder that doesn't exist" do
103
+ it "nots allow the user to specify a folder that doesn't exist" do
74
104
  output_path = "#{fixture_file_path}/icecream"
75
- -> { Voyeur::Video.new( filename: valid_mpeg_file_path ).
105
+ -> { Voyeur::Media.new( filename: valid_mpeg_file_path ).
76
106
  convert(to: :ogv, output_path: output_path) }.should raise_error Voyeur::Exceptions::InvalidLocation
77
107
  end
108
+
109
+ context "when convert is called with a block" do
110
+ it "updates the progress with time" do
111
+ output = ''
112
+ Voyeur::Media.new( filename: valid_mpeg_file_path ).convert(to: :ogv) do |time|
113
+ output += time
114
+ end
115
+ output.should_not == ''
116
+ output.length.should > 0
117
+ end
118
+ end
78
119
  end
metadata CHANGED
@@ -1,119 +1,124 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: voyeur
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 2
9
- version: 0.1.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Peter Garbers
13
9
  - Hendrik F. Louw
14
10
  autorequire:
15
11
  bindir: bin
16
12
  cert_chain: []
17
-
18
- date: 2012-01-31 00:00:00 +02:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
13
+ date: 2012-08-16 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
22
16
  name: rspec
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
- version: "0"
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
31
23
  type: :development
32
- version_requirements: *id001
33
- - !ruby/object:Gem::Dependency
34
- name: open4
35
24
  prerelease: false
36
- requirement: &id002 !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- segments:
41
- - 0
42
- version: "0"
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: open4
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
43
39
  type: :runtime
44
- version_requirements: *id002
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
45
47
  description: A ruby library to convert videos into common html5 formats
46
- email:
48
+ email:
47
49
  - peter.garbers@gmail.com
48
50
  - hflouw@gmail.com
49
- executables: []
50
-
51
+ executables:
52
+ - voyeur.rb
51
53
  extensions: []
52
-
53
54
  extra_rdoc_files: []
54
-
55
- files:
55
+ files:
56
56
  - .gitignore
57
57
  - Gemfile
58
58
  - README.md
59
59
  - Rakefile
60
60
  - Voyeur.gemspec
61
+ - bin/voyeur.rb
62
+ - lib/Voyeur/audio_converters/aac.rb
63
+ - lib/Voyeur/audio_converters/ogg.rb
61
64
  - lib/Voyeur/converter.rb
62
65
  - lib/Voyeur/exceptions.rb
66
+ - lib/Voyeur/media.rb
67
+ - lib/Voyeur/media_time.rb
63
68
  - lib/Voyeur/version.rb
64
- - lib/Voyeur/video.rb
69
+ - lib/Voyeur/video_converters/iphone.rb
65
70
  - lib/Voyeur/video_converters/mp4.rb
66
71
  - lib/Voyeur/video_converters/ogv.rb
67
72
  - lib/Voyeur/video_converters/webm.rb
68
73
  - lib/voyeur.rb
69
74
  - spec/converter_spec.rb
70
- - spec/converters/mp4_spec.rb
71
- - spec/converters/ogv_spec.rb
72
- - spec/converters/webm_spec.rb
75
+ - spec/converters/audio_converters/aac_spec.rb
76
+ - spec/converters/audio_converters/ogg_spec.rb
77
+ - spec/converters/video_converters/iphone_spec.rb
78
+ - spec/converters/video_converters/mp4_spec.rb
79
+ - spec/converters/video_converters/ogv_spec.rb
80
+ - spec/converters/video_converters/webm_spec.rb
73
81
  - spec/fixtures/converted/PLACEHOLDER
74
- - spec/fixtures/test.3gp
75
82
  - spec/fixtures/test.mpeg
83
+ - spec/media_time_spec.rb
76
84
  - spec/spec_helper.rb
77
85
  - spec/spec_helpers/video_file_spec_helper.rb
78
86
  - spec/video_spec.rb
79
- has_rdoc: true
80
87
  homepage: http://devthenet.github.com/voyeur
81
88
  licenses: []
82
-
83
89
  post_install_message:
84
90
  rdoc_options: []
85
-
86
- require_paths:
91
+ require_paths:
87
92
  - lib
88
- required_ruby_version: !ruby/object:Gem::Requirement
89
- requirements:
90
- - - ">="
91
- - !ruby/object:Gem::Version
92
- segments:
93
- - 0
94
- version: "0"
95
- required_rubygems_version: !ruby/object:Gem::Requirement
96
- requirements:
97
- - - ">="
98
- - !ruby/object:Gem::Version
99
- segments:
100
- - 0
101
- version: "0"
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
102
105
  requirements: []
103
-
104
106
  rubyforge_project: Voyeur
105
- rubygems_version: 1.3.6
107
+ rubygems_version: 1.8.23
106
108
  signing_key:
107
109
  specification_version: 3
108
110
  summary: Ruby library to convert common video formats to HTML5 formats
109
- test_files:
111
+ test_files:
110
112
  - spec/converter_spec.rb
111
- - spec/converters/mp4_spec.rb
112
- - spec/converters/ogv_spec.rb
113
- - spec/converters/webm_spec.rb
113
+ - spec/converters/audio_converters/aac_spec.rb
114
+ - spec/converters/audio_converters/ogg_spec.rb
115
+ - spec/converters/video_converters/iphone_spec.rb
116
+ - spec/converters/video_converters/mp4_spec.rb
117
+ - spec/converters/video_converters/ogv_spec.rb
118
+ - spec/converters/video_converters/webm_spec.rb
114
119
  - spec/fixtures/converted/PLACEHOLDER
115
- - spec/fixtures/test.3gp
116
120
  - spec/fixtures/test.mpeg
121
+ - spec/media_time_spec.rb
117
122
  - spec/spec_helper.rb
118
123
  - spec/spec_helpers/video_file_spec_helper.rb
119
124
  - spec/video_spec.rb
data/lib/Voyeur/video.rb DELETED
@@ -1,23 +0,0 @@
1
- module Voyeur
2
- class Video
3
- attr_reader :filename
4
- def initialize(options)
5
- @filename = options[:filename]
6
- end
7
-
8
- def convert(options)
9
- converter = Voyeur::Converter.create(format: options[:to])
10
- converter.convert(video: self,
11
- output_filename: options[:output_filename],
12
- output_path: options[:output_path])
13
- end
14
-
15
- def convert_to_html5(options = nil)
16
- [:mp4, :ogv, :webm].each do |f|
17
- options_hash = {to: f}
18
- options_hash.merge!(options) if options
19
- convert(options_hash)
20
- end
21
- end
22
- end
23
- end
@@ -1,66 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Voyeur::Mp4 do
4
- before :each do
5
- @converter = Voyeur::Converter.create(format: :mp4)
6
- @video = Voyeur::Video.new(filename: valid_mpeg_file_path)
7
- end
8
-
9
- it "should use the correct factory" do
10
- @converter.class.to_s.should == "Voyeur::Mp4"
11
- end
12
-
13
- it "default convert string" do
14
- @converter.convert_options.should == "-b 1500k -vcodec libx264 -g 30"
15
- end
16
-
17
- context "A valid Video" do
18
- after :each do
19
- File.delete(valid_mpeg_file_path.gsub(/mpeg/, "mp4")) if File.exists?(valid_mpeg_file_path.gsub(/mpeg/, "mp4"))
20
- end
21
-
22
- context "#convert_options" do
23
- it "should name the video correctly" do
24
- @converter.convert(video: @video)
25
- output_file = valid_mpeg_file_path.gsub(/mpeg/, "mp4")
26
- @converter.output_video.filename.should == output_file
27
- end
28
-
29
- it "should return a video" do
30
- @converter.convert(video: @video)
31
- @converter.input_video.should == @video
32
- end
33
-
34
- context "real video" do
35
- it "should return conversion status indicating success" do
36
- result = @converter.convert(video: @video)
37
- result[:status].should == 0
38
- result[:video].should == @converter.output_video
39
- end
40
-
41
- it "should allow them to name the video" do
42
- result = @converter.convert(video: @video)
43
- result[:status].should == 0
44
- result[:video].should == @converter.output_video
45
- end
46
- end
47
- end
48
- end
49
-
50
- context "An invalid Video" do
51
- before :each do
52
- @converter = Voyeur::Converter.create(format: :mp4)
53
- @video = Voyeur::Video.new(filename: 'test_video.mpeg')
54
- end
55
-
56
- context "File does not exist" do
57
- it "should return conversion status indicating failure" do
58
- result = @converter.convert(video: @video)
59
- result[:status].should == 1
60
- result[:video].should == @converter.output_video
61
- result[:error_message].should match(/test_video.mpeg: No such file or directory/)
62
- result[:stderr].nil?.should == false
63
- end
64
- end
65
- end
66
- end
@@ -1,46 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Voyeur::Ogv do
4
- context "New Video" do
5
- before :each do
6
- @converter = Voyeur::Converter.create(format: :ogv)
7
- @video = Voyeur::Video.new(filename: 'test_video.ogv')
8
- end
9
-
10
- it "should use the correct factory" do
11
- @converter.class.to_s.should == "Voyeur::Ogv"
12
- end
13
-
14
- context "#convert_options" do
15
- it "default convert string" do
16
- @converter.convert_options.should == "-b 1500k -vcodec libtheora -acodec libvorbis -ab 160000 -g 30"
17
- end
18
-
19
- it "should raise an exception if no video is passed" do
20
- @video = nil
21
- -> { @converter.convert(video: @video) }.should raise_error Voyeur::Exceptions::NoVideoPresent
22
- end
23
-
24
- it "should return a video" do
25
- @converter.convert(video: @video)
26
- @converter.input_video.should == @video
27
- end
28
- end
29
- end
30
-
31
- context "An invalid Video" do
32
- before :each do
33
- @converter = Voyeur::Converter.create(format: :ogv)
34
- @video = Voyeur::Video.new(filename: 'test_video.mpeg')
35
- end
36
- context "File does not exist" do
37
- it "should return conversion status indicating failure" do
38
- result = @converter.convert(video: @video)
39
- result[:status].should == 1
40
- result[:video].should == @converter.output_video
41
- result[:error_message].should match(/test_video.mpeg: No such file or directory/)
42
- result[:stderr].nil?.should == false
43
- end
44
- end
45
- end
46
- end
@@ -1,48 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Voyeur::Webm do
4
- context "New Video" do
5
- before :each do
6
- @converter = Voyeur::Converter.create(format: :webm)
7
- @video = Voyeur::Video.new(filename: 'test_video.webm')
8
- end
9
-
10
- it "should use the correct factory" do
11
- @converter.class.to_s.should == "Voyeur::Webm"
12
- end
13
-
14
- context "#convert_options" do
15
- it "default convert string" do
16
- @converter.convert_options.should == "-b 1500k -vcodec libvpx -acodec libvorbis -ab 160000 -f webm -g 30"
17
- end
18
-
19
- it "should raise an exception if no video is passed" do
20
- @video = nil
21
- -> { @converter.convert(video: @video) }.should raise_error Voyeur::Exceptions::NoVideoPresent
22
- end
23
-
24
- it "should return a video" do
25
- @converter.convert(video: @video)
26
- @converter.input_video.should == @video
27
- end
28
- end
29
- end
30
-
31
- context "An invalid Video" do
32
- before :each do
33
- @converter = Voyeur::Converter.create(format: :webm)
34
- @video = Voyeur::Video.new(filename: 'test_video.mpeg')
35
- end
36
-
37
- context "File does not exist" do
38
- it "should return conversion status indicating failure" do
39
- result = @converter.convert(video: @video)
40
- result[:status].should == 1
41
- result[:video].should == @converter.output_video
42
- result[:error_message].should match(/test_video.mpeg: No such file or directory/)
43
- result[:stderr].nil?.should == false
44
- end
45
- end
46
- end
47
-
48
- end
Binary file