Git Product home page Git Product logo

streamio-ffmpeg's Introduction

Streamio FFMPEG

Build Status Code Climate Test 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 from Rackfish.

Streamio

Installation

gem install streamio-ffmpeg

Compatibility

Ruby

Only guaranteed to work with MRI Ruby 1.9.3 or later. Should work with rubinius head in 1.9 mode. Will not work in jruby until they fix: http://goo.gl/Z4UcX (should work in the upcoming 1.7.5)

ffmpeg

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

require 'streamio-ffmpeg'

Reading Metadata

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

movie.duration # 7.5 (duration of the movie in seconds)
movie.bitrate # 481 (bitrate in kb/s)
movie.size # 455546 (filesize in bytes)

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)
movie.video_codec # "h264"
movie.colorspace # "yuv420p"
movie.resolution # "640x480"
movie.width # 640 (width of the movie in pixels)
movie.height # 480 (height of the movie in pixels)
movie.frame_rate # 16.72 (frames per second)

movie.audio_stream # "aac, 44100 Hz, stereo, s16, 75 kb/s" (raw audio stream info)
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)

Transcoding

First argument is the output file path.

movie.transcode("tmp/movie.mp4") # Default ffmpeg settings for mp4 format

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 an array.

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 is an array so that it can be used for FFMpeg options like -map that can be repeated:

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)

The transcode function returns a Movie object for the encoded file.

transcoded_movie = movie.transcode("tmp/movie.flv")

transcoded_movie.video_codec # "flv"
transcoded_movie.audio_codec # "mp3"

Aspect ratio is added to encoding options automatically if none is specified.

options = { resolution: "320x180" } # Will add -aspect 1.77777777777778 to ffmpeg

Preserve aspect ratio on width or height by using the preserve_aspect_ratio transcoder option.

widescreen_movie = FFMPEG::Movie.new("path/to/widescreen_movie.mov")

options = { resolution: "320x240" }

transcoder_options = { preserve_aspect_ratio: :width }
widescreen_movie.transcode("movie.mp4", options, transcoder_options) # Output resolution will be 320x180

transcoder_options = { preserve_aspect_ratio: :height }
widescreen_movie.transcode("movie.mp4", options, transcoder_options) # Output resolution will be 426x240

For constant bitrate encoding use video_min_bitrate and video_max_bitrate with buffer_size.

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.

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.

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.

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

You can use the screenshot method to make taking screenshots a bit simpler.

movie.screenshot("screenshot.jpg")

The screenshot method has the very same API as transcode so the same options will work.

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:

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:

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

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

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.

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

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.

Automatically kill hung processes

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:

# Change the timeout
Transcoder.timeout = 10

# Disable the timeout altogether
Transcoder.timeout = false

Disabling output file validation

By default Transcoder validates the output file, in case you use FFMPEG for HLS format that creates multiple outputs you can disable the validation by passing validate: false to transcoder_options.

Note that transcode will not return the encoded movie object in this case since attempting to open a (possibly) invalid output file might result in an error being raised.

transcoder_options = { validate: false }
movie.transcode("movie.mp4", options, transcoder_options) # returns nil

Copyright

Copyright (c) Rackfish AB. See LICENSE for details.

streamio-ffmpeg's People

Contributors

akicho8 avatar amksd avatar antstorm avatar bikeath1337 avatar corny avatar csilivestru avatar d4rky-pl avatar dbackeus avatar innonate avatar konk303 avatar linutux avatar mishaux avatar mistydemeo avatar mziwisky avatar neerfri avatar pirvudoru avatar poctek avatar rackfishdaniel avatar rbrooks avatar rlovelett avatar smoothdvd avatar squidarth avatar stakach avatar streamio avatar vitalis avatar walterdavis avatar wilcovanesch avatar youpy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

streamio-ffmpeg's Issues

How to list audio and video codecs

How can I get a listing of the available encoding and decoding audio and video codecs on the system that streamio-ffmpeg is installed?

Progress block returns values greater than 1.0

I'm using v1.0.0.

movie = FFMPEG::Movie.new("my_apple_animation_codec.mov")
movie.transcode("my_x264_codec.mov", "-c:a copy -c:v libx264 -x264opts crf=18 -pix_fmt yuv420p") do |progress|
  puts progress
end

This returns

0.0
0.13289036544850497
0.26578073089700993
0.46511627906976744
0.5980066445182723
0.7315614617940199
0.9308970099667774
1.0086378737541528 # this should be less than 1.0
1.0

is it can read remote video

I have a video stored in amazon s3.
Is this gem can read the video and make the video thumbnails?

I just try

 movie = FFMPEG::Movie.new("https://s3.amazonaws.com/XXX/XXX.mp4")

Seems don't work.

Export Data stream?

Hello,

I would like to know if it is possible to allow export of Data stream in your next release.

Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuvj420p, 1280x960 [SAR 1:1 DAR 4:3], 15072 kb/s, 59.94 fps, 59.94 tbr, 60k tbn, 119.88 tbc

Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 127 kb/s
Stream #0:2(eng): Data: none (tmcd / 0x64636D74)

Thanks

input source regex conflicts with custom_filter on some cases

On EncodingOptions#to_s:

      ...
      # codecs should go before the presets so that the files will be matched successfully
      # all other parameters go after so that we can override whatever is in the preset
      source  = params.select {|p| p =~ /\-i/ }
      seek    = params.select {|p| p =~ /\-ss/ }
      ...

Conflicts with filter as this pad to center: pad=640:480:(ow-iw)/2:(oh-ih)/2

It should be fix to:

      source  = params.select {|p| p =~ /\-i / }
      seek    = params.select {|p| p =~ /\-ss / }

because every input flag will include a space between the -i and the input source.

Support multiple outputs

It would be great if streamio-ffmpeg could support multiple outputs in one transcode, just like FFmpeg can do on the command line. Essentially just an array of encoding_options with the output filenames, rather than just a single output file on the transcode() call.

Use ffprobe instead of ffmpeg

Parsing the ffmpeg text output is complex an error prone. It is much easier to parse ffprobe output, when using the json option (-print_format json). This is at least, what I use in my last project. Just a recommendation of mine.

Performance of screenshot taking function

I'm very happy about the new screenshot function. Works great in my MacOS Development machine:

7022a30

However the function suffers from heavy performance issues on Ubuntu 12.04 server. Now sure what exactly is causing it, but workaround is provided on this blog post:

http://www.nrg-media.de/2010/11/creating-screenshots-with-ffmpeg-is-slow/

Somehow moving the time shift parameter "-ss" to the very beginning is solving the issue. As workaround I programmed my own call to ffmpeg to pass the parameters in the desired order and this solves the issue.
I checked the coding, but found that the first parameters are provided within transcoder.rb and not encoding_options.rb :-( . Would be anyways nice to get with working on different ffmpeg versions.

Failures on 1.8.7

NoMethodError: undefined method 'pid' for nil:NilClass

Looks like the use of wait_thr.pid in Transcoder#run chokes on 1.8.7 because Open3::popen3 doesn't provide that argument yet.

I'm upgrading my app to 1.9, but in the meantime, would like to use this wrapper for FFMPEG. For my use case, it would be sufficient not to set a timeout, and I could submit a patch that disables it for ruby < 1.9, but don't have time for much else, unfortunately.

Any preferences?

video_stream regex misses some Quicktime videos

https://github.com/streamio/streamio-ffmpeg/blob/master/lib/ffmpeg/movie.rb#L46

This doesn't quite work with every video stream and could probably be more sophisticated (I may get around to it, but putting up here in case any one else wants to take a stab).

I have a video exported from an old iMovie version. It's video stream value is:

none (icod / 0x646F6369), 960x540, 18653 kb/s): unknown codec

This causes the resolution to be 18653 resulting in a height of 0 and width of 18653

May be better to extract resolution separately with a regex like (\d{1,})x(\d{1,}),

H264 Seems to Break Colorspace / Dimensions

Hi,

Using the default example from the documentation in a script to examine an H264 file, it seems as if a comma in the "movie.colorspace" value will cause that value to overflow into the next 3 key values :

movie.resolution
movie.width
movie.height

movie.resolution will become the colorspace value post-comma and movie.width & movie.height will have a value of 0.

Below is the script run on two different files to demonstrate this. The first is a ProRes file, the 2nd is an H264. The section in question is in bold. At the very end is the script as run.

PRO RES FILE OUTPUT

98.92
51896
641678236
prores (apcn / 0x6E637061), yuv422p10le(bt709), 1280x720, 51743 kb/s, 24 fps, 24 tbr, 24 tbn, 24 tbc (default)
prores (apcn / 0x6E637061)
yuv422p10le(bt709)
1280x720
1280
720

24.0
aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 147 kb/s (default)
aac (LC) (mp4a / 0x6134706D)
48000
2

H264 FILE OUTPUT

98.93
5343
66084289
h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720, 3805 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 48k tbc (default)
h264 (Main) (avc1 / 0x31637661)
yuv420p(tv
bt709)
0
0

23.98
pcm_s16be (twos / 0x736F7774), 48000 Hz, stereo, s16, 1536 kb/s (default)
pcm_s16be (twos / 0x736F7774)
48000
2

SCRIPT :

require 'rubygems'
require 'streamio-ffmpeg'

movie = FFMPEG::Movie.new(ARGV[0])

puts "#{movie.duration}" # 7.5 (duration of the movie in seconds)
puts "#{movie.bitrate}" # 481 (bitrate in kb/s)
puts "#{movie.size}" # 455546 (filesize in bytes)

puts "#{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)
puts "#{movie.video_codec}" # "h264"
puts "#{movie.colorspace}" # "yuv420p"
puts "#{movie.resolution}" # "640x480"
puts "#{movie.width}" # 640 (width of the movie in pixels)
puts "#{movie.height}" # 480 (height of the movie in pixels)
puts "#{movie.frame_rate}" # 16.72 (frames per second)

puts "#{movie.audio_stream}" # "aac, 44100 Hz, stereo, s16, 75 kb/s" (raw audio stream info)
puts "#{movie.audio_codec}" # "aac"
puts "#{movie.audio_sample_rate}" # 44100
puts "#{movie.audio_channels}" # 2

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

movie_spec and transcoder_spec fails

Hi,

Since Shellword.escape(path) the above specs fail under Ubuntu. You changed...

      raise Errno::ENOENT, "the file '#{path}' does not exist" unless File.exists?(path)

      @path = path

      # ffmpeg will output to stderr
      command = "#{FFMPEG.ffmpeg_binary} -i #{Shellwords.escape(path)}"

ffmpeg fails to find the file but the File.exists?(path) test passes.

If I change it to File.exists?(Shellwords.escape(path)) then the test fails along with the specs

Guy

No such file or directory (when file exists)

For some reason, when trying to transcode a video file (that does really exist), FFMPEG says the file does not exist.

Here's some output from the Rails console, demonstrating my headache:

    1.9.3p125 :001 > File.exist?("/Applications/MAMP/htdocs/video-app/public/uploads/tmp/20131208-1416-1234-0984/videotest.mp4")
    => true 

    1.9.3p125 :002 > FFMPEG::Movie.new("/Applications/MAMP/htdocs/video-app/public/uploads/tmp/20131208-1416-1234-0984/videotest.mp4")
    Errno::ENOENT: No such file or directory - ffmpeg -i /Applications/MAMP/htdocs/video-app/public/uploads/tmp/20131208-1416-1234-0984/videotest.mp4
    from /Users/my-comp/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/open3.rb:202:in `spawn'
    from /Users/my-comp/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/open3.rb:202:in `popen_run'
    from /Users/my-comp/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/open3.rb:90:in `popen3'
    from /Users/my-comp/.rvm/gems/ruby-1.9.3-p125@video-app/gems/streamio-ffmpeg-1.0.0/lib/ffmpeg/movie.rb:17:in `initialize'
    from (irb):2:in `new'
    from (irb):2
    from /Users/my-comp/.rvm/gems/ruby-1.9.3-p125@video-app/gems/railties-3.2.8/lib/rails/commands/console.rb:47:in `start'
    from /Users/my-comp/.rvm/gems/ruby-1.9.3-p125@video-app/gems/railties-3.2.8/lib/rails/commands/console.rb:8:in `start'
    from /Users/my-comp/.rvm/gems/ruby-1.9.3-p125@video-app/gems/railties-3.2.8/lib/rails/commands.rb:41:in `<top (required)>    '
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'
    1.9.3p125 :003 > 

Cannot create screenshot

I am currently having trouble creating screenshots. My code is like so:

def make_screenshot
  directory = File.dirname( current_path )
  tmpfile2   = File.join( directory, "tmpfile2" )

  FileUtils.move( current_path, tmpfile2 )

  file = ::FFMPEG::Movie.new(tmpfile2)
  file.screenshot(current_path , {:seek_time => 2, :resolution => '200x120'}, :preserve_aspect_ratio => :width)

  File.delete( tmpfile2 )
end

I am getting the error NoMethodError (undefined method `screenshot' for #FFMPEG::Movie:0x007f0ef8319a08)

I just updated my gem to 0.9.0. Is this something I am doing wrong? Transcode works fine

Wrong resolution info for some videos

Examples of video_stream for which resolution info is wrong:

video_stream: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720, 22469 kb/s, 120.16 fps, 2400 tbr, 2400 tbn, 4800 tbc (default)
resolution: bt709)

video_stream: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, smpte170m), 640x360, 2826 kb/s, SAR 1:1 DAR 16:9, 25 fps, 25 tbr, 2500 tbn, 50 tbc (default)
resolution: smpte170m)

Problem is the colorspace having additional info in parentheses.

Support other Encoders maybe Queues

Any thoughts on supporting other encoders?
ffmpeg2theora, mkclean (for webm container), etc.

Any thoughts on Queuing up multiple process to operate in sequence?
For instance multipass encoding x264, or ffmpeg followed by mkclean for webm.

I understand both of these items would certainly complicate the module as it stands, however, transcoding really is a workflow. I suppose some other modules similar to this one, one for each tool in the workflow, then a tool to tie them together into a workflow could be interesting.

Deprecation warning for -b video bitrate option

I keep getting these warnings on setting the output video bitrate when using the:video_bitrate option in the FFMPEG::Movie#transcode method:

Please use -b:a or -b:v, -b is ambiguous

Not a critical bug, but something that might become one in the future. Apparently the ffmpeg developers changed the preferred syntax for the -b (video bitrate) option. I don't know why exactly, as there was already a -ab audio bitrate option, but this error might prevent the gem from working properly in the future.

Progress reporting fix

Currently the log message displays in between the progress yield block which causes problems in the way I'm reporting my progress.

If you could swap lines 44 and 45 of code in transcoder.rb then

  1. FFMPEG.logger.info "Transcoding of #{@movie.path} to #{@output_file} succeeded\n"
  2. yield(1.0) if block_given?

to

  1. yield(1.0) if block_given?
  2. FFMPEG.logger.info "Transcoding of #{@movie.path} to #{@output_file} succeeded\n"

That would be awesome and then I can remove my nasty monkey patch :-)

by the way keep it up this gem is way better then Rvideo

supports_option? fail on Ruby 1.9

I would suggest a following patch, otherwise no parameters are parsed properly. The difference is in added .to_sym method.

module FFMPEG
  class EncodingOptions    
    private
    def supports_option?(option)
      private_methods.include?("convert_#{option}".to_sym)
    end   
  end
end

How to hide streamio-ffmpeg dumpling information on terminal

Hi All~

When I running the testing to get video file to compare the latest previous video file.
There dumping the information on terminal. It look like no big deal.

But if I fetch the video used this method:

     'let(:resource) { create :resource, :file => File.new("#{Rails.root}/spec/fixtures/xx.mp4") }'

And give some test logic code like this:

    'it {expect(resource.width).to eq 640}'
    'it {expect(resource.height).to eq 428}'

It will be duplicate dumpling below information twice by the above two ‘it' block description code.
What should I do if I want to hide those redundant information on terminal completely?
Have Any Good Ideas?


                               The streamio-ffmpeg dumpling information

Run options: include {:locations=>{"./spec/models/resource_spec.rb"=>[11]}}
ffmpeg version 2.7.2 Copyright (c) 2000-2015 the FFmpeg developers
built with Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/2.7.2_1 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-vda
libavutil 54. 27.100 / 54. 27.100
libavcodec 56. 41.100 / 56. 41.100
libavformat 56. 36.100 / 56. 36.100
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 16.101 / 5. 16.101
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.100 / 1. 2.100
libpostproc 53. 3.100 / 53. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/var/folders/rv/t962rfpn1799m819d5qw3_wr0000gn/T/5e8ff9bf55ba3508199d22e984129be620150902-38041-vlxbfk.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
creation_time : 2015-08-17 14:11:30
encoder : Lavf52.62.0
comment : FlixEngine_8.1.0.2
Duration: 00:00:09.60, start: 0.000000, bitrate: 750 kb/s


...
[swscaler @ 0x7f903300a200] deprecated pixel format used, make sure you did set range correctly
Output #0, image2, to '/var/folders/rv/t962rfpn1799m819d5qw3_wr0000gn/T/5e8ff9bf55ba3508199d22e984129be620150902-38041-vlxbfk20150902-38041-e644hi.jpg':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
comment : FlixEngine_8.1.0.2
encoder : Lavf56.36.100
Stream #0:0(und): Video: mjpeg, yuvj420p(pc), 192x192, q=2-31, 200 kb/s, 30 fps, 30 tbn, 30 tbc (default)
Metadata:
creation_time : 2015-08-17 14:11:30
handler_name : VideoHandler
encoder : Lavc56.41.100 jpeg

-crop* options no longer working in ffmpeg 0.10.2

I was trying to crop videos and noticed the -croptop, -cropbottom, -cropleft and -cropright options did not seem to be doing anything. After some searching, the ffmpeg 0.10.2 manual gave me this:

All the crop options have been removed. Use -vf crop=width:height: x: y instead.

I'm not entirely sure how the -vf syntax could be implemented in terms of simple key-value pairs for the transcode method, but I thought i'd mention it here as it might help others who have problems with video cropping.

-loop 1 parameter

This option should be before -i
Like: ffmpeg -loop 1 -y -i test.jpg -t 10 result.avi

I think there should be a way to define some params before input parameter.

Getting the PID?

Hi there,

Is there a way to get PID of FFMPEG instance inside or outside of transcode method? I need to be able to cancel transcode process so I assume I should have PID? Do you have any better idea?

Thank you

ThreadError: can't create Thread (11)

Hi there,

First of all, thanks for this excellent job!

I'm running many instances of Transcode at the same time. It sometimes peaks up to 15-20 instances concurrently.

But sometimes I get this error:

can't create Thread (11)
/var/www/sts/shared/bundle/ruby/2.0.0/gems/streamio-ffmpeg-0.9.0/lib/ffmpeg/io_monkey.rb:46:in `initialize'
/var/www/sts/shared/bundle/ruby/2.0.0/gems/streamio-ffmpeg-0.9.0/lib/ffmpeg/io_monkey.rb:46:in `new'
/var/www/sts/shared/bundle/ruby/2.0.0/gems/streamio-ffmpeg-0.9.0/lib/ffmpeg/io_monkey.rb:46:in `new_thread'
/var/www/sts/shared/bundle/ruby/2.0.0/gems/streamio-ffmpeg-0.9.0/lib/ffmpeg/io_monkey.rb:26:in `block in each_with_timeout'
/var/www/sts/shared/bundle/ruby/2.0.0/gems/streamio-ffmpeg-0.9.0/lib/ffmpeg/io_monkey.rb:37:in `call'
/var/www/sts/shared/bundle/ruby/2.0.0/gems/streamio-ffmpeg-0.9.0/lib/ffmpeg/io_monkey.rb:37:in `block in each_with_timeout'
/var/www/sts/shared/bundle/ruby/2.0.0/gems/streamio-ffmpeg-0.9.0/lib/ffmpeg/io_monkey.rb:34:in `each'
/var/www/sts/shared/bundle/ruby/2.0.0/gems/streamio-ffmpeg-0.9.0/lib/ffmpeg/io_monkey.rb:34:in `each_with_timeout'
/var/www/sts/shared/bundle/ruby/2.0.0/gems/streamio-ffmpeg-0.9.0/lib/ffmpeg/transcoder.rb:65:in `block in run'
/home/deployer/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/open3.rb:217:in `popen_run'
/home/deployer/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/open3.rb:99:in `popen3'
/var/www/sts/shared/bundle/ruby/2.0.0/gems/streamio-ffmpeg-0.9.0/lib/ffmpeg/transcoder.rb:41:in `run'
/var/www/sts/shared/bundle/ruby/2.0.0/gems/streamio-ffmpeg-0.9.0/lib/ffmpeg/movie.rb:92:in `transcode'
/var/www/sts/releases/20130927134245/app/workers/converter30.rb:22:in `perform'

Is this about some limitations?

Thanks in advence.

Add timecode reading

Hi,

I'm very new to RoR and i want to make an app where i have to convert some audio file and read meta.
So i found your very interesting gem. In some of these audio files there is a meta data call: timecode which indicate the starting time of this audio file.
Is it possible to add this meta? So here what i would like to add in movie.rb

attr_reader :timecode

output[/timecode {1,}: {1,}(\d{2}):(\d{2}):(\d{2}):(\d{2})/]
@timecode = ($1.to_i_60_60) + ($2.to_i*60) + $3.to_i

Btw, the timecode is HH:MM:SS:frame don't know to use the fram so i ignored it.

the regular expression not correctly parse some video stream

"h264 (Main) (avc1 / 0x31637661), yuv420p".split(/\s?,(?![^,)]+))\s?/)
=> ["h264 (Main) (avc1 / 0x31637661)", "yuv420p"]

"h264 (Main) (avc1 / 0x31637661), yuv420p(tv)".split(/\s?,(?![^,)]+))\s?/)
=> ["h264 (Main) (avc1 / 0x31637661), yuv420p(tv)"]

Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height

when i use this gem in my OSX everything is fine, but when i deploy to Ubuntu 12.04
i got this issue

here is my detail log


ffmpeg -y -i thecliphcmryukjed-Gsusha.mp4 -vcodec h263 -r 10 -s 320x180 -b:v 25k -bt 100k -aspect 1.78 -g 90 -b:a 16k -ar 22050 -ac 1 -threads 2 -vf crop=60:60:10:10 movie.mp4

E, [2014-06-26T04:26:41.434317 #18292] ERROR -- : Failed encoding...
ffmpeg -y -i thecliphcmryukjed-Gsusha.mp4 -vcodec h263 -r 10 -s 320x180 -b:v 25k -bt 100k -aspect 1.78 -g 90 -b:a 16k -ar 22050 -ac 1 -threads 2 -vf crop=60:60:10:10 movie.mp4

ffmpeg version 0.10.12-7:0.10.12-1~precise1 Copyright (c) 2000-2014 the FFmpeg developers
  built on Apr 26 2014 09:49:36 with gcc 4.6.3
  configuration: --arch=amd64 --disable-stripping --enable-pthreads --enable-runtime-cpudetect --extra-version='7:0.10.12-1~precise1' --libdir=/usr/lib/x86_64-linux-gnu --prefix=/usr --enable-bzlib --enable-libdc1394 --enable-libfreetype --enable-frei0r --enable-gnutls --enable-libgsm --enable-libmp3lame --enable-librtmp --enable-libopencv --enable-libopenjpeg --enable-libpulse --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-vaapi --enable-vdpau --enable-libvorbis --enable-libvpx --enable-zlib --enable-gpl --enable-postproc --enable-libcdio --enable-x11grab --enable-libx264 --shlibdir=/usr/lib/x86_64-linux-gnu --enable-shared --disable-static
  libavutil      51. 35.100 / 51. 35.100
  libavcodec     53. 61.100 / 53. 61.100
  libavformat    53. 32.100 / 53. 32.100
  libavdevice    53.  4.100 / 53.  4.100
  libavfilter     2. 61.100 /  2. 61.100
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0.  6.100 /  0.  6.100
  libpostproc    52.  0.100 / 52.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'thecliphcmryukjed-Gsusha.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 1
    compatible_brands: mp41mp42isom
    creation_time   : 2014-06-25 05:25:32
  Duration: 00:00:06.23, start: 0.000000, bitrate: 251 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 640x360, 212 kb/s, 30 fps, 30 tbr, 600 tbn, 1200 tbc
    Metadata:
      creation_time   : 2014-06-25 05:25:32
      handler_name    : Core Media Video
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, s16, 33 kb/s
    Metadata:
      creation_time   : 2014-06-25 05:25:32
      handler_name    : Core Media Audio
[buffer @ 0x1d66600] w:640 h:360 pixfmt:yuv420p tb:1/1000000 sar:0/1 sws_param:
[scale @ 0x1d404e0] w:640 h:360 fmt:yuv420p -> w:320 h:180 fmt:yuv420p flags:0x4
[crop @ 0x1d40d80] w:320 h:180 -> w:60 h:60
Incompatible sample format 's16' for codec 'aac', auto-selecting format 'flt'
[h263 @ 0x1d644e0] The specified picture size of 60x60 is not valid for the H.263 codec.
Valid sizes are 128x96, 176x144, 352x288, 704x576, and 1408x1152. Try H.263+.
Output #0, mp4, to 'movie.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 1
    compatible_brands: mp41mp42isom
    creation_time   : 2014-06-25 05:25:32
    Stream #0:0(und): Video: h263, yuv420p, 60x60 [SAR 89:50 DAR 89:50], q=2-31, 25 kb/s, 90k tbn, 10 tbc
    Metadata:
      creation_time   : 2014-06-25 05:25:32
      handler_name    : Core Media Video
    Stream #0:1(und): Audio: none, 22050 Hz, 1 channels, flt, 128 kb/s
    Metadata:
      creation_time   : 2014-06-25 05:25:32
      handler_name    : Core Media Audio
Stream mapping:
  Stream #0:0 -> #0:0 (h264 -> h263)
  Stream #0:1 -> #0:1 (aac -> aac)
Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height

Errors: encoded file is invalid.

FFMPEG::Error: Failed encoding.Errors: encoded file is invalid. Full output: ffmpeg version 0.10.12-7:0.10.12-1~precise1 Copyright (c) 2000-2014 the FFmpeg developers
  built on Apr 26 2014 09:49:36 with gcc 4.6.3
  configuration: --arch=amd64 --disable-stripping --enable-pthreads --enable-runtime-cpudetect --extra-version='7:0.10.12-1~precise1' --libdir=/usr/lib/x86_64-linux-gnu --prefix=/usr --enable-bzlib --enable-libdc1394 --enable-libfreetype --enable-frei0r --enable-gnutls --enable-libgsm --enable-libmp3lame --enable-librtmp --enable-libopencv --enable-libopenjpeg --enable-libpulse --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-vaapi --enable-vdpau --enable-libvorbis --enable-libvpx --enable-zlib --enable-gpl --enable-postproc --enable-libcdio --enable-x11grab --enable-libx264 --shlibdir=/usr/lib/x86_64-linux-gnu --enable-shared --disable-static
  libavutil      51. 35.100 / 51. 35.100
  libavcodec     53. 61.100 / 53. 61.100
  libavformat    53. 32.100 / 53. 32.100
  libavdevice    53.  4.100 / 53.  4.100
  libavfilter     2. 61.100 /  2. 61.100
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0.  6.100 /  0.  6.100
  libpostproc    52.  0.100 / 52.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'thecliphcmryukjed-Gsusha.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 1
    compatible_brands: mp41mp42isom
    creation_time   : 2014-06-25 05:25:32
  Duration: 00:00:06.23, start: 0.000000, bitrate: 251 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 640x360, 212 kb/s, 30 fps, 30 tbr, 600 tbn, 1200 tbc
    Metadata:
      creation_time   : 2014-06-25 05:25:32
      handler_name    : Core Media Video
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, s16, 33 kb/s
    Metadata:
      creation_time   : 2014-06-25 05:25:32
      handler_name    : Core Media Audio
[buffer @ 0x1d66600] w:640 h:360 pixfmt:yuv420p tb:1/1000000 sar:0/1 sws_param:
[scale @ 0x1d404e0] w:640 h:360 fmt:yuv420p -> w:320 h:180 fmt:yuv420p flags:0x4
[crop @ 0x1d40d80] w:320 h:180 -> w:60 h:60
Incompatible sample format 's16' for codec 'aac', auto-selecting format 'flt'
[h263 @ 0x1d644e0] The specified picture size of 60x60 is not valid for the H.263 codec.
Valid sizes are 128x96, 176x144, 352x288, 704x576, and 1408x1152. Try H.263+.
Output #0, mp4, to 'movie.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 1
    compatible_brands: mp41mp42isom
    creation_time   : 2014-06-25 05:25:32
    Stream #0:0(und): Video: h263, yuv420p, 60x60 [SAR 89:50 DAR 89:50], q=2-31, 25 kb/s, 90k tbn, 10 tbc
    Metadata:
      creation_time   : 2014-06-25 05:25:32
      handler_name    : Core Media Video
    Stream #0:1(und): Audio: none, 22050 Hz, 1 channels, flt, 128 kb/s
    Metadata:
      creation_time   : 2014-06-25 05:25:32
      handler_name    : Core Media Audio
Stream mapping:
  Stream #0:0 -> #0:0 (h264 -> h263)
  Stream #0:1 -> #0:1 (aac -> aac)
Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height

Streams details

As i see in lib/ffmpeg/movie.rb we can read details about only one video stream and on audio stream.
As is possible to have different informations and codes on more then one video streams and on audio streams, may be nice to add a attr_reader :video_streams, :audio_streams to return a hash with all the stream data (and meta-data).

Loglevel

Hi,

I want to know if it's possible to enable the option -loglevel warning and output that into a new file.

streamio-ffmpeg windows install error

If I simply add the gem to my gemfile...
gem 'streamio-ffmpeg'

Then run bundle, everything looks good. But when I start my app I get the following error on bootup...

BTW I'm using Rails 3 w/ Windows 7. I also have the latest ffmpeg version installed & in my path, I understand that the readme says to use a lower version, gonna change to that and try again but wanted to know that this error is cropping up....

c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in require': cannot load such file -- win32/process (LoadError) from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:inblock in require'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:236:in load_dependency' from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:inrequire'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/streamio-ffmpeg-0.9.0/lib/ffmpeg/io_monkey.rb:15:in <top (required)>' from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:inrequire'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in block in require' from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:236:inload_dependency'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in require' from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/streamio-ffmpeg-0.9.0/lib/streamio-ffmpeg.rb:9:in<top (required)>'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.0.22/lib/bundler/runtime.rb:68:in require' from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.0.22/lib/bundler/runtime.rb:68:inblock (2 levels) in require'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.0.22/lib/bundler/runtime.rb:66:in each' from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.0.22/lib/bundler/runtime.rb:66:inblock in require'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.0.22/lib/bundler/runtime.rb:55:in each' from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.0.22/lib/bundler/runtime.rb:55:inrequire'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.0.22/lib/bundler.rb:122:in `require'

Better IO compatibility in jruby and 1.9 using popen4

In my fork I have switched to using popen4. I was going to send a pull req but after merging from your master my commits are a bit messed up.

Essentially it means using the Open4 gem in MRI 1.9 and the jruby IO popen4.

Please have a look at my fork as I would like to use the gem rather than a github link in my gemfile.

If you would be keen to use what I have done - please say so and I will detangle my commits to give you an easy merge.

Ta,
Guy

Return Metadata

I can't find an accessor to custom metadata, such as "date" (although we do have "creation_time"), which is the moment when the user actually shot the video.

irb> local_path = "/home/alexis2/Downloads/IMG_0980.MOV"
irb> movie = FFMPEG::Movie.new(local_path)
=> #<FFMPEG::Movie:0x000000010c5c28 @path="/home/alexis2/Downloads/IMG_0980.MOV", @duration=14.76, @time=0.0, @creation_time=2013-05-31 00:00:05 -0700, @bitrate=809, @rotation=nil, @video_stream="h264 (Main), yuv420p, 480x272, 742 kb/s, 30 fps, 30 tbr, 600 tbn, 1200 tbc", @audio_stream="aac, 44100 Hz, mono, s16, 62 kb/s", @video_codec="h264 (Main)", @colorspace="yuv420p", @video_bitrate=742, @resolution="480x272", @audio_codec="aac", @audio_channels="mono", @audio_bitrate=62, @audio_sample_rate=44100>

whereas

$ ffmpeg -i /home/alexis2/Downloads/IMG_0980.MOV
Metadata:
major_brand     : qt  
minor_version   : 0
compatible_brands: qt  
creation_time   : 2013-05-31 00:00:05
encoder         : 6.1.4
encoder-eng     : 6.1.4
date            : 2013-05-27T19:43:59-0700
date-eng        : 2013-05-27T19:43:59-0700
Duration: 00:00:14.76, start: 0.000000, bitrate: 809 kb/s

which has a date info I'm interested in. Not interested in creation_time in my app.

require is missing

nice ffmpeg gem ! , could you please put the require 'x' needed to use the gem inside irb or and .rb script, please.

Failed to load mov.

I tried to run the demo code. It didn't work. I may be making a newbie mistake cuz I've never really used ruby before. I got no error message or anything.

My code:

require 'rubygems'
require 'streamio-ffmpeg'

path = 'recording.mov'
puts "path: #{path}"
movie = FFMPEG::Movie.new(path)
puts "movie: #{movie}"

puts movie.duration # 7.5 (duration of the movie in seconds)
puts movie.bitrate # 481 (bitrate in kb/s)
puts movie.size # 455546 (filesize in bytes)

puts 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)
puts movie.video_codec # "h264"
puts movie.colorspace # "yuv420p"
puts movie.resolution # "640x480"
puts movie.width # 640 (width of the movie in pixels)
puts movie.height # 480 (height of the movie in pixels)
# puts movie.frame_rate # 16.72 (frames per second)

puts movie.audio_stream # "aac, 44100 Hz, stereo, s16, 75 kb/s" (raw audio stream info)
puts movie.audio_codec # "aac"
puts movie.audio_sample_rate # 44100
puts movie.audio_channels # 2

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

Output:
path: recording.mov
movie: #FFMPEG::Movie:0x10ca80680
0.0
nil
29189897
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
false
[Finished in 0.1s]

$ ffmpeg
FFmpeg version SVN-r26402, Copyright (c) 2000-2011 the FFmpeg developers
built on May 23 2012 21:02:07 with llvm_gcc 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)
configuration: --enable-libmp3lame --enable-shared --disable-mmx --arch=x86_64
libavutil 50.36. 0 / 50.36. 0
libavcore 0.16. 1 / 0.16. 1
libavcodec 52.108. 0 / 52.108. 0
libavformat 52.93. 0 / 52.93. 0
libavdevice 52. 2. 3 / 52. 2. 3
libavfilter 1.74. 0 / 1.74. 0
libswscale 0.12. 0 / 0.12. 0
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Use -h to get full help or, even better, run 'man ffmpeg'

Capture web camera and show in Gtk window

Hi. I'm a developer of P2P social network Pandora.
I've used gstreamer before, but it has a lot of trouble after migration to version 1.0.
Now I decide to try ffmpeg.

I didn't find any examples or documentation about "streamio-ffmpeg" bindings.

Please, tell me, how can I do:

  1. capture video stream from web-camera
  2. encode it to vp8 (or x264)
  3. give raw data from stream (i will send it via TCP)
  4. put raw data to stream
  5. decode it from vp8
  6. show video stream in Gtk window

Does "streamio-ffmpeg" can do it? Does it work in Windows?
Thanks in advance.

Creating screenshots is slow

Hello,

Screenshots generation can be very slow on long videos. There is a trick:

BAD:
fmpeg -i test.avi -ss 100 -f image2 screenshot1.jpg

GOOD:
ffmpeg -ss 100 -i test.avi -f image2 screenshot1.jpg

Is it possible to move -ss parameter before -i ? Thanks.

Start time offset

When I run --
system( "ffmpeg -y -ss 10505.89 -t 10 -i video/test-meeting.m4v -ab 192000 tmp/output.m4v" )
completion time is less than a second.

When I run --
options = { custom: "-ss 10505.89 -t 10" }
transcoder_options = { custom: "-ab 192000"}
@transcoded_movie = service.transcode( "tmp/movie.m4v", options, transcoder_options )

it takes minutes...or more. Is there a reason for this?

Create movie from data stream instead of filename

Is there a way that I can call FFMPEG::Movie.new with a data stream instead of a filename? Basically I want to generate a thumbnail from a video while it's being uploaded to my rails site. The file doesn't exist as the user is still uploading it and I am saving it to a mysql database instead of the file system. However, I have access to the data stream if that makes sense.

Generating thumbnails

Hi,

Thanks for your great plugin.

I am currently generating thumbnails with FFMPEG.
I would like to do this with your plugin. But i encounter some errors.

For the test I did this
duration = movie.duration.to_i
1.upto(duration) do |i|
if i % 10 == 0
movie.transcode(File.join(dir, "#{i}.jpg"), "-itsoffset -#{i} -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240")
end
end

The problem is it seems that itsoffset has to be before the -i filename.
I did several tests in zsh and this one works
ffmpeg -y -itsoffset -9 -i IMGP3577.avi -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 60.jpg

And this one don't works
ffmpeg -y -i IMGP3577.avi -itsoffset -9 -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 60.jpg

If you have any idea

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.