streamio-ffmpeg 0.8.2 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ == 0.8.3 2011-09-01
2
+
3
+ * Parameters now come in the order of codecs, presets, others so that we can override the presets
4
+ * Added encoding option keyframe_interval to set number of frames between i-frames (aka GOP size)
5
+ * Streamio (sponsor of this project) have launched new awesome pricing @ http://streamio.com
6
+
1
7
  == 0.8.2 2011-08-19
2
8
 
3
9
  * Path to ffmpeg binary can now be specified (thanks jonathandean)
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 Streamio Networks AB
1
+ Copyright (c) 2011 Streamio AB
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md ADDED
@@ -0,0 +1,140 @@
1
+ Streamio FFMPEG
2
+ ===============
3
+
4
+ Simple yet powerful wrapper around the ffmpeg command for reading metadata and transcoding movies.
5
+
6
+ All work on this project is sponsored by the online video platform [Streamio](http://streamio.com).
7
+
8
+ [![Streamio](http://d253c4ja9jigvu.cloudfront.net/assets/small-logo.png)](http://streamio.com)
9
+
10
+ Installation
11
+ ------------
12
+
13
+ (sudo) gem install streamio-ffmpeg
14
+
15
+ This version is tested against ffmpeg 0.8. So no guarantees with earlier (or much later) versions. Output and input standards have inconveniently changed rather a lot between versions of ffmpeg. My goal is to keep this library in sync with new versions of ffmpeg as they come along.
16
+
17
+ Usage
18
+ -----
19
+
20
+ ### Require the gem
21
+
22
+ ``` ruby
23
+ require 'rubygems'
24
+ require 'streamio-ffmpeg'
25
+ ```
26
+
27
+ ### Reading Metadata
28
+
29
+ ``` ruby
30
+ movie = FFMPEG::Movie.new("path/to/movie.mov")
31
+
32
+ movie.duration # 7.5 (duration of the movie in seconds)
33
+ movie.bitrate # 481 (bitrate in kb/s)
34
+ movie.size # 455546 (filesize in bytes)
35
+
36
+ movie.video_stream # "h264, yuv420p, 640x480 [PAR 1:1 DAR 4:3], 371 kb/s, 16.75 fps, 15 tbr, 600 tbn, 1200 tbc" (raw video stream info)
37
+ movie.video_codec # "h264"
38
+ movie.colorspace # "yuv420p"
39
+ movie.resolution # "640x480"
40
+ movie.width # 640 (width of the movie in pixels)
41
+ movie.height # 480 (height of the movie in pixels)
42
+ movie.frame_rate # 16.72 (frames per second)
43
+
44
+ movie.audio_stream # "aac, 44100 Hz, stereo, s16, 75 kb/s" (raw audio stream info)
45
+ movie.audio_codec # "aac"
46
+ movie.audio_sample_rate # 44100
47
+ movie.audio_channels # 2
48
+
49
+ movie.valid? # true (would be false if ffmpeg fails to read the movie)
50
+ ```
51
+
52
+ ### Transcoding
53
+
54
+ First argument is the output file path.
55
+
56
+ ``` ruby
57
+ movie.transcode("tmp/movie.mp4") # Default ffmpeg settings for mp4 format
58
+ ```
59
+
60
+ Keep track of progress with an optional block.
61
+
62
+ ``` ruby
63
+ movie.transcode(movie.mp4") { |progress| puts progress } # 0.2 ... 0.5 ... 1.0
64
+ ```
65
+
66
+ Give custom command line options with a string.
67
+
68
+ ``` ruby
69
+ movie.transcode("movie.mp4", "-ac aac -vc libx264 -ac 2 ...")
70
+ ```
71
+
72
+ Use the EncodingOptions parser for humanly readable transcoding options. Below you'll find most of the supported options. Note that the :custom key will be used as is without modification so use it for any tricky business you might need.
73
+
74
+ ``` ruby
75
+ options = {:video_codec => "libx264", :frame_rate => 10, :resolution => "320x240", :video_bitrate => 300, :video_bitrate_tolerance => 100,
76
+ :croptop => 60, :cropbottom => 60, :cropleft => 10, :cropright => 10, :aspect => 1.333333, :keyframe_interval => 90,
77
+ :audio_codec => "libfaac", :audio_bitrate => 32, :audio_sample_rate => 22050, :audio_channels => 1,
78
+ :threads => 2,
79
+ :custom => "-flags +loop -cmp +chroma -partitions +parti4x4+partp8x8 -flags2 +mixed_refs -me_method umh -subq 6 -refs 6 -rc_eq 'blurCplx^(1-qComp)' -coder 0 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 21"}
80
+ movie.transcode("movie.mp4", options)
81
+ ```
82
+
83
+ The transcode function returns a Movie object for the encoded file.
84
+
85
+ ``` ruby
86
+ transcoded_movie = movie.transcode("tmp/movie.flv")
87
+
88
+ transcoded_movie.video_codec # "flv"
89
+ transcoded_movie.audio_codec # "mp3"
90
+ ```
91
+
92
+ Aspect ratio is added to encoding options automatically if none is specified.
93
+
94
+ ``` ruby
95
+ options = {:resolution => "320x180"} # Will add -aspect 1.77777777777778 to ffmpeg
96
+ ```
97
+
98
+ Preserve aspect ratio on width or height by using the preserve_aspect_ratio transcoder option.
99
+
100
+ ``` ruby
101
+ widescreen_movie = FFMPEG::Movie.new("path/to/widescreen_movie.mov")
102
+
103
+ options = {:resolution => "320x240"}
104
+
105
+ transcoder_options = {:preserve_aspect_ratio => :width}
106
+ widescreen_movie.transcode("movie.mp4", options, transcoder_options) # Output resolution will be 320x180
107
+
108
+ transcoder_options = {:preserve_aspect_ratio => :height}
109
+ widescreen_movie.transcode("movie.mp4", options, transcoder_options) # Output resolution will be 426x240
110
+ ```
111
+
112
+ For constant bitrate encoding use video_min_bitrate and video_max_bitrate with buffer_size.
113
+
114
+ ``` ruby
115
+ options = {:video_min_bitrate => 600, :video_max_bitrate => 600, :buffer_size => 2000}
116
+ movie.transcode("movie.flv", options)
117
+ ```
118
+
119
+ Use ffpreset files to avoid headaches when encoding with libx264 (http://www.ffmpeg.org/ffmpeg-doc.html#SEC13).
120
+
121
+ ``` ruby
122
+ options = {:video_codec => "libx264", :video_preset => "medium"} # audio_preset and file_preset also availible
123
+ movie.transcode("movie.mp4", options) # encodes video using libx264-medium.ffpreset
124
+ ```
125
+
126
+ Specify the path to ffmpeg
127
+ --------------------------
128
+
129
+ By default, streamio assumes that the ffmpeg binary is available in the execution path and named ffmpeg and so will run commands that look something like "ffmpeg -i /path/to/input.file ...". Use the FFMPEG.ffmpeg_binary setter to specify the full path to the binary if necessary:
130
+
131
+ ``` ruby
132
+ FFMPEG.ffmpeg_binary = '/usr/local/bin/ffmpeg'
133
+ ```
134
+
135
+ This will cause the same command to run as "/usr/local/bin/ffmpeg -i /path/to/input.file ..." instead.
136
+
137
+ Copyright
138
+ ---------
139
+
140
+ Copyright (c) 2011 Streamio AB. See LICENSE for details.
@@ -9,8 +9,12 @@ module FFMPEG
9
9
  send("convert_#{key}", value) if value && supports_option?(key)
10
10
  end
11
11
 
12
- # put the preset parameters last
13
- params = params.reject { |p| p =~ /\-.pre/ } + params.select { |p| p =~ /\-.pre/ }
12
+ # codecs should go before the presets so that the files will be matched successfully
13
+ # all other parameters go after so that we can override whatever is in the preset
14
+ codecs = params.select { |p| p =~ /codec/ }
15
+ presets = params.select { |p| p =~ /\-.pre/ }
16
+ other = params - codecs - presets
17
+ params = codecs + presets + other
14
18
 
15
19
  params_string = params.join(" ")
16
20
  params_string << " #{convert_aspect(calculate_aspect)}" if calculate_aspect?
@@ -128,6 +132,10 @@ module FFMPEG
128
132
  "-fpre #{value}"
129
133
  end
130
134
 
135
+ def convert_keyframe_interval(value)
136
+ "-g #{value}"
137
+ end
138
+
131
139
  def convert_custom(value)
132
140
  value
133
141
  end
@@ -1,3 +1,3 @@
1
1
  module FFMPEG
2
- VERSION = "0.8.2"
2
+ VERSION = "0.8.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: streamio-ffmpeg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.8.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-19 00:00:00.000000000Z
12
+ date: 2011-09-12 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &2152909420 !ruby/object:Gem::Requirement
16
+ requirement: &2160926780 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 2.6.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2152909420
24
+ version_requirements: *2160926780
25
25
  description: Simple yet powerful wrapper around ffmpeg to get metadata from movies
26
26
  and do transcoding.
27
27
  email:
@@ -35,7 +35,7 @@ files:
35
35
  - lib/ffmpeg/transcoder.rb
36
36
  - lib/ffmpeg/version.rb
37
37
  - lib/streamio-ffmpeg.rb
38
- - README.rdoc
38
+ - README.md
39
39
  - LICENSE
40
40
  - CHANGELOG
41
41
  homepage: http://github.com/streamio/streamio-ffmpeg
@@ -52,7 +52,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
52
52
  version: '0'
53
53
  segments:
54
54
  - 0
55
- hash: 951887406957158189
55
+ hash: -1357797066708853074
56
56
  required_rubygems_version: !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  version: '0'
62
62
  segments:
63
63
  - 0
64
- hash: 951887406957158189
64
+ hash: -1357797066708853074
65
65
  requirements: []
66
66
  rubyforge_project:
67
67
  rubygems_version: 1.8.6
data/README.rdoc DELETED
@@ -1,107 +0,0 @@
1
- = Streamio FFMPEG
2
-
3
- Simple yet powerful wrapper around the ffmpeg command for reading metadata and transcoding movies.
4
-
5
- == Installation
6
-
7
- (sudo) gem install streamio-ffmpeg
8
-
9
- This version is tested against ffmpeg 0.8. So no guarantees with earlier (or much later) versions. Output and input standards have inconveniently changed rather a lot between versions of ffmpeg. My goal is to keep this library in sync with new versions of ffmpeg as they come along.
10
-
11
- == Usage
12
-
13
- === Require the gem
14
-
15
- require 'rubygems'
16
- require 'streamio-ffmpeg'
17
-
18
- === Reading Metadata
19
-
20
- movie = FFMPEG::Movie.new("path/to/movie.mov")
21
-
22
- movie.duration # 7.5 (duration of the movie in seconds)
23
- movie.bitrate # 481 (bitrate in kb/s)
24
- movie.size # 455546 (filesize in bytes)
25
-
26
- movie.video_stream # "h264, yuv420p, 640x480 [PAR 1:1 DAR 4:3], 371 kb/s, 16.75 fps, 15 tbr, 600 tbn, 1200 tbc" (raw video stream info)
27
- movie.video_codec # "h264"
28
- movie.colorspace # "yuv420p"
29
- movie.resolution # "640x480"
30
- movie.width # 640 (width of the movie in pixels)
31
- movie.height # 480 (height of the movie in pixels)
32
- movie.frame_rate # 16.72 (frames per second)
33
-
34
- movie.audio_stream # "aac, 44100 Hz, stereo, s16, 75 kb/s" (raw audio stream info)
35
- movie.audio_codec # "aac"
36
- movie.audio_sample_rate # 44100
37
- movie.audio_channels # 2
38
-
39
- movie.valid? # true (would be false if ffmpeg fails to read the movie)
40
-
41
- === Transcoding
42
-
43
- First argument is the output file path.
44
-
45
- movie.transcode("tmp/movie.mp4") # Default ffmpeg settings for mp4 format
46
-
47
- Keep track of progress with an optional block.
48
-
49
- movie.transcode(movie.mp4") { |progress| puts progress } # 0.2 ... 0.5 ... 1.0
50
-
51
- Give custom command line options with a string.
52
-
53
- movie.transcode("movie.mp4", "-ac aac -vc libx264 -ac 2 ...")
54
-
55
- Use the EncodingOptions parser for humanly readable transcoding options. Below you'll find most of the supported options. Note that the :custom key will be used as is without modification so use it for any tricky business you might need.
56
-
57
- options = {:video_codec => "libx264", :frame_rate => 10, :resolution => "320x240", :video_bitrate => 300, :video_bitrate_tolerance => 100,
58
- :croptop => 60, :cropbottom => 60, :cropleft => 10, :cropright => 10, :aspect => 1.333333,
59
- :audio_codec => "libfaac", :audio_bitrate => 32, :audio_sample_rate => 22050, :audio_channels => 1,
60
- :threads => 2,
61
- :custom => "-flags +loop -cmp +chroma -partitions +parti4x4+partp8x8 -flags2 +mixed_refs -me_method umh -subq 6 -refs 6 -rc_eq 'blurCplx^(1-qComp)' -coder 0 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 21"}
62
- movie.transcode("movie.mp4", options)
63
-
64
- The transcode function returns a Movie object for the encoded file.
65
-
66
- transcoded_movie = movie.transcode("tmp/movie.flv")
67
-
68
- transcoded_movie.video_codec # "flv"
69
- transcoded_movie.audio_codec # "mp3"
70
-
71
- Aspect ratio is added to encoding options automatically if none is specified.
72
-
73
- options = {:resolution => 320x180} # Will add -aspect 1.77777777777778 to ffmpeg
74
-
75
- Preserve aspect ratio on width or height by using the preserve_aspect_ratio transcoder option.
76
-
77
- widescreen_movie = FFMPEG::Movie.new("path/to/widescreen_movie.mov")
78
-
79
- options = {:resolution => 320x240}
80
-
81
- transcoder_options = {:preserve_aspect_ratio => :width}
82
- widescreen_movie.transcode("movie.mp4", options, transcoder_options) # Output resolution will be 320x180
83
-
84
- transcoder_options = {:preserve_aspect_ratio => :height}
85
- widescreen_movie.transcode("movie.mp4", options, transcoder_options) # Output resolution will be 426x240
86
-
87
- For constant bitrate encoding use video_min_bitrate and video_max_bitrate with buffer_size.
88
-
89
- options = {:video_min_bitrate => 600, :video_max_bitrate => 600, :buffer_size => 2000}
90
- movie.transcode("movie.flv", options)
91
-
92
- Use ffpreset files to avoid headaches when encoding with libx264 (http://www.ffmpeg.org/ffmpeg-doc.html#SEC13).
93
-
94
- options = {:video_codec => "libx264", :video_preset => "medium"} # audio_preset and file_preset also availible
95
- movie.transcode("movie.mp4", options) # encodes video using libx264-medium.ffpreset
96
-
97
- == Specify the path to ffmpeg
98
-
99
- By default, streamio assumes that the ffmpeg binary is available in the execution path and named ffmpeg and so will run commands that look something like "ffmpeg -i /path/to/input.file ...". Use the FFMPEG.ffmpeg_binary setter to specify the full path to the binary if necessary:
100
-
101
- FFMPEG.ffmpeg_binary = '/usr/local/bin/ffmpeg'
102
-
103
- This will cause the same command to run as "/usr/local/bin/ffmpeg -i /path/to/input.file ..." instead.
104
-
105
- == Copyright
106
-
107
- Copyright (c) 2010 Streamio Networks AB. See LICENSE for details.