Skip to content
This repository was archived by the owner on Jan 28, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
a50da5f
Updated gemspec
invalid-email-address Oct 27, 2015
9267eee
Minor adaptions to FFMpeg 2.8 (handles rotated media)
invalid-email-address Oct 27, 2015
4feea03
whitespace
Oct 27, 2015
a8ebb3a
Updated changelog
Oct 27, 2015
219848b
Updated changelog
Oct 27, 2015
6dd86e8
Prioritize watermark-related parameters to work with ffmpeg 2.8
rackfishdaniel Nov 9, 2015
6aad983
edit depracated File.exists? to File.exist?
Oct 27, 2014
95f01da
add _ before unused block arguments
Oct 27, 2014
0a12003
Merges PR #89 from geh4y8, resolving deprecations and coding standard…
bikeath1337 Jan 7, 2016
50b3327
Ignore RubyMine files
RLovelett Feb 4, 2014
0d0a8bc
Refactor specs and code to be compatible with ffmpeg 2.6.2
RLovelett May 5, 2015
9f81c73
Create a FFMPEG.ffprobe_binary static method
RLovelett Feb 4, 2014
68dc2ad
Refactor FFMPEG.ffmpeg_binary to raise exceptions
RLovelett Feb 4, 2014
153e278
Re-implement FFMPEG::Movie and use ffprobe
RLovelett Feb 4, 2014
f43fe14
Provide ffprobe JSON output for RSpec fixtures
RLovelett Feb 4, 2014
08e920e
ffprobe does not encounter these complexities
RLovelett Feb 4, 2014
333b3a0
Refactor specs to handle change in units
RLovelett Feb 4, 2014
315bdf4
Use JSON agnostic processor MultiJson
RLovelett Feb 5, 2014
72544ff
Restores specs broken by removing the attr_readers, thus breaking the…
bikeath1337 Jan 12, 2016
b8aee35
Applies rlovelett's enhancements to use ffprobe for metadata, less ch…
bikeath1337 Jan 12, 2016
fb4cb05
Corrects Rspec deprecations
bikeath1337 Sep 6, 2015
591942c
Adds ability to set -vframes option when creating screenshots. Speeds…
bikeath1337 Sep 6, 2015
d83b4d1
Adds ability to set compressed image quality for screenshots
bikeath1337 Sep 7, 2015
9357e3d
Replaces GLC license libfaac reference to prebuilt libmp3lame
bikeath1337 Sep 9, 2015
3620504
Adds ability to support -target encoding_option
bikeath1337 Sep 9, 2015
9949cb0
Fixes broken spec “MPEG1/2 does not support 15/1 fps”
bikeath1337 Sep 9, 2015
f2d116b
Checks for support of ISO-8859-1 characters
bikeath1337 Sep 9, 2015
991199a
Updates audio spec to fail on timeout. Why should it not fail?
bikeath1337 Sep 9, 2015
2243bb6
Improves specs and support for -vframes
bikeath1337 Sep 9, 2015
5873a6c
Corrects deprecations in Spec, and removes references to instance var…
bikeath1337 Sep 9, 2015
b0dc66b
Merges PR #113, to support multiple screenshots in one pass
bikeath1337 Jan 12, 2016
4f66d2e
Bumps version to 2.0.0 as this is a potentially breaking change as we…
bikeath1337 Jan 13, 2016
c84b8cf
Updates email
bikeath1337 Jan 18, 2016
32f6800
Ignore DAR when calculating dimensions
rackfishdaniel Feb 23, 2016
1b14534
Made SAR/DAR adapt after rotation
rackfishdaniel Apr 13, 2016
492c64c
Updates readme to describe how to produce multiple screenshots; adds …
bikeath1337 Jul 29, 2016
c1ff726
Raise error if JSON parsing fails.
Aug 2, 2016
d433fe5
Add test.
Aug 2, 2016
95b58fd
Update tests to use rspec 3.4 syntax, closes #129
d4rky-pl Jun 7, 2016
a1eb09c
Add support for remote URLs as input for FFMPEG::Movie, closes #130
d4rky-pl Jun 7, 2016
6ff0d12
Fix data streams incorrectly marking video as broken, closes #131
d4rky-pl Jun 22, 2016
b32281e
Resolves ambiguities in specs after Rspec upgrade
bikeath1337 Aug 2, 2016
a8380bb
Addresses Rspec reported deprecations
bikeath1337 Aug 2, 2016
c162f2c
rescue from exceptions when parsing metadata creation_time, closes #124
mziwisky Mar 22, 2016
114fd20
Brings spec current with Rspec 3
bikeath1337 Aug 2, 2016
9bbd902
Only reject invalid video or audio streams
mziwisky Mar 16, 2016
9dcb89a
Bring spec current with v3
bikeath1337 Aug 2, 2016
420dbf9
Movie#valid? only requires one supported stream, closes #123
mziwisky Apr 12, 2016
1bdffd0
Removes previous attempt to validate various, invalid streams
bikeath1337 Aug 2, 2016
24220b2
Bring spec current with v3
bikeath1337 Aug 2, 2016
7e17d8e
Corrects screenshot spec that relied on an unclean
bikeath1337 Aug 2, 2016
8f9b706
Adds encoding fix to stderr. Closes #122.
mziwisky Mar 16, 2016
e3ca82b
Uses attr_accessor for the timeout attribute. Closes #111.
antstorm Dec 1, 2015
5bdd71c
Exposes format tags and metadata as attributes of Movie as FFProbe ma…
Sep 2, 2015
6a813e1
Directly pass arguments to ffmpeg
corny Dec 21, 2014
4916eee
Brings Kornberger’s work current with master, Closes #96.
bikeath1337 Aug 3, 2016
6c33d2d
Removes superfluous parameter (it was misplaced)
bikeath1337 Aug 2, 2016
3ead1c1
Prepares the test block for more specs related to transcoding_options
bikeath1337 Aug 2, 2016
ff28d62
Adds ability to define `input` and `input_options` in the transcoding…
bikeath1337 Aug 2, 2016
e275b87
Updates readme. Closes #135
bikeath1337 Aug 2, 2016
a5ffa7a
Adds specs for watermarking.
bikeath1337 Aug 2, 2016
03ac82e
Brings work current with master
bikeath1337 Aug 3, 2016
3c314b7
Adds support for creating slideshows from stills, makes shell command…
bikeath1337 Aug 8, 2016
a0a1386
Bumps version, updates changelog
bikeath1337 Aug 8, 2016
30fa648
Fixes ability to define custom options, adds specs, Closes #137.
bikeath1337 Aug 15, 2016
0df706a
Adds more tests related to custom options.
bikeath1337 Aug 22, 2016
f8ebc6e
Updates documentation to reflect new format for custom options. The u…
bikeath1337 Aug 23, 2016
7382640
Bumps version.
bikeath1337 Sep 7, 2016
120a019
Adds specs for converting audio only files. Closes #120.
bikeath1337 Sep 9, 2016
46223c6
Adds specs to test for filenames that contain “URL” Characters that p…
bikeath1337 Sep 9, 2016
422c5e3
Prefers %w over lateral list syntax
bikeath1337 Sep 13, 2016
ec3b981
Adds CodeClimate badge.
bikeath1337 Sep 23, 2016
e9e1123
Allow for Windows filepaths
wilcovanesch Oct 7, 2016
a2b5dab
Update README.md: Modern standards
Oct 9, 2016
a508ff7
Add how to install ffmpeg on macOS, Closes #146.
Oct 9, 2016
1963f21
Specs for slideshows without a movie, closes #144
bikeath1337 Oct 12, 2016
1502155
Adds travis.yml
bikeath1337 Sep 23, 2016
ed86990
Adds ability to follow redirects; Adds new class property “max_http_r…
bikeath1337 Sep 27, 2016
8fd6db6
Removes additional class check as the redirect status will never happen
bikeath1337 Sep 27, 2016
41fc915
Simplifies response to relative location paths
bikeath1337 Sep 27, 2016
f898d1f
Validates FFMPEG.max_http_redirect_attempts to be a positive whole nu…
bikeath1337 Sep 27, 2016
df9737e
Uses 'request_uri' over 'path' so that query parameters
bikeath1337 Sep 27, 2016
aeef1f7
Adds support to follow URL redirects in input specifications
bikeath1337 Nov 10, 2016
1129c67
Addresses a typo in the readme, closes #148
poctek Oct 17, 2016
e8916ea
Updates changelog, bumps version
bikeath1337 Nov 10, 2016
0260e9f
Do not trust `unset value` in dar/sar, in flipped movie
konk303 Nov 7, 2016
c35ab55
DRYs up the dar/sar calculations
bikeath1337 Nov 18, 2016
ede782c
Expose multiple audio streams. Closes #153
CSilivestru Nov 16, 2016
ff669f8
Breaks up expectations into distinct blocks; prefers RSpec `expect` t…
bikeath1337 Nov 18, 2016
6c62990
bumps
bikeath1337 Nov 18, 2016
0fa8cd7
Updates Travis.yml
bikeath1337 Nov 18, 2016
3393e40
Correct test coverage gem spec
bikeath1337 Nov 18, 2016
387221d
Updates badges
bikeath1337 Nov 18, 2016
e78b43c
Corrects badge.
bikeath1337 Nov 18, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ tmtags
## VIM
*.swp

## RubyMine
.idea/

## PROJECT::GENERAL
coverage
rdoc
Expand Down
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
before_install: wget http://johnvansickle.com/ffmpeg/releases/ffmpeg-release-64bit-static.tar.xz -O - | sudo tar -xJ --strip-components=1 -C /usr/local/bin/
language: ruby
rvm:
- 2.0.0
- 2.2
- 2.3.1
cache:
- bundler
addons:
code_climate:
repo_token: 25cb5ce0278a4633050937ff504ef0eef45f5756b53db51b179ad42ed5d8c428
after_success:
- bundle exec codeclimate-test-reporter
53 changes: 53 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,10 +1,63 @@
== Master

Current with 3.0.2

== 3.0.2 2016-11-18

Improvements:
* Issue #153 Adds support for multiple audio streams
* Issue #150 Does not trust reported SAR/DAR as these may not be defined per https://trac.ffmpeg.org/ticket/3798

== 3.0.1 2016-11-10

Improvements:
* Issue #144 is fixed. Of a nil movie is presented to transcode, the progress block does not fail
* Issue #145 Adds ability to follow URLs when presented as Movie inputs


== 3.0.0 2016-09-07

Breaking Changes:
* Changes: custom parameters now specified using an array syntax

Improvements:
* Issue # 128, #137 are fixed (custom parameters passed as strings) which was caused
by 2.1.0 in attempting to avoid the use of shell and filename escaping issues
on various platforms.


== 2.1.0 2016-08-08

New:
* Issue #135, Support creating slideshows from stills
* Issue #130, Adds support for a URL as an input
* Support for specifying options to apply to the input file
* Improved support for calling FFMpeg with popen3, improving compatibility with various platforms, including windows
* Issue #111. uses attr_accessor for the timeout attribute
* Exposes the movie's entire meta data and format tags as movie attributes
* Issue #122, adds encoding fix to stderr
* All specs pass and brought current with Rspec V3
* Issue #123, #131 improved stream validation, ignoring additional invalid streams if a valid stream is recognized
* Issue #124, improved parsing for moving creation_time
* SAR and DAR now adapt after rotation, DAR is ignored when calculating dimensions

Improvements:
* Allow parenthesis in colorspace (thanks walterdavis for initial code and rociiu for finding a bug with it)
* Width and height now switched if video is filmed in portrait mode. ffmpeg 2.7 or later now automatically rotates output
* Movie metadata now provided with ffprobe (#114). Thanks to Ryan Lovelett for the contributions!
* Ability to create multiple screenshots at consistent intervals in one pass (#113)

== 2.0.0 2016-01-14

New:
* Support watermarking (thanks smoothdvd)
* Bumped target ffmpeg version to 2.8

Improvements:
* Allow parenthesis in colorspace (thanks walterdavis for initial code and rociiu for finding a bug with it)
* Width and height now switched if video is filmed in portrait mode. ffmpeg 2.7 or later now automatically rotates output
* Movie metadata now provided with ffprobe (#114). Thanks to Ryan Lovelett for the contributions!
* Ability to create multiple screenshots at consistent intervals in one pass (#113)

== 1.0.0 2013-07-08

Expand Down
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
source "https://rubygems.org"

gemspec

group :test do
gem 'webmock'
gem 'simplecov'
end
116 changes: 99 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Streamio FFMPEG
===============

[![Build Status](https://travis-ci.org/bikeath1337/streamio-ffmpeg.svg?branch=master)](https://travis-ci.org/bikeath1337/streamio-ffmpeg)
[![Code Climate](https://codeclimate.com/github/bikeath1337/streamio-ffmpeg/badges/gpa.svg)](https://codeclimate.com/github/bikeath1337/streamio-ffmpeg)
[![Test Coverage](https://codeclimate.com/github/bikeath1337/streamio-ffmpeg/badges/coverage.svg)](https://codeclimate.com/github/bikeath1337/streamio-ffmpeg/coverage)

Simple yet powerful wrapper around the ffmpeg command for reading metadata and transcoding movies.

All work on this project is sponsored by the online video platform [Streamio](http://streamio.com).
Expand All @@ -10,7 +14,7 @@ All work on this project is sponsored by the online video platform [Streamio](ht
Installation
------------

(sudo) gem install streamio-ffmpeg
gem install streamio-ffmpeg

Compatibility
-------------
Expand All @@ -23,15 +27,18 @@ Will not work in jruby until they fix: http://goo.gl/Z4UcX (should work in the u

### ffmpeg

The current gem is tested against ffmpeg 1.2.1. 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.
The current gem is tested against ffmpeg 2.8.4. 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.

On macOS: `brew install ffmpeg`.

Usage
-----

### Require the gem

``` ruby
require 'rubygems'
require 'streamio-ffmpeg'
```

Expand All @@ -57,6 +64,9 @@ movie.audio_codec # "aac"
movie.audio_sample_rate # 44100
movie.audio_channels # 2

# Multiple audio streams
movie.audio_streams[0] # "aac, 44100 Hz, stereo, s16, 75 kb/s" (raw audio stream info)

movie.valid? # true (would be false if ffmpeg fails to read the movie)
```

Expand All @@ -74,21 +84,24 @@ Keep track of progress with an optional block.
movie.transcode("movie.mp4") { |progress| puts progress } # 0.2 ... 0.5 ... 1.0
```

Give custom command line options with a string.
Give custom command line options with an array.

``` ruby
movie.transcode("movie.mp4", "-ac aac -vc libx264 -ac 2 ...")
movie.transcode("movie.mp4", %w(-ac aac -vc libx264 -ac 2 ...))
```

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.
Use the EncodingOptions parser for humanly readable transcoding options. Below you'll find most of the supported options.
Note that the :custom key is an array so that it can be used for FFMpeg options like
`-map` that can be repeated:

``` ruby
options = {video_codec: "libx264", frame_rate: 10, resolution: "320x240", video_bitrate: 300, video_bitrate_tolerance: 100,
aspect: 1.333333, keyframe_interval: 90,
x264_vprofile: "high", x264_preset: "slow",
audio_codec: "libfaac", audio_bitrate: 32, audio_sample_rate: 22050, audio_channels: 1,
threads: 2,
custom: "-vf crop=60:60:10:10"}
options = {
video_codec: "libx264", frame_rate: 10, resolution: "320x240", video_bitrate: 300, video_bitrate_tolerance: 100,
aspect: 1.333333, keyframe_interval: 90, x264_vprofile: "high", x264_preset: "slow",
audio_codec: "libfaac", audio_bitrate: 32, audio_sample_rate: 22050, audio_channels: 1,
threads: 2, custom: %w(-vf crop=60:60:10:10 -map 0:0 -map 0:1)
}

movie.transcode("movie.mp4", options)
```

Expand Down Expand Up @@ -128,15 +141,52 @@ options = {video_min_bitrate: 600, video_max_bitrate: 600, buffer_size: 2000}
movie.transcode("movie.flv", options)
```

### Specifying Input Options

To specify which options apply the input, such as changing the input framerate, use `input_options` hash
in the transcoder_options.

``` ruby
movie = FFMPEG::Movie.new("path/to/movie.mov")

transcoder_options = { input_options: { framerate: '1/5' } }
movie.transcode("movie.mp4", {}, transcoder_options)

# FFMPEG Command will look like this:
# ffmpeg -y -framerate 1/5 -i path/to/movie.mov movie.mp4
```

### Overriding the Input Path

If FFMPEG's input path needs to specify a sequence of files, rather than a path to a single movie, transcoding_options
`input` can be set. If this option is present, the path of the original movie will not be used.

``` ruby
movie = FFMPEG::Movie.new("path/to/movie.mov")

transcoder_options = { input: 'img_%03d.png' }
movie.transcode("movie.mp4", {}, transcoder_options)

# FFMPEG Command will look like this:
# ffmpeg -y -i img_%03d.png movie.mp4
```

### Watermarking

Add watermark image on the video.

For example, you want to add a watermark on the video at right top corner with 10px padding.

``` ruby
options = { watermark: "full_path_of_watermark.png", resolution: "640x360", watermark_filter: { position: "RT", padding_x: 10, padding_y: 10 } }
options = {
watermark: "full_path_of_watermark.png", resolution: "640x360",
watermark_filter: { position: "RT", padding_x: 10, padding_y: 10 }
}
```

Position can be "LT" (Left Top Corner), "RT" (Right Top Corner), "LB" (Left Bottom Corner), "RB" (Right Bottom Corner).
The watermark will not appear unless `watermark_options` specifies the position. `padding_x` and `padding_y` default to
`10`.

### Taking Screenshots

Expand All @@ -152,28 +202,61 @@ The screenshot method has the very same API as transcode so the same options wil
movie.screenshot("screenshot.bmp", seek_time: 5, resolution: '320x240')
```

To generate multiple screenshots in a single pass, specify `vframes` and a wildcard filename. Make
sure to disable output file validation. The following code generates up to 20 screenshots every 10 seconds:

``` ruby
movie.screenshot("screenshot_%d.jpg", { vframes: 20, frame_rate: '1/6' }, validate: false)
```

To specify the quality when generating compressed screenshots (.jpg), use `quality` which specifies
ffmpeg `-v:q` option. Quality is an integer between 1 and 31, where lower is better quality:

``` ruby
movie.screenshot("screenshot_%d.jpg", quality: 3)
```

You can preserve aspect ratio the same way as when using transcode.

``` ruby
movie.screenshot("screenshot.png", { seek_time: 2, resolution: '200x120' }, preserve_aspect_ratio: :width)
```

### Create a Slideshow from Stills
Creating a slideshow from stills uses named sequences of files and stiches the result together in a slideshow
video.

Since there is not movie to transcode, the Transcoder class needs to be used. The input and input_options are
provided through transcoder options.

``` ruby
slideshow_transcoder = FFMPEG::Transcoder.new(
'',
'slideshow.mp4',
{ resolution: "320x240" },
input: 'img_%03d.jpeg',
input_options: { framerate: '1/5' }
)

slideshow = slideshow_transcoder.run
```

Specify the path to ffmpeg
--------------------------

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:
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:

``` ruby
FFMPEG.ffmpeg_binary = '/usr/local/bin/ffmpeg'
```

This will cause the same command to run as "/usr/local/bin/ffmpeg -i /path/to/input.file ..." instead.
This will cause the same command to run as `/usr/local/bin/ffmpeg -i /path/to/input.file ...` instead.


Automatically kill hung processes
---------------------------------

By default, streamio will wait for 30 seconds between IO feedback from the FFMPEG process. After which an error is logged and the process killed.
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.
It is possible to modify this behaviour by setting a new default:

``` ruby
Expand All @@ -199,7 +282,6 @@ transcoder_options = { validate: false }
movie.transcode("movie.mp4", options, transcoder_options) # returns nil
```


Copyright
---------

Expand Down
Loading