polly-rffmpeg 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +104 -0
- data/VERSION.yml +4 -0
- data/lib/rffmpeg.rb +108 -0
- data/lib/rffmpeg/ffmpeg_command.rb +25 -0
- data/spec/rffmpeg_spec.rb +60 -0
- data/spec/spec_helper.rb +9 -0
- metadata +60 -0
data/README.rdoc
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
= rFFmpeg
|
2
|
+
|
3
|
+
A tiny wrapper for ffmpeg
|
4
|
+
|
5
|
+
== Requirements
|
6
|
+
|
7
|
+
rFFmpeg requires that you already have ffmpeg installed, obviously :)
|
8
|
+
|
9
|
+
== Install
|
10
|
+
|
11
|
+
gem install polly-rffmpeg --source http://gems.github.com
|
12
|
+
|
13
|
+
== Note
|
14
|
+
|
15
|
+
Please note that this is still pretty experimental and should be viewed more as an api proposal
|
16
|
+
rather than production ready.
|
17
|
+
However it does work so you can use it right now, if you so choose, but expect some major api
|
18
|
+
changes as time goes on.
|
19
|
+
|
20
|
+
== Usage
|
21
|
+
|
22
|
+
=== You can use RFFmpef like so:
|
23
|
+
|
24
|
+
require 'rubygems'
|
25
|
+
require 'rffmpeg'
|
26
|
+
|
27
|
+
include RFFmpeg
|
28
|
+
|
29
|
+
capture_stream "/path/to/video/<filename>.<ext>" do |input_stream|
|
30
|
+
input_stream.seek "00:02:10"
|
31
|
+
input_stream.duration "00:04:53"
|
32
|
+
|
33
|
+
input_stream.output_to "/path/to/video/<filename>.<ext>" do |output_stream|
|
34
|
+
output_stream.resolution "800x600"
|
35
|
+
output_stream.overwrite_existing true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
RFFmpeg::run
|
40
|
+
|
41
|
+
=== or like this:
|
42
|
+
|
43
|
+
require 'rubygems'
|
44
|
+
require 'rffmpeg'
|
45
|
+
|
46
|
+
include RFFmpeg
|
47
|
+
|
48
|
+
capture_stream("/path/to/video/<filename>.<ext>").output_to("/path/to/video/<filename>.<ext>")
|
49
|
+
|
50
|
+
RFFmpeg::run
|
51
|
+
|
52
|
+
=== or how about:
|
53
|
+
|
54
|
+
require 'rubygems'
|
55
|
+
require 'rffmpeg'
|
56
|
+
|
57
|
+
include RFFmpeg
|
58
|
+
|
59
|
+
capture_stream("/path/to/video/<filename>.<ext>")
|
60
|
+
output_to("/path/to/video/<filename>.<ext>")
|
61
|
+
|
62
|
+
RFFmpeg::run
|
63
|
+
|
64
|
+
=== this also works:
|
65
|
+
|
66
|
+
require 'rubygems'
|
67
|
+
require 'rffmpeg'
|
68
|
+
|
69
|
+
include RFFmpeg
|
70
|
+
|
71
|
+
capture_stream("/path/to/video/<filename>.<ext>").seek("00:02:10").output_to("/path/to/video/<filename>.<ext>").resolution("800x600")
|
72
|
+
|
73
|
+
RFFmpeg::run
|
74
|
+
|
75
|
+
|
76
|
+
== Extending
|
77
|
+
|
78
|
+
You can extend it with your own methods if they aren't already available, or even overide the default
|
79
|
+
behaviour of existing ones. Here's how you would go about it:
|
80
|
+
|
81
|
+
RFFmpeg::add_method :my_extension, :args do |args|
|
82
|
+
RFFmpegCommand.add args
|
83
|
+
end
|
84
|
+
|
85
|
+
So if you wanted to add a method for say, setting the video quantizer scale blur for example, here's
|
86
|
+
how you could do it:
|
87
|
+
|
88
|
+
RFFmpeg::add_method :quantizer_scale_blur, :blur do |blur|
|
89
|
+
RFFmpegCommand.add "-qblur #{blur}"
|
90
|
+
end
|
91
|
+
|
92
|
+
You would then call it just like any other method:
|
93
|
+
|
94
|
+
capture_stream "/path/to/video/<filename>.<ext>" do |input_stream|
|
95
|
+
input_stream.quantizer_scale_blur "0.5" # Your method is now available just like any other
|
96
|
+
# library method.
|
97
|
+
|
98
|
+
input_stream.output_to "/path/to/video/<filename>.<ext>" do |output_stream|
|
99
|
+
output_stream.resolution "800x600"
|
100
|
+
output_stream.overwrite_existing true
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
RFFmpeg::run
|
data/VERSION.yml
ADDED
data/lib/rffmpeg.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'rffmpeg/ffmpeg_command'
|
2
|
+
|
3
|
+
include FFMpegCommand
|
4
|
+
|
5
|
+
module RFFmpeg
|
6
|
+
|
7
|
+
def capture_stream(*input_streams, &block)
|
8
|
+
yield self if block_given?
|
9
|
+
input_streams.each do |input_stream|
|
10
|
+
FFMpegCommand.add "-i #{input_stream}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def output_to(*output_streams, &block)
|
15
|
+
yield self if block_given?
|
16
|
+
output_streams.each do |output_stream|
|
17
|
+
FFMpegCommand.add "#{output_stream}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.add_method(name, *args, &block)
|
22
|
+
define_method name do |args|
|
23
|
+
yield args
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
# Main options
|
29
|
+
def overwrite_existing(overwrite)
|
30
|
+
FFMpegCommand.add_at("-y", 0) if overwrite
|
31
|
+
end
|
32
|
+
|
33
|
+
def duration(duration)
|
34
|
+
FFMpegCommand.add "-t #{duration}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def file_size_limit(limit)
|
38
|
+
FFMpegCommand.add "-fs #{limit}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def seek(position)
|
42
|
+
FFMpegCommand.add "-ss #{position}"
|
43
|
+
end
|
44
|
+
|
45
|
+
def offset(offset)
|
46
|
+
FFMpegCommand.add "-itsoffset #{offset}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def title(title)
|
50
|
+
FFMpegCommand.add "-title '#{title}'"
|
51
|
+
end
|
52
|
+
|
53
|
+
def timestamp(timestamp)
|
54
|
+
FFMpegCommand.add "-timestamp #{timestamp}"
|
55
|
+
end
|
56
|
+
|
57
|
+
def author(author)
|
58
|
+
FFMpegCommand.add "-author '#{author}'"
|
59
|
+
end
|
60
|
+
|
61
|
+
def copyright(copyright)
|
62
|
+
FFMpegCommand.add "-copyright '#{copyright}'"
|
63
|
+
end
|
64
|
+
|
65
|
+
def comment(comment)
|
66
|
+
FFMpegCommand.add "-comment '#{comment}'"
|
67
|
+
end
|
68
|
+
|
69
|
+
def album(album)
|
70
|
+
FFMpegCommand.add "-album '#{album}'"
|
71
|
+
end
|
72
|
+
|
73
|
+
def track(track)
|
74
|
+
FFMpegCommand.add "-track #{track}"
|
75
|
+
end
|
76
|
+
|
77
|
+
def year(year)
|
78
|
+
FFMpegCommand.add "-year #{year}"
|
79
|
+
end
|
80
|
+
|
81
|
+
def logging_verbosity_level(verbosity)
|
82
|
+
FFMpegCommand.add "-v #{verbosity}"
|
83
|
+
end
|
84
|
+
|
85
|
+
def target(target)
|
86
|
+
FFMpegCommand.add "-target #{target}"
|
87
|
+
end
|
88
|
+
|
89
|
+
def frames_to_record(frames)
|
90
|
+
FFMpegCommand.add "-dframes #{frames}"
|
91
|
+
end
|
92
|
+
|
93
|
+
def subtitle_codec(codec)
|
94
|
+
FFMpegCommand.add "-scodec #{codec}"
|
95
|
+
end
|
96
|
+
|
97
|
+
# Video options
|
98
|
+
def resolution(resolution)
|
99
|
+
FFMpegCommand.add "-s #{resolution}"
|
100
|
+
end
|
101
|
+
|
102
|
+
# Execute ffmpeg command
|
103
|
+
|
104
|
+
def self.run
|
105
|
+
puts "Executing: " + FFMpegCommand.run
|
106
|
+
system FFMpegCommand.run
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module FFMpegCommand
|
2
|
+
extend self
|
3
|
+
|
4
|
+
@@commands = []
|
5
|
+
|
6
|
+
def add(cmd)
|
7
|
+
@@commands << cmd
|
8
|
+
end
|
9
|
+
|
10
|
+
def add_at(cmd, pos)
|
11
|
+
@@commands.insert(pos, cmd)
|
12
|
+
end
|
13
|
+
|
14
|
+
def clear
|
15
|
+
@@commands.clear
|
16
|
+
end
|
17
|
+
|
18
|
+
def run
|
19
|
+
str = "ffmpeg"
|
20
|
+
@@commands.each do |cmd|
|
21
|
+
str << " " + cmd
|
22
|
+
end
|
23
|
+
str
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
require 'rffmpeg'
|
4
|
+
|
5
|
+
include RFFmpeg
|
6
|
+
|
7
|
+
describe "calling a single method from the public api" do
|
8
|
+
|
9
|
+
it "should construct the corresponding ffmpeg command" do
|
10
|
+
FFMpegCommand.clear
|
11
|
+
|
12
|
+
resolution "800x600"
|
13
|
+
|
14
|
+
FFMpegCommand.run.should eql("ffmpeg -s 800x600")
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "calling several methods from the public api" do
|
20
|
+
|
21
|
+
it "should construct the corresponding ffmpeg command" do
|
22
|
+
FFMpegCommand.clear
|
23
|
+
|
24
|
+
capture_stream("some_movie.mov")
|
25
|
+
seek("00:02:10")
|
26
|
+
output_to("test.avi")
|
27
|
+
resolution("800x600")
|
28
|
+
|
29
|
+
FFMpegCommand.run.should eql("ffmpeg -i some_movie.mov -ss 00:02:10 test.avi -s 800x600")
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "chaining methods from the public api" do
|
35
|
+
|
36
|
+
it "should construct the corresponding ffmpeg command" do
|
37
|
+
FFMpegCommand.clear
|
38
|
+
|
39
|
+
capture_stream("some_movie.mov").seek("00:02:10").output_to("test.avi").resolution("800x600")
|
40
|
+
|
41
|
+
FFMpegCommand.run.should eql("ffmpeg -i some_movie.mov -ss 00:02:10 test.avi -s 800x600")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "using RFFmpeg with blocks" do
|
46
|
+
|
47
|
+
it "should construct the corresponding ffmpeg command" do
|
48
|
+
FFMpegCommand.clear
|
49
|
+
|
50
|
+
capture_stream "some_movie.mov" do |input_stream|
|
51
|
+
input_stream.seek "00:02:10"
|
52
|
+
|
53
|
+
input_stream.output_to "some_movie.mov" do |output_stream|
|
54
|
+
output_stream.resolution "800x600"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
FFMpegCommand.run.should eql("ffmpeg -ss 00:02:10 -s 800x600 some_movie.mov -i some_movie.mov")
|
59
|
+
end
|
60
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: polly-rffmpeg
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Patrik Hedman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-02-11 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: TODO
|
17
|
+
email: patrik@moresale.se
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- README.rdoc
|
26
|
+
- VERSION.yml
|
27
|
+
- lib/rffmpeg
|
28
|
+
- lib/rffmpeg/ffmpeg_command.rb
|
29
|
+
- lib/rffmpeg.rb
|
30
|
+
- spec/rffmpeg_spec.rb
|
31
|
+
- spec/spec_helper.rb
|
32
|
+
has_rdoc: true
|
33
|
+
homepage: http://github.com/polly/rffmpeg
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options:
|
36
|
+
- --inline-source
|
37
|
+
- --charset=UTF-8
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "0"
|
45
|
+
version:
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
requirements: []
|
53
|
+
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 1.2.0
|
56
|
+
signing_key:
|
57
|
+
specification_version: 2
|
58
|
+
summary: TODO
|
59
|
+
test_files: []
|
60
|
+
|