d-streamio-ffmpeg 3.0.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.
- checksums.yaml +7 -0
- data/CHANGELOG +263 -0
- data/LICENSE +20 -0
- data/README.md +286 -0
- data/lib/ffmpeg/encoding_options.rb +200 -0
- data/lib/ffmpeg/errors.rb +6 -0
- data/lib/ffmpeg/io_monkey.rb +42 -0
- data/lib/ffmpeg/movie.rb +257 -0
- data/lib/ffmpeg/transcoder.rb +141 -0
- data/lib/ffmpeg/version.rb +3 -0
- data/lib/streamio-ffmpeg.rb +108 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5a981303075790fd07460a42f62b562b6e05f59dd377a34252ce90d3e55ef3bb
|
4
|
+
data.tar.gz: 5610658999c6811facecc0c8e5288dcbda6d31813b83d80cead6afddbb571183
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1752b2bf0e09e9695d47b1c0aab552e4c93d45f5b2ca190b11bfe62f815f2cf8e56aa46bfd3f41ed112e5401b08a8d26ca9ef9fcb6b17a84c7ca552192abbf03
|
7
|
+
data.tar.gz: 8ac71feee27b6a73162af2dfdfb6674f7fbd5a9cb56c84ed648b31690e60be9126675c3a6ba255067d8d01cd29763f47b565c5e3438ed2fcf1a58e593a0d9e68
|
data/CHANGELOG
ADDED
@@ -0,0 +1,263 @@
|
|
1
|
+
== Master
|
2
|
+
|
3
|
+
Current with 3.0.2
|
4
|
+
|
5
|
+
== 3.0.2 2016-11-18
|
6
|
+
|
7
|
+
Improvements:
|
8
|
+
* Issue #153 Adds support for multiple audio streams
|
9
|
+
* Issue #150 Does not trust reported SAR/DAR as these may not be defined per https://trac.ffmpeg.org/ticket/3798
|
10
|
+
|
11
|
+
== 3.0.1 2016-11-10
|
12
|
+
|
13
|
+
Improvements:
|
14
|
+
* Issue #144 is fixed. Of a nil movie is presented to transcode, the progress block does not fail
|
15
|
+
* Issue #145 Adds ability to follow URLs when presented as Movie inputs
|
16
|
+
|
17
|
+
|
18
|
+
== 3.0.0 2016-09-07
|
19
|
+
|
20
|
+
Breaking Changes:
|
21
|
+
* Changes: custom parameters now specified using an array syntax
|
22
|
+
|
23
|
+
Improvements:
|
24
|
+
* Issue # 128, #137 are fixed (custom parameters passed as strings) which was caused
|
25
|
+
by 2.1.0 in attempting to avoid the use of shell and filename escaping issues
|
26
|
+
on various platforms.
|
27
|
+
|
28
|
+
|
29
|
+
== 2.1.0 2016-08-08
|
30
|
+
|
31
|
+
New:
|
32
|
+
* Issue #135, Support creating slideshows from stills
|
33
|
+
* Issue #130, Adds support for a URL as an input
|
34
|
+
* Support for specifying options to apply to the input file
|
35
|
+
* Improved support for calling FFMpeg with popen3, improving compatibility with various platforms, including windows
|
36
|
+
* Issue #111. uses attr_accessor for the timeout attribute
|
37
|
+
* Exposes the movie's entire meta data and format tags as movie attributes
|
38
|
+
* Issue #122, adds encoding fix to stderr
|
39
|
+
* All specs pass and brought current with Rspec V3
|
40
|
+
* Issue #123, #131 improved stream validation, ignoring additional invalid streams if a valid stream is recognized
|
41
|
+
* Issue #124, improved parsing for moving creation_time
|
42
|
+
* SAR and DAR now adapt after rotation, DAR is ignored when calculating dimensions
|
43
|
+
|
44
|
+
Improvements:
|
45
|
+
* Allow parenthesis in colorspace (thanks walterdavis for initial code and rociiu for finding a bug with it)
|
46
|
+
* Width and height now switched if video is filmed in portrait mode. ffmpeg 2.7 or later now automatically rotates output
|
47
|
+
* Movie metadata now provided with ffprobe (#114). Thanks to Ryan Lovelett for the contributions!
|
48
|
+
* Ability to create multiple screenshots at consistent intervals in one pass (#113)
|
49
|
+
|
50
|
+
== 2.0.0 2016-01-14
|
51
|
+
|
52
|
+
New:
|
53
|
+
* Support watermarking (thanks smoothdvd)
|
54
|
+
* Bumped target ffmpeg version to 2.8
|
55
|
+
|
56
|
+
Improvements:
|
57
|
+
* Allow parenthesis in colorspace (thanks walterdavis for initial code and rociiu for finding a bug with it)
|
58
|
+
* Width and height now switched if video is filmed in portrait mode. ffmpeg 2.7 or later now automatically rotates output
|
59
|
+
* Movie metadata now provided with ffprobe (#114). Thanks to Ryan Lovelett for the contributions!
|
60
|
+
* Ability to create multiple screenshots at consistent intervals in one pass (#113)
|
61
|
+
|
62
|
+
== 1.0.0 2013-07-08
|
63
|
+
|
64
|
+
New:
|
65
|
+
* Bumped target ffmpeg version to 1.2.1
|
66
|
+
|
67
|
+
Improvements:
|
68
|
+
* Simpler implementation for timeouts.
|
69
|
+
Should be far less cpu and memory dependent (don't spawn a thread for every line of output)
|
70
|
+
Timeout spec now passes in Rubinius (using 1.9 mode)
|
71
|
+
* Give helpful error message for windows users lacking the win32-process gem (thanks casoetan)
|
72
|
+
* Add Movie#container (thanks vitalis)
|
73
|
+
* Support vprofile and preset encoding options (thanks vitalis)
|
74
|
+
|
75
|
+
Changes:
|
76
|
+
* Default timeout lowered to 30 seconds
|
77
|
+
|
78
|
+
Bugs:
|
79
|
+
* Avoid crash if asking for frame_rate of a video without video stream (thanks squidarth)
|
80
|
+
* Fix crash when doing audio transcoding on ffmpeg >= 1.0.1 (thanks vitalis)
|
81
|
+
|
82
|
+
Deprecations:
|
83
|
+
* Removed support for Ruby 1.8
|
84
|
+
* Removed support for ffmpeg 0.7
|
85
|
+
|
86
|
+
Refactorings:
|
87
|
+
* Quite a few, see commit history for details.
|
88
|
+
|
89
|
+
== 0.9.0 2012-07-24
|
90
|
+
|
91
|
+
New:
|
92
|
+
* Bumped target ffmpeg version to 0.11.1
|
93
|
+
* Add hung process detection with configurable timeout (thanks stakach)
|
94
|
+
* Raise FFMPEG::Error instead of generic RuntimeError on failed transcodings
|
95
|
+
* Movie#screenshot for more intuitive screenshotting (README has details)
|
96
|
+
* Movie#creation_time and Movie#rotation attributes when metadata is available (thanks Innonate)
|
97
|
+
|
98
|
+
Bugs:
|
99
|
+
* Fixed too many open files bug (thanks to akicho8)
|
100
|
+
* Fixed missing path escaping (thanks to mikesager)
|
101
|
+
* Fixed README typo (thanks to Linutux)
|
102
|
+
* Files outputing "could not find codec parameters" are now recognized as invalid
|
103
|
+
|
104
|
+
Deprecations:
|
105
|
+
* Removed Movie#uncertain_duration?
|
106
|
+
* Removed all the deprecated crop options (use :custom => '-vf crop=x:x:x:x' if you need it)
|
107
|
+
|
108
|
+
Refactorings:
|
109
|
+
* Removed the deprecated duration validation code
|
110
|
+
* Polish on the transcoder class
|
111
|
+
* Polish on the spec suite
|
112
|
+
|
113
|
+
== 0.8.5 2011-03-05
|
114
|
+
|
115
|
+
* If a clip has a DAR that doesn't make sense fall back to calculating aspect ratio from dimensions
|
116
|
+
* Allow filenames with single quote characters (thanks to youpy)
|
117
|
+
|
118
|
+
== 0.8.4 2011-11-30
|
119
|
+
|
120
|
+
* Duration now one decimal more accurate (thanks to Russel Brooks)
|
121
|
+
* Added encoding option seek_time (thanks to Misty De Meo)
|
122
|
+
|
123
|
+
== 0.8.3 2011-09-01
|
124
|
+
|
125
|
+
* Parameters now come in the order of codecs, presets, others so that we can override the presets
|
126
|
+
* Added encoding option keyframe_interval to set number of frames between i-frames (aka GOP size)
|
127
|
+
* Streamio (sponsor of this project) have launched new awesome pricing @ http://streamio.com
|
128
|
+
|
129
|
+
== 0.8.2 2011-08-19
|
130
|
+
|
131
|
+
* Path to ffmpeg binary can now be specified (thanks jonathandean)
|
132
|
+
* If ffmpeg output contains "is not supported" the Movie will be considered invalid
|
133
|
+
|
134
|
+
== 0.8.1 2011-07-28
|
135
|
+
|
136
|
+
* Fix progress yielding with ffmpeg 0.8
|
137
|
+
* Updated specs to pass with ffmpeg 0.8
|
138
|
+
|
139
|
+
== 0.8.0 2011-05-26
|
140
|
+
|
141
|
+
* Duration is now ALWAYS considered uncertain (we've noticed that ffmpeg is not always correct)
|
142
|
+
* This means that the duration check will normally never run (unless you manually hack @uncertain_duration to false)
|
143
|
+
* Movie#audio_channels now returns nil if there is no audio stream (instead of crashing)
|
144
|
+
* Development: Use Bundler
|
145
|
+
* Development: Update RSpec to 2.6
|
146
|
+
|
147
|
+
== 0.7.8 2011-04-04
|
148
|
+
|
149
|
+
* Fixed number of audio channels on files with 5.1 audio
|
150
|
+
|
151
|
+
== 0.7.7 2011-02-01
|
152
|
+
|
153
|
+
* Movies with starttime are now considered as having uncertain duration as its behavior is not consistent across formats
|
154
|
+
* Upgrade development environment to RSpec 2.4
|
155
|
+
|
156
|
+
== 0.7.6 2011-01-14
|
157
|
+
|
158
|
+
* Another ruby 1.9 encoding fix
|
159
|
+
|
160
|
+
== 0.7.5 2011-01-14
|
161
|
+
|
162
|
+
* Fixed some ruby 1.9 issues
|
163
|
+
* Added Movie#video_bitrate and Movie#audio_bitrate (thanks to mbj)
|
164
|
+
|
165
|
+
== 0.7.4 2010-12-07
|
166
|
+
|
167
|
+
* Fixed broken duration on movies with start times over 0 by reducing duration with start-time
|
168
|
+
|
169
|
+
== 0.7.3 2010-08-26
|
170
|
+
|
171
|
+
* Replaced Jewler with simple dynamic gemspec file
|
172
|
+
* Spec files now not in published gem to make it a lot smaller in size
|
173
|
+
* Full output from ffmpeg command in error raised during transcoding
|
174
|
+
|
175
|
+
== 0.7.2 2010-08-11
|
176
|
+
|
177
|
+
* Added encoding option duration
|
178
|
+
* Avoid crashing when ffmpeg can't find resolution of a movie
|
179
|
+
|
180
|
+
== 0.7.1 2010-07-08
|
181
|
+
|
182
|
+
* Make sure preset parameters are always put last to avoid them ending up before any codec assignments
|
183
|
+
* Testing against a fresh ffmpeg build (r24069)
|
184
|
+
|
185
|
+
== 0.7.0 2010-07-07
|
186
|
+
|
187
|
+
* Support for ffpresets through video_preset, audio_preset and file_preset encoding options
|
188
|
+
* Added encoding option video_bitrate_tolerance
|
189
|
+
|
190
|
+
== 0.6.8.1 2010-07-06
|
191
|
+
|
192
|
+
* Bugfix - aspect ratio was not calculated properly on movies with no DAR
|
193
|
+
|
194
|
+
== 0.6.8 2010-07-06
|
195
|
+
|
196
|
+
* Don't use encoding options with nil values
|
197
|
+
* Added encoding options video_max_bitrate, video_min_bitrate and buffer_size for constant bitrate encoding
|
198
|
+
|
199
|
+
== 0.6.7 2010-06-10
|
200
|
+
|
201
|
+
* Bugfix - aspect ratio preserver could suggest non even resolutions in certain circumstances
|
202
|
+
|
203
|
+
== 0.6.6 2010-06-10
|
204
|
+
|
205
|
+
* Transcodings to .jpg and .png will now work as they will skip duration validation
|
206
|
+
|
207
|
+
== 0.6.5 2010-05-19
|
208
|
+
|
209
|
+
* Movie#size method to get file size.
|
210
|
+
|
211
|
+
== 0.6.4 2010-05-12
|
212
|
+
|
213
|
+
* Ruby 1.9 compatibility fix for EncodingOptions (thanks michalf!)
|
214
|
+
|
215
|
+
== 0.6.3 2010-05-05
|
216
|
+
|
217
|
+
* Use DAR to calculate aspect ratio if available
|
218
|
+
|
219
|
+
== 0.6.2 2010-05-05
|
220
|
+
|
221
|
+
* Added Movie#uncertain_duration? which is true if ffmpeg is guessing duration from bitrate
|
222
|
+
* Skipping the transcoders duration validation if original file has uncertain duration
|
223
|
+
* Made sure aspect ratio preservation always rounds new size to an even number to avoid "not divisible by 2" errors
|
224
|
+
* Changed Movie#valid? logic to accept any movie with either a readable audio or video stream
|
225
|
+
|
226
|
+
== 0.6.0 2010-05-04
|
227
|
+
|
228
|
+
* Cropping options now handled by EncodingOptions (croptop, cropbottom, cropleft and cropright)
|
229
|
+
* Aspect ratio parameter calculated and added by default
|
230
|
+
* Added transcoder options to preserve original aspect ratio on width or height
|
231
|
+
|
232
|
+
== 0.5.0 2010-04-28
|
233
|
+
|
234
|
+
* Added logging capabilities
|
235
|
+
|
236
|
+
== 0.4.3 2010-04-06
|
237
|
+
|
238
|
+
* Correctly identify invalid movies on latest ffmpeg build (r22811)
|
239
|
+
|
240
|
+
== 0.4.2 2010-04-06
|
241
|
+
|
242
|
+
* Escape the path to handle spaces in filenames and avoid CLI injection attacks (thanks J. Weir!)
|
243
|
+
|
244
|
+
== 0.4.1 2010-02-10
|
245
|
+
|
246
|
+
* Forgot to change the transcoding shortcut from Movie
|
247
|
+
|
248
|
+
== 0.4.0 2010-02-10
|
249
|
+
|
250
|
+
* Transcoding API changed to make use of more humanly readable options (see README for examples)
|
251
|
+
* Fixed frame rate parsing for integer frame rates
|
252
|
+
|
253
|
+
== 0.3.0 2010-02-07
|
254
|
+
|
255
|
+
* Simple transcoding
|
256
|
+
|
257
|
+
== 0.2.0 2010-02-06
|
258
|
+
|
259
|
+
* Some more metadata parsing
|
260
|
+
|
261
|
+
== 0.1.0 2010-02-05
|
262
|
+
|
263
|
+
* Some basic parsing of metadata added
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Streamio AB
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,286 @@
|
|
1
|
+
Streamio FFMPEG
|
2
|
+
===============
|
3
|
+
|
4
|
+
[](https://codeclimate.com/github/streamio/streamio-ffmpeg)
|
5
|
+
|
6
|
+
Simple yet powerful wrapper around the ffmpeg command for reading metadata and transcoding movies.
|
7
|
+
|
8
|
+
All work on this project is sponsored by the online video platform [Streamio](http://streamio.com).
|
9
|
+
|
10
|
+
[](http://streamio.com)
|
11
|
+
|
12
|
+
Installation
|
13
|
+
------------
|
14
|
+
|
15
|
+
gem install streamio-ffmpeg
|
16
|
+
|
17
|
+
Compatibility
|
18
|
+
-------------
|
19
|
+
|
20
|
+
### Ruby
|
21
|
+
|
22
|
+
Only guaranteed to work with MRI Ruby 1.9.3 or later.
|
23
|
+
Should work with rubinius head in 1.9 mode.
|
24
|
+
Will not work in jruby until they fix: http://goo.gl/Z4UcX (should work in the upcoming 1.7.5)
|
25
|
+
|
26
|
+
### ffmpeg
|
27
|
+
|
28
|
+
The current gem is tested against ffmpeg 2.8.4. So no guarantees with earlier (or much later)
|
29
|
+
versions. Output and input standards have inconveniently changed rather a lot between versions
|
30
|
+
of ffmpeg. My goal is to keep this library in sync with new versions of ffmpeg as they come along.
|
31
|
+
|
32
|
+
On macOS: `brew install ffmpeg`.
|
33
|
+
|
34
|
+
Usage
|
35
|
+
-----
|
36
|
+
|
37
|
+
### Require the gem
|
38
|
+
|
39
|
+
``` ruby
|
40
|
+
require 'streamio-ffmpeg'
|
41
|
+
```
|
42
|
+
|
43
|
+
### Reading Metadata
|
44
|
+
|
45
|
+
``` ruby
|
46
|
+
movie = FFMPEG::Movie.new("path/to/movie.mov")
|
47
|
+
|
48
|
+
movie.duration # 7.5 (duration of the movie in seconds)
|
49
|
+
movie.bitrate # 481 (bitrate in kb/s)
|
50
|
+
movie.size # 455546 (filesize in bytes)
|
51
|
+
|
52
|
+
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)
|
53
|
+
movie.video_codec # "h264"
|
54
|
+
movie.colorspace # "yuv420p"
|
55
|
+
movie.resolution # "640x480"
|
56
|
+
movie.width # 640 (width of the movie in pixels)
|
57
|
+
movie.height # 480 (height of the movie in pixels)
|
58
|
+
movie.frame_rate # 16.72 (frames per second)
|
59
|
+
|
60
|
+
movie.audio_stream # "aac, 44100 Hz, stereo, s16, 75 kb/s" (raw audio stream info)
|
61
|
+
movie.audio_codec # "aac"
|
62
|
+
movie.audio_sample_rate # 44100
|
63
|
+
movie.audio_channels # 2
|
64
|
+
|
65
|
+
# Multiple audio streams
|
66
|
+
movie.audio_streams[0] # "aac, 44100 Hz, stereo, s16, 75 kb/s" (raw audio stream info)
|
67
|
+
|
68
|
+
movie.valid? # true (would be false if ffmpeg fails to read the movie)
|
69
|
+
```
|
70
|
+
|
71
|
+
### Transcoding
|
72
|
+
|
73
|
+
First argument is the output file path.
|
74
|
+
|
75
|
+
``` ruby
|
76
|
+
movie.transcode("tmp/movie.mp4") # Default ffmpeg settings for mp4 format
|
77
|
+
```
|
78
|
+
|
79
|
+
Keep track of progress with an optional block.
|
80
|
+
|
81
|
+
``` ruby
|
82
|
+
movie.transcode("movie.mp4") { |progress| puts progress } # 0.2 ... 0.5 ... 1.0
|
83
|
+
```
|
84
|
+
|
85
|
+
Give custom command line options with an array.
|
86
|
+
|
87
|
+
``` ruby
|
88
|
+
movie.transcode("movie.mp4", %w(-ac aac -vc libx264 -ac 2 ...))
|
89
|
+
```
|
90
|
+
|
91
|
+
Use the EncodingOptions parser for humanly readable transcoding options. Below you'll find most of the supported options.
|
92
|
+
Note that the :custom key is an array so that it can be used for FFMpeg options like
|
93
|
+
`-map` that can be repeated:
|
94
|
+
|
95
|
+
``` ruby
|
96
|
+
options = {
|
97
|
+
video_codec: "libx264", frame_rate: 10, resolution: "320x240", video_bitrate: 300, video_bitrate_tolerance: 100,
|
98
|
+
aspect: 1.333333, keyframe_interval: 90, x264_vprofile: "high", x264_preset: "slow",
|
99
|
+
audio_codec: "libfaac", audio_bitrate: 32, audio_sample_rate: 22050, audio_channels: 1,
|
100
|
+
threads: 2, custom: %w(-vf crop=60:60:10:10 -map 0:0 -map 0:1)
|
101
|
+
}
|
102
|
+
|
103
|
+
movie.transcode("movie.mp4", options)
|
104
|
+
```
|
105
|
+
|
106
|
+
The transcode function returns a Movie object for the encoded file.
|
107
|
+
|
108
|
+
``` ruby
|
109
|
+
transcoded_movie = movie.transcode("tmp/movie.flv")
|
110
|
+
|
111
|
+
transcoded_movie.video_codec # "flv"
|
112
|
+
transcoded_movie.audio_codec # "mp3"
|
113
|
+
```
|
114
|
+
|
115
|
+
Aspect ratio is added to encoding options automatically if none is specified.
|
116
|
+
|
117
|
+
``` ruby
|
118
|
+
options = { resolution: "320x180" } # Will add -aspect 1.77777777777778 to ffmpeg
|
119
|
+
```
|
120
|
+
|
121
|
+
Preserve aspect ratio on width or height by using the preserve_aspect_ratio transcoder option.
|
122
|
+
|
123
|
+
``` ruby
|
124
|
+
widescreen_movie = FFMPEG::Movie.new("path/to/widescreen_movie.mov")
|
125
|
+
|
126
|
+
options = { resolution: "320x240" }
|
127
|
+
|
128
|
+
transcoder_options = { preserve_aspect_ratio: :width }
|
129
|
+
widescreen_movie.transcode("movie.mp4", options, transcoder_options) # Output resolution will be 320x180
|
130
|
+
|
131
|
+
transcoder_options = { preserve_aspect_ratio: :height }
|
132
|
+
widescreen_movie.transcode("movie.mp4", options, transcoder_options) # Output resolution will be 426x240
|
133
|
+
```
|
134
|
+
|
135
|
+
For constant bitrate encoding use video_min_bitrate and video_max_bitrate with buffer_size.
|
136
|
+
|
137
|
+
``` ruby
|
138
|
+
options = {video_min_bitrate: 600, video_max_bitrate: 600, buffer_size: 2000}
|
139
|
+
movie.transcode("movie.flv", options)
|
140
|
+
```
|
141
|
+
|
142
|
+
### Specifying Input Options
|
143
|
+
|
144
|
+
To specify which options apply the input, such as changing the input framerate, use `input_options` hash
|
145
|
+
in the transcoder_options.
|
146
|
+
|
147
|
+
``` ruby
|
148
|
+
movie = FFMPEG::Movie.new("path/to/movie.mov")
|
149
|
+
|
150
|
+
transcoder_options = { input_options: { framerate: '1/5' } }
|
151
|
+
movie.transcode("movie.mp4", {}, transcoder_options)
|
152
|
+
|
153
|
+
# FFMPEG Command will look like this:
|
154
|
+
# ffmpeg -y -framerate 1/5 -i path/to/movie.mov movie.mp4
|
155
|
+
```
|
156
|
+
|
157
|
+
### Overriding the Input Path
|
158
|
+
|
159
|
+
If FFMPEG's input path needs to specify a sequence of files, rather than a path to a single movie, transcoding_options
|
160
|
+
`input` can be set. If this option is present, the path of the original movie will not be used.
|
161
|
+
|
162
|
+
``` ruby
|
163
|
+
movie = FFMPEG::Movie.new("path/to/movie.mov")
|
164
|
+
|
165
|
+
transcoder_options = { input: 'img_%03d.png' }
|
166
|
+
movie.transcode("movie.mp4", {}, transcoder_options)
|
167
|
+
|
168
|
+
# FFMPEG Command will look like this:
|
169
|
+
# ffmpeg -y -i img_%03d.png movie.mp4
|
170
|
+
```
|
171
|
+
|
172
|
+
### Watermarking
|
173
|
+
|
174
|
+
Add watermark image on the video.
|
175
|
+
|
176
|
+
For example, you want to add a watermark on the video at right top corner with 10px padding.
|
177
|
+
|
178
|
+
``` ruby
|
179
|
+
options = {
|
180
|
+
watermark: "full_path_of_watermark.png", resolution: "640x360",
|
181
|
+
watermark_filter: { position: "RT", padding_x: 10, padding_y: 10 }
|
182
|
+
}
|
183
|
+
```
|
184
|
+
|
185
|
+
Position can be "LT" (Left Top Corner), "RT" (Right Top Corner), "LB" (Left Bottom Corner), "RB" (Right Bottom Corner).
|
186
|
+
The watermark will not appear unless `watermark_options` specifies the position. `padding_x` and `padding_y` default to
|
187
|
+
`10`.
|
188
|
+
|
189
|
+
### Taking Screenshots
|
190
|
+
|
191
|
+
You can use the screenshot method to make taking screenshots a bit simpler.
|
192
|
+
|
193
|
+
``` ruby
|
194
|
+
movie.screenshot("screenshot.jpg")
|
195
|
+
```
|
196
|
+
|
197
|
+
The screenshot method has the very same API as transcode so the same options will work.
|
198
|
+
|
199
|
+
``` ruby
|
200
|
+
movie.screenshot("screenshot.bmp", seek_time: 5, resolution: '320x240')
|
201
|
+
```
|
202
|
+
|
203
|
+
To generate multiple screenshots in a single pass, specify `vframes` and a wildcard filename. Make
|
204
|
+
sure to disable output file validation. The following code generates up to 20 screenshots every 10 seconds:
|
205
|
+
|
206
|
+
``` ruby
|
207
|
+
movie.screenshot("screenshot_%d.jpg", { vframes: 20, frame_rate: '1/6' }, validate: false)
|
208
|
+
```
|
209
|
+
|
210
|
+
To specify the quality when generating compressed screenshots (.jpg), use `quality` which specifies
|
211
|
+
ffmpeg `-v:q` option. Quality is an integer between 1 and 31, where lower is better quality:
|
212
|
+
|
213
|
+
``` ruby
|
214
|
+
movie.screenshot("screenshot_%d.jpg", quality: 3)
|
215
|
+
```
|
216
|
+
|
217
|
+
You can preserve aspect ratio the same way as when using transcode.
|
218
|
+
|
219
|
+
``` ruby
|
220
|
+
movie.screenshot("screenshot.png", { seek_time: 2, resolution: '200x120' }, preserve_aspect_ratio: :width)
|
221
|
+
```
|
222
|
+
|
223
|
+
### Create a Slideshow from Stills
|
224
|
+
Creating a slideshow from stills uses named sequences of files and stiches the result together in a slideshow
|
225
|
+
video.
|
226
|
+
|
227
|
+
Since there is not movie to transcode, the Transcoder class needs to be used. The input and input_options are
|
228
|
+
provided through transcoder options.
|
229
|
+
|
230
|
+
``` ruby
|
231
|
+
slideshow_transcoder = FFMPEG::Transcoder.new(
|
232
|
+
'',
|
233
|
+
'slideshow.mp4',
|
234
|
+
{ resolution: "320x240" },
|
235
|
+
input: 'img_%03d.jpeg',
|
236
|
+
input_options: { framerate: '1/5' }
|
237
|
+
)
|
238
|
+
|
239
|
+
slideshow = slideshow_transcoder.run
|
240
|
+
```
|
241
|
+
|
242
|
+
Specify the path to ffmpeg
|
243
|
+
--------------------------
|
244
|
+
|
245
|
+
By default, the gem 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:
|
246
|
+
|
247
|
+
``` ruby
|
248
|
+
FFMPEG.ffmpeg_binary = '/usr/local/bin/ffmpeg'
|
249
|
+
```
|
250
|
+
|
251
|
+
This will cause the same command to run as `/usr/local/bin/ffmpeg -i /path/to/input.file ...` instead.
|
252
|
+
|
253
|
+
|
254
|
+
Automatically kill hung processes
|
255
|
+
---------------------------------
|
256
|
+
|
257
|
+
By default, the gem will wait for 30 seconds between IO feedback from the FFMPEG process. After which an error is logged and the process killed.
|
258
|
+
It is possible to modify this behaviour by setting a new default:
|
259
|
+
|
260
|
+
``` ruby
|
261
|
+
# Change the timeout
|
262
|
+
Transcoder.timeout = 10
|
263
|
+
|
264
|
+
# Disable the timeout altogether
|
265
|
+
Transcoder.timeout = false
|
266
|
+
```
|
267
|
+
|
268
|
+
Disabling output file validation
|
269
|
+
------------------------------
|
270
|
+
|
271
|
+
By default Transcoder validates the output file, in case you use FFMPEG for HLS
|
272
|
+
format that creates multiple outputs you can disable the validation by passing
|
273
|
+
`validate: false` to transcoder_options.
|
274
|
+
|
275
|
+
Note that transcode will not return the encoded movie object in this case since
|
276
|
+
attempting to open a (possibly) invalid output file might result in an error being raised.
|
277
|
+
|
278
|
+
```ruby
|
279
|
+
transcoder_options = { validate: false }
|
280
|
+
movie.transcode("movie.mp4", options, transcoder_options) # returns nil
|
281
|
+
```
|
282
|
+
|
283
|
+
Copyright
|
284
|
+
---------
|
285
|
+
|
286
|
+
Copyright (c) Streamio AB. See LICENSE for details.
|