rvideo-tecnobrat 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/ENV +100 -0
  2. data/ENV2 +129 -0
  3. data/History.txt +30 -0
  4. data/License.txt +20 -0
  5. data/Manifest.txt +47 -0
  6. data/README.txt +91 -0
  7. data/RULES +11 -0
  8. data/Rakefile +184 -0
  9. data/config/boot.rb +16 -0
  10. data/lib/rvideo.rb +17 -0
  11. data/lib/rvideo/errors.rb +24 -0
  12. data/lib/rvideo/float.rb +7 -0
  13. data/lib/rvideo/inspector.rb +486 -0
  14. data/lib/rvideo/reporter.rb +176 -0
  15. data/lib/rvideo/reporter/views/index.html.erb +27 -0
  16. data/lib/rvideo/reporter/views/report.css +27 -0
  17. data/lib/rvideo/reporter/views/report.html.erb +81 -0
  18. data/lib/rvideo/reporter/views/report.js +9 -0
  19. data/lib/rvideo/tools/abstract_tool.rb +79 -0
  20. data/lib/rvideo/tools/ffmpeg.rb +128 -0
  21. data/lib/rvideo/tools/flvtool2.rb +45 -0
  22. data/lib/rvideo/tools/mencoder.rb +65 -0
  23. data/lib/rvideo/transcoder.rb +122 -0
  24. data/lib/rvideo/version.rb +9 -0
  25. data/scripts/txt2html +67 -0
  26. data/setup.rb +1585 -0
  27. data/spec/files/kites.mp4 +0 -0
  28. data/spec/fixtures/ffmpeg_builds.yml +28 -0
  29. data/spec/fixtures/files.yml +385 -0
  30. data/spec/fixtures/recipes.yml +57 -0
  31. data/spec/integrations/files/files.yml +361 -0
  32. data/spec/integrations/formats_spec.rb +295 -0
  33. data/spec/integrations/inspection_spec.rb +15 -0
  34. data/spec/integrations/recipes_spec.rb +0 -0
  35. data/spec/integrations/rvideo_spec.rb +17 -0
  36. data/spec/integrations/transcoding_spec.rb +9 -0
  37. data/spec/spec.opts +1 -0
  38. data/spec/spec_helper.rb +11 -0
  39. data/spec/units/abstract_tool_spec.rb +112 -0
  40. data/spec/units/ffmpeg_spec.rb +703 -0
  41. data/spec/units/flvtool2_spec.rb +314 -0
  42. data/spec/units/inspector_spec.rb +49 -0
  43. data/spec/units/mencoder_spec.rb +4986 -0
  44. data/spec/units/transcoder_spec.rb +140 -0
  45. data/website/index.html +219 -0
  46. data/website/index.txt +142 -0
  47. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  48. metadata +116 -0
@@ -0,0 +1,140 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ def setup_spec
4
+ @options = {:input_file => "foo", :output_file => "bar", :resolution => "baz"}
5
+ @simple_avi = "ffmpeg -i $input_file$ -ar 44100 -ab 64 -vcodec xvid -acodec mp3 -r 29.97 -s $resolution$ -y $output_file$"
6
+ @transcoder = RVideo::Transcoder.new
7
+ @mock_original_file = mock(:original)
8
+ @mock_original_file.stub!(:raw_response)
9
+ RVideo::Inspector.stub!(:new).and_return(@mock_original_file)
10
+ end
11
+
12
+ module RVideo
13
+
14
+ describe Transcoder, " when the execute method receives valid parameters" do
15
+ before do
16
+ setup_spec
17
+ @transcoder.stub!(:check_integrity).and_return(true)
18
+ end
19
+
20
+ it "should pass a string as-is, along with options" do
21
+ @transcoder.stub!(:parse_and_execute)
22
+ @simple_avi = "ffmpeg -i foo"
23
+ @transcoder.execute(@simple_avi, @options)
24
+ end
25
+
26
+ it "should store a Tool object at transcoder.executed_commands" do
27
+ @mock_ffmpeg = mock("ffmpeg")
28
+ Tools::AbstractTool.stub!(:assign).and_return(@mock_ffmpeg)
29
+ @mock_ffmpeg.should_receive(:execute)
30
+ @transcoder.execute(@simple_avi, @options)
31
+ @transcoder.executed_commands.size.should == 1
32
+ @transcoder.executed_commands.first.should == @mock_ffmpeg
33
+ end
34
+
35
+ end
36
+
37
+ describe Transcoder, " file integrity checks" do
38
+
39
+ before do
40
+ setup_spec
41
+ @transcoder.stub!(:parse_and_execute)
42
+ @mock_processed_file = mock("processed")
43
+ @mock_original_file.stub!(:duration).and_return 10
44
+ @mock_processed_file.stub!(:duration).and_return 10
45
+ @mock_processed_file.stub!(:invalid?).and_return false
46
+ Inspector.should_receive(:new).once.with(:file => "foo").and_return(@mock_original_file)
47
+ Inspector.should_receive(:new).once.with(:file => "bar").and_return(@mock_processed_file)
48
+ end
49
+
50
+ it "should call the inspector twice on a successful job, and should set @original and @processed" do
51
+ @transcoder.original.should be_nil
52
+ @transcoder.processed.should be_nil
53
+
54
+ @transcoder.execute(@simple_avi, @options)
55
+ @transcoder.original.should == @mock_original_file
56
+ @transcoder.processed.should == @mock_processed_file
57
+ end
58
+
59
+ it "should check integrity" do
60
+ @transcoder.should_receive(:check_integrity).once.and_return true
61
+ @transcoder.execute(@simple_avi, @options).should be_true
62
+ @transcoder.errors.should be_empty
63
+ end
64
+
65
+ it "should fail if output duration is more than 10% different than the original" do
66
+ @mock_original_file.should_receive(:duration).twice.and_return(10)
67
+ @mock_processed_file.should_receive(:duration).twice.and_return(13)
68
+ @transcoder.execute(@simple_avi, @options).should be_false
69
+ @transcoder.errors.should == ["Original file has a duration of 10, but processed file has a duration of 13"]
70
+ end
71
+
72
+ it "should fail if the processed file is invalid" do
73
+ @mock_processed_file.should_receive(:invalid?).and_return(true)
74
+ @transcoder.execute(@simple_avi, @options).should be_false
75
+ @transcoder.errors.should_not be_empty
76
+ end
77
+
78
+ end
79
+
80
+ describe Transcoder, "#parse_and_execute" do
81
+ before do
82
+ @options = {:input_file => "foo", :output_file => "bar", :resolution => "baz"}
83
+ @simple_avi = "ffmpeg -i $input_file$ -ar 44100 -ab 64 -vcodec xvid -acodec mp3 -r 29.97 -s $resolution$ -y $output_file$"
84
+ @mock_tool = mock("tool")
85
+ @mock_tool.stub!(:execute)
86
+ @transcoder = Transcoder.new
87
+ Inspector.stub!(:new)
88
+ end
89
+
90
+ it "should assign a command via AbstractTool.assign, and pass the right options" do
91
+ Tools::AbstractTool.should_receive(:assign).with(@simple_avi, @options).and_return(@mock_tool)
92
+ @transcoder.send(:parse_and_execute, @simple_avi, @options)
93
+ end
94
+
95
+ it "should call Tools::AbstractTool once with a one-line recipe" do
96
+ Tools::AbstractTool.should_receive(:assign).once.and_return(@mock_tool)
97
+ @transcoder.send(:parse_and_execute, @simple_avi, @options)
98
+ end
99
+
100
+ it "should call twice with a two-line recipe" do
101
+ two_line = "ffmpeg -i foo \n ffmpeg -i bar"
102
+ Tools::AbstractTool.should_receive(:assign).twice.and_return(@mock_tool)
103
+ @transcoder.send(:parse_and_execute, two_line, @options)
104
+ end
105
+
106
+ it "should call five times with a five-line recipe" do
107
+ five_line = "ffmpeg -i foo \n ffmpeg -i bar \n flvtool -i foo \n mp4box \n qt tools 8"
108
+ Tools::AbstractTool.should_receive(:assign).exactly(5).and_return(@mock_tool)
109
+ @transcoder.send(:parse_and_execute, five_line, @options)
110
+ end
111
+
112
+ it "should pass an exception from the abstract tool" do
113
+ Tools::AbstractTool.should_receive(:assign).and_raise(TranscoderError::UnexpectedResult)
114
+
115
+ lambda {
116
+ @transcoder.send(:parse_and_execute, @simple_avi, @options)
117
+ }.should raise_error(TranscoderError::UnexpectedResult)
118
+ end
119
+ end
120
+
121
+ describe Transcoder, " when the execute method receives invalid parameters" do
122
+ before do
123
+ setup_spec
124
+ end
125
+
126
+ it "should raise an exception when trying to call a tool that doesn't exist" do
127
+ lambda {
128
+ @transcoder.send(:parse_and_execute, "foo -i bar")
129
+ }.should raise_error(NameError, "uninitialized constant RVideo::Tools::Foo")
130
+ end
131
+
132
+ it "should raise an exception when the first argument is not a string" do
133
+ [String, 1, 1.0, true, nil, :foo].each do |obj|
134
+ lambda {
135
+ @transcoder.execute(obj)
136
+ }.should raise_error(TranscoderError::UnknownError, /ArgumentError.*first/)
137
+ end
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,219 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
6
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7
+ <title>
8
+ Ruby Video Processing
9
+ </title>
10
+ <script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
11
+ <style>
12
+
13
+ </style>
14
+ <script type="text/javascript">
15
+ window.onload = function() {
16
+ settings = {
17
+ tl: { radius: 10 },
18
+ tr: { radius: 10 },
19
+ bl: { radius: 10 },
20
+ br: { radius: 10 },
21
+ antiAlias: true,
22
+ autoPad: true,
23
+ validTags: ["div"]
24
+ }
25
+ var versionBox = new curvyCorners(settings, document.getElementById("version"));
26
+ versionBox.applyCornersToAll();
27
+ }
28
+ </script>
29
+ </head>
30
+ <body>
31
+ <div id="main">
32
+ <div style="text-align:right">
33
+ <a href="http://rvideo.rubyforge.org/rdoc">Documentation</a> | <a href="http://zencoder.tv">Zencoder</a> | <a href="http://railspikes.com">Blog</a> | <a href="http://groups.google.com/group/rvideo">Group</a>
34
+ </div>
35
+ <h1>Ruby Video Processing</h1>
36
+ <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/rvideo"; return false'>
37
+ <p>Get Version</p>
38
+ <a href="http://rubyforge.org/projects/rvideo" class="numbers">0.9.3</a>
39
+ </div>
40
+ <h1>&#x2192; &#8216;rvideo&#8217;</h1>
41
+
42
+
43
+ <h2>What</h2>
44
+
45
+
46
+ <p>RVideo is a Ruby library inspects and processes video and audio files by
47
+ providing an interface to free Unix tools like ffmpeg.</p>
48
+
49
+
50
+ <h2>Installing</h2>
51
+
52
+
53
+ <p>Installation is a little involved. First, install the gem:</p>
54
+
55
+
56
+ <pre syntax="ruby">sudo gem install rvideo</pre>
57
+
58
+ <p>Next, install ffmpeg and (possibly) other related libraries. This is
59
+ documented elsewhere on the web, and can be a headache. If you are on a Mac,
60
+ the Macports build is reasonably good (though not perfect). Install with:</p>
61
+
62
+
63
+ <pre>sudo port install ffmpeg</pre>
64
+
65
+ <p>Or, for a better build (recommended), add additional video- and audio-related
66
+ libraries, like this:</p>
67
+
68
+
69
+ <pre>sudo port install ffmpeg +lame +libogg +vorbis +faac +faad +xvid +x264 +a52</pre>
70
+
71
+ <p>Most package management systems include a build of ffmpeg, but many include a
72
+ poor build. So you may need to compile from scratch.</p>
73
+
74
+
75
+ <p>If you want to create Flash Video files, also install flvtool2:</p>
76
+
77
+
78
+ <pre>sudo gem install flvtool2</pre>
79
+
80
+ <p>Once ffmpeg and RVideo are installed, you&#8217;re set.</p>
81
+
82
+
83
+ <h2>The basics</h2>
84
+
85
+
86
+ <pre>
87
+ file = RVideo::Inspector.new(:file =&gt; "#{FILE_PATH}/filename.mp4")
88
+ file.video_codec # =&gt; mpeg4
89
+ file.audio_codec # =&gt; aac
90
+ file.resolution # =&gt; 320x240
91
+ </pre>
92
+
93
+ <pre>
94
+ command = "ffmpeg -i $input_file -vcodec xvid -s $resolution$ $output_file$"
95
+ options = {
96
+ :input_file =&gt; "#{FILE_PATH}/filename.mp4",
97
+ :output_file =&gt; "#{FILE_PATH}/processed_file.mp4",
98
+ :resolution =&gt; "640x480"
99
+ }
100
+
101
+ transcoder = RVideo::Transcoder.new
102
+
103
+ transcoder.execute(command, options)
104
+
105
+ transcoder.processed.video_codec # =&gt; xvid
106
+ </pre>
107
+
108
+ <h2>Demonstration of usage</h2>
109
+
110
+
111
+ <p>To inspect a file, initialize an RVideo file inspector object. See the
112
+ documentation for details.</p>
113
+
114
+
115
+ <p>A few examples:</p>
116
+
117
+
118
+ <pre>file = RVideo::Inspector.new(:file =&gt; "#{APP_ROOT}/files/input.mp4")</pre>
119
+
120
+ <pre>file = RVideo::Inspector.new(:raw_response =&gt; @existing_response)</pre>
121
+
122
+ <pre>
123
+ file = RVideo::Inspector.new(:file =&gt; "#{APP_ROOT}/files/input.mp4",
124
+ :ffmpeg_binary =&gt; "#{APP_ROOT}/bin/ffmpeg")
125
+ </pre>
126
+
127
+ <pre>
128
+ file.fps # =&gt; "29.97"
129
+ file.duration # =&gt; "00:05:23.4"
130
+ </pre>
131
+
132
+ <p>To transcode a video, initialize a Transcoder object.</p>
133
+
134
+
135
+ <pre>transcoder = RVideo::Transcoder.new</pre>
136
+
137
+ <p>Then pass a command and valid options to the execute method.</p>
138
+
139
+
140
+ <pre>
141
+ recipe = "ffmpeg -i $input_file$ -ar 22050 -ab 64 -f flv -r 29.97 -s"
142
+ recipe += " $resolution$ -y $output_file$"
143
+ recipe += "\nflvtool2 -U $output_file$"
144
+ begin
145
+ transcoder.execute(recipe, {:input_file =&gt; "/path/to/input.mp4",
146
+ :output_file =&gt; "/path/to/output.flv", :resolution =&gt; "640x360"})
147
+ rescue TranscoderError =&gt; e
148
+ puts "Unable to transcode file: #{e.class} - #{e.message}"
149
+ end
150
+ </pre>
151
+
152
+ <p>If the job succeeds, you can access the metadata of the input and output
153
+ files with:</p>
154
+
155
+
156
+ <pre>
157
+ transcoder.original # RVideo::Inspector object
158
+ transcoder.processed # RVideo::Inspector object
159
+ </pre>
160
+
161
+ <p>Even if the file is processed, it may still have problems. RVideo
162
+ will populate an errors array if the duration of the processed video
163
+ differs from the duration of the original video, or if the processed
164
+ file is unreadable.</p>
165
+
166
+
167
+ <h2>Contribute</h2>
168
+
169
+
170
+ <p>Contribute to RVideo! If you want to help out, there are a few things you can
171
+ do.</p>
172
+
173
+
174
+ <ul>
175
+ <li>Use, test, and submit bugs/patches</li>
176
+ <li>We need a RVideo::Tools::Mencoder class to add mencoder support.</li>
177
+ <li>Other tool classes would be great &#8211; On2, mp4box, Quicktime (?), etc.</li>
178
+ <li>Submit other fixes, features, optimizations, and refactorings</li>
179
+ </ul>
180
+
181
+
182
+ <p>Read the <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/">8 steps for fixing other people&#8217;s code</a> and for section <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups">8b: Submit patch to Google Groups</a>, use the Google Group above.</p>
183
+
184
+
185
+ <p>The trunk repository is <code>svn://rubyforge.org/var/svn/rvideo/trunk</code> for anonymous access.</p>
186
+
187
+
188
+ <h2>Forum</h2>
189
+
190
+
191
+ <p><a href="http://groups.google.com/group/rvideo">http://groups.google.com/group/rvideo</a></p>
192
+
193
+
194
+ <h2>Zencoder (Shameless Plug)</h2>
195
+
196
+
197
+ <p>Zencoder is a commercial video transcoder built by Slantwise Design. Zencoder uses RVideo for its video processing, but adds file queuing, distributed transcoding, a web-based transcoder dashboard, and more. See <a href="http://zencoder.tv">http://zencoder.tv</a> or <a href="http://slantwisedesign.com">http://slantwisedesign.com</a> for more.</p>
198
+
199
+
200
+ <h2>License</h2>
201
+
202
+
203
+ <p>This code is free to use under the terms of the <span class="caps">MIT</span> license.</p>
204
+
205
+
206
+ <h2>Contact</h2>
207
+
208
+
209
+ <p>Comments are welcome. Send an email to Jonathan Dahl at jon [at] slantwisedesign.</p>
210
+ <p class="coda">
211
+ Page created with newgem by <a href="mailto:drnicwilliams@gmail.com">Dr Nic</a>, 30th October 2007<br>
212
+ Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
213
+ </p>
214
+ </div>
215
+
216
+ <!-- insert site tracking codes here, like Google Urchin -->
217
+
218
+ </body>
219
+ </html>
@@ -0,0 +1,142 @@
1
+ h1. Ruby Video Processing
2
+
3
+ h1. &#x2192; 'rvideo'
4
+
5
+
6
+ h2. What
7
+
8
+ RVideo is a Ruby library inspects and processes video and audio files by
9
+ providing an interface to free Unix tools like ffmpeg.
10
+
11
+ h2. Installing
12
+
13
+ Installation is a little involved. First, install the gem:
14
+
15
+ <pre syntax="ruby">sudo gem install rvideo</pre>
16
+
17
+ Next, install ffmpeg and (possibly) other related libraries. This is
18
+ documented elsewhere on the web, and can be a headache. If you are on a Mac,
19
+ the Macports build is reasonably good (though not perfect). Install with:
20
+
21
+ <pre>sudo port install ffmpeg</pre>
22
+
23
+ Or, for a better build (recommended), add additional video- and audio-related
24
+ libraries, like this:
25
+
26
+ <pre>sudo port install ffmpeg +lame +libogg +vorbis +faac +faad +xvid +x264 +a52</pre>
27
+
28
+ Most package management systems include a build of ffmpeg, but many include a
29
+ poor build. So you may need to compile from scratch.
30
+
31
+ If you want to create Flash Video files, also install flvtool2:
32
+
33
+ <pre>sudo gem install flvtool2</pre>
34
+
35
+ Once ffmpeg and RVideo are installed, you're set.
36
+
37
+ h2. The basics
38
+
39
+ <pre>
40
+ file = RVideo::Inspector.new(:file => "#{FILE_PATH}/filename.mp4")
41
+ file.video_codec # => mpeg4
42
+ file.audio_codec # => aac
43
+ file.resolution # => 320x240
44
+ </pre>
45
+
46
+ <pre>
47
+ command = "ffmpeg -i $input_file -vcodec xvid -s $resolution$ $output_file$"
48
+ options = {
49
+ :input_file => "#{FILE_PATH}/filename.mp4",
50
+ :output_file => "#{FILE_PATH}/processed_file.mp4",
51
+ :resolution => "640x480"
52
+ }
53
+
54
+ transcoder = RVideo::Transcoder.new
55
+
56
+ transcoder.execute(command, options)
57
+
58
+ transcoder.processed.video_codec # => xvid
59
+ </pre>
60
+
61
+ h2. Demonstration of usage
62
+
63
+ To inspect a file, initialize an RVideo file inspector object. See the
64
+ documentation for details.
65
+
66
+ A few examples:
67
+
68
+ <pre>file = RVideo::Inspector.new(:file => "#{APP_ROOT}/files/input.mp4")</pre>
69
+
70
+ <pre>file = RVideo::Inspector.new(:raw_response => @existing_response)</pre>
71
+
72
+ <pre>
73
+ file = RVideo::Inspector.new(:file => "#{APP_ROOT}/files/input.mp4",
74
+ :ffmpeg_binary => "#{APP_ROOT}/bin/ffmpeg")
75
+ </pre>
76
+
77
+ <pre>
78
+ file.fps # => "29.97"
79
+ file.duration # => "00:05:23.4"
80
+ </pre>
81
+
82
+ To transcode a video, initialize a Transcoder object.
83
+
84
+ <pre>transcoder = RVideo::Transcoder.new</pre>
85
+
86
+ Then pass a command and valid options to the execute method.
87
+
88
+ <pre>
89
+ recipe = "ffmpeg -i $input_file$ -ar 22050 -ab 64 -f flv -r 29.97 -s"
90
+ recipe += " $resolution$ -y $output_file$"
91
+ recipe += "\nflvtool2 -U $output_file$"
92
+ begin
93
+ transcoder.execute(recipe, {:input_file => "/path/to/input.mp4",
94
+ :output_file => "/path/to/output.flv", :resolution => "640x360"})
95
+ rescue TranscoderError => e
96
+ puts "Unable to transcode file: #{e.class} - #{e.message}"
97
+ end
98
+ </pre>
99
+
100
+ If the job succeeds, you can access the metadata of the input and output
101
+ files with:
102
+
103
+ <pre>
104
+ transcoder.original # RVideo::Inspector object
105
+ transcoder.processed # RVideo::Inspector object
106
+ </pre>
107
+
108
+ Even if the file is processed, it may still have problems. RVideo
109
+ will populate an errors array if the duration of the processed video
110
+ differs from the duration of the original video, or if the processed
111
+ file is unreadable.
112
+
113
+ h2. Contribute
114
+
115
+ Contribute to RVideo! If you want to help out, there are a few things you can
116
+ do.
117
+
118
+ * Use, test, and submit bugs/patches
119
+ * We need a RVideo::Tools::Mencoder class to add mencoder support.
120
+ * Other tool classes would be great - On2, mp4box, Quicktime (?), etc.
121
+ * Submit other fixes, features, optimizations, and refactorings
122
+
123
+ Read the "8 steps for fixing other people's code":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/ and for section "8b: Submit patch to Google Groups":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups, use the Google Group above.
124
+
125
+ The trunk repository is <code>svn://rubyforge.org/var/svn/rvideo/trunk</code> for anonymous access.
126
+
127
+
128
+ h2. Forum
129
+
130
+ "http://groups.google.com/group/rvideo":http://groups.google.com/group/rvideo
131
+
132
+ h2. Zencoder (Shameless Plug)
133
+
134
+ Zencoder is a commercial video transcoder built by Slantwise Design. Zencoder uses RVideo for its video processing, but adds file queuing, distributed transcoding, a web-based transcoder dashboard, and more. See "http://zencoder.tv":http://zencoder.tv or "http://slantwisedesign.com":http://slantwisedesign.com for more.
135
+
136
+ h2. License
137
+
138
+ This code is free to use under the terms of the MIT license.
139
+
140
+ h2. Contact
141
+
142
+ Comments are welcome. Send an email to Jonathan Dahl at jon [at] slantwisedesign.