ffprober 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ffprober.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 beanieboi
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Ffprober
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'ffprober'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install ffprober
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task default: :spec
data/ffprober.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/ffprober/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["beanieboi"]
6
+ gem.email = ["beanie@benle.de"]
7
+ gem.description = %q{a Ruby wrapper for ffprobe}
8
+ gem.summary = %q{a Ruby wrapper for ffprobe (part of ffmpeg)}
9
+ gem.homepage = "https://github.com/beanieboi/ffprober"
10
+
11
+ gem.required_ruby_version = ">= 1.9.2"
12
+ gem.rubyforge_project = "ffprober"
13
+
14
+ gem.add_development_dependency "rspec", "~> 2.9"
15
+ gem.add_development_dependency 'rake', '~> 0.9'
16
+
17
+ gem.add_runtime_dependency 'multi_json', '~> 1.3'
18
+
19
+ gem.files = `git ls-files`.split($\)
20
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
21
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
22
+ gem.name = "ffprober"
23
+ gem.require_paths = ["lib"]
24
+ gem.version = Ffprober::VERSION
25
+ end
@@ -0,0 +1,7 @@
1
+ module Ffprober
2
+ class AudioStream < Stream
3
+ attr_accessor :sample_fmt, :sample_rate, :channels,
4
+ :bits_per_sample
5
+
6
+ end
7
+ end
@@ -0,0 +1,14 @@
1
+ module Ffprober
2
+ class Format
3
+ attr_accessor :filename, :nb_streams, :format_name,
4
+ :format_long_name, :start_time, :duration,
5
+ :size, :bit_rate
6
+
7
+ def initialize(object_attribute_hash)
8
+ object_attribute_hash.map do |(k, v)|
9
+ writer_m = "#{k}="
10
+ send(writer_m, v) if respond_to?(writer_m)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,38 @@
1
+ module Ffprober
2
+ class Parser
3
+ @@ffprobe_path = `which ffprobe`
4
+ @@options = '-v quiet -print_format json -show_format -show_streams'
5
+
6
+ def self.from_file(file_to_parse)
7
+ json_output = `#{@@ffprobe_path} #{@@options} #{@file_to_parse}`
8
+ from_json(json_output)
9
+ end
10
+
11
+ def self.from_json(json_to_parse)
12
+ parser = self.new
13
+ parser.parse(json_to_parse)
14
+ parser
15
+ end
16
+
17
+ def parse(json_to_parse)
18
+ raise ArgumentError.new("No JSON found") if json_to_parse.nil?
19
+ @video_json = MultiJson.load(json_to_parse, :symbolize_keys => true)
20
+ end
21
+
22
+ def format
23
+ Ffprober::Format.new(@video_json[:format])
24
+ end
25
+
26
+ def video_streams
27
+ @video_json[:streams].select { |stream| stream[:codec_type] == 'video'}.map do |s|
28
+ Ffprober::VideoStream.new(s)
29
+ end
30
+ end
31
+
32
+ def audio_streams
33
+ @video_json[:streams].select { |stream| stream[:codec_type] == 'audio'}.map do |s|
34
+ Ffprober::AudioStream.new(s)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,16 @@
1
+ module Ffprober
2
+ class Stream
3
+ attr_accessor :codec_name, :codec_long_name, :codec_type,
4
+ :codec_time_base, :codec_tag_string, :codec_tag,
5
+ :r_frame_rate, :avg_frame_rate,
6
+ :time_base, :start_time, :duration,
7
+ :nb_frames
8
+
9
+ def initialize(object_attribute_hash)
10
+ object_attribute_hash.map do |(k, v)|
11
+ writer_m = "#{k}="
12
+ send(writer_m, v) if respond_to?(writer_m)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module Ffprober
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,7 @@
1
+ module Ffprober
2
+ class VideoStream < Stream
3
+ attr_accessor :width, :height, :has_b_frames,
4
+ :sample_aspect_ratio, :display_aspect_ratio,
5
+ :pix_fmt, :level, :is_avc, :nal_length_size
6
+ end
7
+ end
data/lib/ffprober.rb ADDED
@@ -0,0 +1,10 @@
1
+ require "ffprober/version"
2
+ require "ffprober/parser"
3
+ require "ffprober/format"
4
+ require "ffprober/stream"
5
+ require "ffprober/audio_stream"
6
+ require "ffprober/video_stream"
7
+ require 'multi_json'
8
+
9
+ module Ffprober
10
+ end
@@ -0,0 +1,74 @@
1
+ {
2
+ "streams": [
3
+ {
4
+ "index": 0,
5
+ "codec_name": "h264",
6
+ "codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
7
+ "codec_type": "video",
8
+ "codec_time_base": "1/180000",
9
+ "codec_tag_string": "avc1",
10
+ "codec_tag": "0x31637661",
11
+ "width": 960,
12
+ "height": 600,
13
+ "has_b_frames": 2,
14
+ "sample_aspect_ratio": "1:1",
15
+ "display_aspect_ratio": "8:5",
16
+ "pix_fmt": "yuv420p",
17
+ "level": 31,
18
+ "is_avc": "1",
19
+ "nal_length_size": "4",
20
+ "r_frame_rate": "25/1",
21
+ "avg_frame_rate": "320805000/44607683",
22
+ "time_base": "1/90000",
23
+ "start_time": "0.000000",
24
+ "duration": "991.281844",
25
+ "nb_frames": "7129",
26
+ "tags": {
27
+ "creation_time": "2011-11-21 06:45:09",
28
+ "language": "und",
29
+ "handler_name": ""
30
+ }
31
+ },
32
+ {
33
+ "index": 1,
34
+ "codec_name": "aac",
35
+ "codec_long_name": "Advanced Audio Coding",
36
+ "codec_type": "audio",
37
+ "codec_time_base": "1/48000",
38
+ "codec_tag_string": "mp4a",
39
+ "codec_tag": "0x6134706d",
40
+ "sample_fmt": "s16",
41
+ "sample_rate": "48000",
42
+ "channels": 1,
43
+ "bits_per_sample": 0,
44
+ "r_frame_rate": "0/0",
45
+ "avg_frame_rate": "375/8",
46
+ "time_base": "1/48000",
47
+ "start_time": "0.000000",
48
+ "duration": "991.338667",
49
+ "nb_frames": "46469",
50
+ "tags": {
51
+ "creation_time": "2011-11-21 06:45:09",
52
+ "language": "eng",
53
+ "handler_name": ""
54
+ }
55
+ }
56
+ ],
57
+ "format": {
58
+ "filename": "301-extracting-a-ruby-gem.mp4",
59
+ "nb_streams": 2,
60
+ "format_name": "mov,mp4,m4a,3gp,3g2,mj2",
61
+ "format_long_name": "QuickTime/MPEG-4/Motion JPEG 2000 format",
62
+ "start_time": "0.000000",
63
+ "duration": "991.338667",
64
+ "size": "44772490",
65
+ "bit_rate": "361309",
66
+ "tags": {
67
+ "major_brand": "mp42",
68
+ "minor_version": "0",
69
+ "compatible_brands": "mp42isomavc1",
70
+ "creation_time": "2011-11-21 06:45:09",
71
+ "encoder": "HandBrake 0.9.5 2011010300"
72
+ }
73
+ }
74
+ }
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Ffprober do
5
+ before :each do
6
+ @ffprobe = Ffprober::Parser.from_json(File.read('spec/assets/301-extracting_a_ruby_gem.json'))
7
+ end
8
+
9
+ describe "format" do
10
+ it "should determine the correct filename" do
11
+ @ffprobe.format.filename.should eq("301-extracting-a-ruby-gem.mp4")
12
+ end
13
+
14
+ it "should find the correct size" do
15
+ @ffprobe.format.size.should eq("44772490")
16
+ end
17
+
18
+ it "should find the correct bit_rate" do
19
+ @ffprobe.format.bit_rate.should eq("361309")
20
+ end
21
+ end
22
+
23
+ describe "audio_streams" do
24
+ it "should determine the correct number of audio streams" do
25
+ @ffprobe.audio_streams.count.should eq(1)
26
+ end
27
+
28
+ it "should determine the correct sample rate of the first audio stream" do
29
+ @ffprobe.audio_streams.first.sample_rate.should eq("48000")
30
+ end
31
+
32
+ end
33
+
34
+ describe "video_streams" do
35
+ it "should determine the correct width of the first video streams" do
36
+ @ffprobe.video_streams.first.width.should eq(960)
37
+ end
38
+
39
+ it "should determine the correct width of the first video streams" do
40
+ @ffprobe.video_streams.first.height.should eq(600)
41
+ end
42
+
43
+ it "should determine the correct number of video streams" do
44
+ @ffprobe.video_streams.count.should eq(1)
45
+ end
46
+ end
47
+
48
+ end
@@ -0,0 +1 @@
1
+ require 'ffprober'
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ffprober
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - beanieboi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70161613079940 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.9'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70161613079940
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &70161613077620 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '0.9'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70161613077620
36
+ - !ruby/object:Gem::Dependency
37
+ name: multi_json
38
+ requirement: &70161613076500 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '1.3'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70161613076500
47
+ description: a Ruby wrapper for ffprobe
48
+ email:
49
+ - beanie@benle.de
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - .rspec
56
+ - Gemfile
57
+ - LICENSE
58
+ - README.md
59
+ - Rakefile
60
+ - ffprober.gemspec
61
+ - lib/ffprober.rb
62
+ - lib/ffprober/audio_stream.rb
63
+ - lib/ffprober/format.rb
64
+ - lib/ffprober/parser.rb
65
+ - lib/ffprober/stream.rb
66
+ - lib/ffprober/version.rb
67
+ - lib/ffprober/video_stream.rb
68
+ - spec/assets/301-extracting_a_ruby_gem.json
69
+ - spec/ffprober_spec.rb
70
+ - spec/spec_helper.rb
71
+ homepage: https://github.com/beanieboi/ffprober
72
+ licenses: []
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: 1.9.2
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project: ffprober
91
+ rubygems_version: 1.8.17
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: a Ruby wrapper for ffprobe (part of ffmpeg)
95
+ test_files:
96
+ - spec/assets/301-extracting_a_ruby_gem.json
97
+ - spec/ffprober_spec.rb
98
+ - spec/spec_helper.rb