streamio-ffmpeg 3.0.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +8 -1
- data/README.md +28 -15
- data/lib/ffmpeg/errors.rb +2 -0
- data/lib/ffmpeg/movie.rb +17 -7
- data/lib/ffmpeg/transcoder.rb +5 -2
- data/lib/ffmpeg/version.rb +1 -1
- data/lib/streamio-ffmpeg.rb +18 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d040320bc3f959563977e37be82de8c7dcc0b6dd
|
4
|
+
data.tar.gz: f3074b7953107d34c7560efc1be4ae5ab104341d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aedc131eef3f61197c5db195f8ed3f22dbd8dff133b47f8b3cdfc9c1c64640fee671cb087011e27a3d795e95d7764d431c6212ebcd763f0fa09c993a6de8bafe
|
7
|
+
data.tar.gz: 0ceaeb9d374541e9de8d1b70623632913ff69d60a39c8482fe7a28cc9a56be5bd983a7fa4414117045791355ebd7a2aa1a6bdf402a7b76b2571c0b068b31174c
|
data/CHANGELOG
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
== Master
|
2
2
|
|
3
|
-
Current with 3.0.
|
3
|
+
Current with 3.0.1
|
4
|
+
|
5
|
+
== 3.0.1 2016-11-10
|
6
|
+
|
7
|
+
Improvements:
|
8
|
+
* Issue #144 is fixed. Of a nil movie is presented to transcode, the progress block does not fail
|
9
|
+
* Issue #145 Adds ability to follow URLs when presented as Movie inputs
|
10
|
+
|
4
11
|
|
5
12
|
== 3.0.0 2016-09-07
|
6
13
|
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
Streamio FFMPEG
|
2
2
|
===============
|
3
3
|
|
4
|
+
[![Code Climate](https://codeclimate.com/github/streamio/streamio-ffmpeg/badges/gpa.svg)](https://codeclimate.com/github/streamio/streamio-ffmpeg)
|
5
|
+
|
4
6
|
Simple yet powerful wrapper around the ffmpeg command for reading metadata and transcoding movies.
|
5
7
|
|
6
8
|
All work on this project is sponsored by the online video platform [Streamio](http://streamio.com).
|
@@ -10,7 +12,7 @@ All work on this project is sponsored by the online video platform [Streamio](ht
|
|
10
12
|
Installation
|
11
13
|
------------
|
12
14
|
|
13
|
-
|
15
|
+
gem install streamio-ffmpeg
|
14
16
|
|
15
17
|
Compatibility
|
16
18
|
-------------
|
@@ -27,13 +29,14 @@ The current gem is tested against ffmpeg 2.8.4. So no guarantees with earlier (o
|
|
27
29
|
versions. Output and input standards have inconveniently changed rather a lot between versions
|
28
30
|
of ffmpeg. My goal is to keep this library in sync with new versions of ffmpeg as they come along.
|
29
31
|
|
32
|
+
On macOS: `brew install ffmpeg`.
|
33
|
+
|
30
34
|
Usage
|
31
35
|
-----
|
32
36
|
|
33
37
|
### Require the gem
|
34
38
|
|
35
39
|
``` ruby
|
36
|
-
require 'rubygems'
|
37
40
|
require 'streamio-ffmpeg'
|
38
41
|
```
|
39
42
|
|
@@ -79,7 +82,7 @@ movie.transcode("movie.mp4") { |progress| puts progress } # 0.2 ... 0.5 ... 1.0
|
|
79
82
|
Give custom command line options with an array.
|
80
83
|
|
81
84
|
``` ruby
|
82
|
-
movie.transcode("movie.mp4", %w(-ac aac -vc libx264 -ac 2 ...)
|
85
|
+
movie.transcode("movie.mp4", %w(-ac aac -vc libx264 -ac 2 ...))
|
83
86
|
```
|
84
87
|
|
85
88
|
Use the EncodingOptions parser for humanly readable transcoding options. Below you'll find most of the supported options.
|
@@ -87,12 +90,13 @@ Note that the :custom key is an array so that it can be used for FFMpeg options
|
|
87
90
|
`-map` that can be repeated:
|
88
91
|
|
89
92
|
``` ruby
|
90
|
-
options = {
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
93
|
+
options = {
|
94
|
+
video_codec: "libx264", frame_rate: 10, resolution: "320x240", video_bitrate: 300, video_bitrate_tolerance: 100,
|
95
|
+
aspect: 1.333333, keyframe_interval: 90, x264_vprofile: "high", x264_preset: "slow",
|
96
|
+
audio_codec: "libfaac", audio_bitrate: 32, audio_sample_rate: 22050, audio_channels: 1,
|
97
|
+
threads: 2, custom: %w(-vf crop=60:60:10:10 -map 0:0 -map 0:1)
|
98
|
+
}
|
99
|
+
|
96
100
|
movie.transcode("movie.mp4", options)
|
97
101
|
```
|
98
102
|
|
@@ -169,7 +173,10 @@ Add watermark image on the video.
|
|
169
173
|
For example, you want to add a watermark on the video at right top corner with 10px padding.
|
170
174
|
|
171
175
|
``` ruby
|
172
|
-
options = {
|
176
|
+
options = {
|
177
|
+
watermark: "full_path_of_watermark.png", resolution: "640x360",
|
178
|
+
watermark_filter: { position: "RT", padding_x: 10, padding_y: 10 }
|
179
|
+
}
|
173
180
|
```
|
174
181
|
|
175
182
|
Position can be "LT" (Left Top Corner), "RT" (Right Top Corner), "LB" (Left Bottom Corner), "RB" (Right Bottom Corner).
|
@@ -194,7 +201,7 @@ To generate multiple screenshots in a single pass, specify `vframes` and a wildc
|
|
194
201
|
sure to disable output file validation. The following code generates up to 20 screenshots every 10 seconds:
|
195
202
|
|
196
203
|
``` ruby
|
197
|
-
movie.screenshot("screenshot_%d.jpg", {vframes: 20, frame_rate: '1/6'}, validate: false)
|
204
|
+
movie.screenshot("screenshot_%d.jpg", { vframes: 20, frame_rate: '1/6' }, validate: false)
|
198
205
|
```
|
199
206
|
|
200
207
|
To specify the quality when generating compressed screenshots (.jpg), use `quality` which specifies
|
@@ -218,20 +225,27 @@ Since there is not movie to transcode, the Transcoder class needs to be used. Th
|
|
218
225
|
provided through transcoder options.
|
219
226
|
|
220
227
|
``` ruby
|
221
|
-
slideshow_transcoder = FFMPEG::Transcoder.new(
|
228
|
+
slideshow_transcoder = FFMPEG::Transcoder.new(
|
229
|
+
'',
|
230
|
+
'slideshow.mp4',
|
231
|
+
{ resolution: "320x240" },
|
232
|
+
input: 'img_%03d.jpeg',
|
233
|
+
input_options: { framerate: '1/5' }
|
234
|
+
)
|
235
|
+
|
222
236
|
slideshow = slideshow_transcoder.run
|
223
237
|
```
|
224
238
|
|
225
239
|
Specify the path to ffmpeg
|
226
240
|
--------------------------
|
227
241
|
|
228
|
-
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
|
242
|
+
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:
|
229
243
|
|
230
244
|
``` ruby
|
231
245
|
FFMPEG.ffmpeg_binary = '/usr/local/bin/ffmpeg'
|
232
246
|
```
|
233
247
|
|
234
|
-
This will cause the same command to run as
|
248
|
+
This will cause the same command to run as `/usr/local/bin/ffmpeg -i /path/to/input.file ...` instead.
|
235
249
|
|
236
250
|
|
237
251
|
Automatically kill hung processes
|
@@ -263,7 +277,6 @@ transcoder_options = { validate: false }
|
|
263
277
|
movie.transcode("movie.mp4", options, transcoder_options) # returns nil
|
264
278
|
```
|
265
279
|
|
266
|
-
|
267
280
|
Copyright
|
268
281
|
---------
|
269
282
|
|
data/lib/ffmpeg/errors.rb
CHANGED
data/lib/ffmpeg/movie.rb
CHANGED
@@ -17,7 +17,7 @@ module FFMPEG
|
|
17
17
|
|
18
18
|
if remote?
|
19
19
|
@head = head
|
20
|
-
raise Errno::ENOENT, "the URL '#{path}' does not exist"
|
20
|
+
raise Errno::ENOENT, "the URL '#{path}' does not exist" unless @head.is_a?(Net::HTTPSuccess)
|
21
21
|
else
|
22
22
|
raise Errno::ENOENT, "the file '#{path}' does not exist" unless File.exist?(path)
|
23
23
|
end
|
@@ -25,7 +25,7 @@ module FFMPEG
|
|
25
25
|
@path = path
|
26
26
|
|
27
27
|
# ffmpeg will output to stderr
|
28
|
-
command = [FFMPEG.ffprobe_binary, '-i', path,
|
28
|
+
command = [FFMPEG.ffprobe_binary, '-i', path, *%w(-print_format json -show_format -show_streams -show_error)]
|
29
29
|
std_output = ''
|
30
30
|
std_error = ''
|
31
31
|
|
@@ -132,7 +132,7 @@ module FFMPEG
|
|
132
132
|
end
|
133
133
|
|
134
134
|
def remote?
|
135
|
-
@path =~ URI::regexp
|
135
|
+
@path =~ URI::regexp(%w(http https))
|
136
136
|
end
|
137
137
|
|
138
138
|
def local?
|
@@ -217,14 +217,24 @@ module FFMPEG
|
|
217
217
|
output.force_encoding("ISO-8859-1")
|
218
218
|
end
|
219
219
|
|
220
|
-
def head
|
221
|
-
url = URI(
|
220
|
+
def head(location=@path, limit=FFMPEG.max_http_redirect_attempts)
|
221
|
+
url = URI(location)
|
222
222
|
return unless url.path
|
223
223
|
|
224
224
|
http = Net::HTTP.new(url.host, url.port)
|
225
225
|
http.use_ssl = url.port == 443
|
226
|
-
http.request_head(url.
|
227
|
-
|
226
|
+
response = http.request_head(url.request_uri)
|
227
|
+
|
228
|
+
case response
|
229
|
+
when Net::HTTPRedirection then
|
230
|
+
raise FFMPEG::HTTPTooManyRequests if limit == 0
|
231
|
+
new_uri = url + URI(response['Location'])
|
232
|
+
|
233
|
+
head(new_uri, limit - 1)
|
234
|
+
else
|
235
|
+
response
|
236
|
+
end
|
237
|
+
rescue SocketError, Errno::ECONNREFUSED => e
|
228
238
|
nil
|
229
239
|
end
|
230
240
|
end
|
data/lib/ffmpeg/transcoder.rb
CHANGED
@@ -81,8 +81,11 @@ module FFMPEG
|
|
81
81
|
else # better make sure it wont blow up in case of unexpected output
|
82
82
|
time = 0.0
|
83
83
|
end
|
84
|
-
|
85
|
-
|
84
|
+
|
85
|
+
if @movie
|
86
|
+
progress = time / @movie.duration
|
87
|
+
yield(progress) if block_given?
|
88
|
+
end
|
86
89
|
end
|
87
90
|
end
|
88
91
|
|
data/lib/ffmpeg/version.rb
CHANGED
data/lib/streamio-ffmpeg.rb
CHANGED
@@ -72,6 +72,24 @@ module FFMPEG
|
|
72
72
|
@ffprobe_binary = bin
|
73
73
|
end
|
74
74
|
|
75
|
+
# Get the maximum number of http redirect attempts
|
76
|
+
#
|
77
|
+
# @return [Integer] the maximum number of retries
|
78
|
+
def self.max_http_redirect_attempts
|
79
|
+
@max_http_redirect_attempts.nil? ? 10 : @max_http_redirect_attempts
|
80
|
+
end
|
81
|
+
|
82
|
+
# Set the maximum number of http redirect attempts.
|
83
|
+
#
|
84
|
+
# @param [Integer] the maximum number of retries
|
85
|
+
# @return [Integer] the number of retries you set
|
86
|
+
# @raise Errno::ENOENT if the value is negative or not an Integer
|
87
|
+
def self.max_http_redirect_attempts=(v)
|
88
|
+
raise Errno::ENOENT, 'max_http_redirect_attempts must be an integer' if v && !v.is_a?(Integer)
|
89
|
+
raise Errno::ENOENT, 'max_http_redirect_attempts may not be negative' if v && v < 0
|
90
|
+
@max_http_redirect_attempts = v
|
91
|
+
end
|
92
|
+
|
75
93
|
# Cross-platform way of finding an executable in the $PATH.
|
76
94
|
#
|
77
95
|
# which('ruby') #=> /usr/bin/ruby
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: streamio-ffmpeg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rackfish AB
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|