streamio-ffmpeg 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.2.0 2009-02-06
2
+
3
+ * Some more metadata parsing
4
+
1
5
  == 0.1.0 2009-02-05
2
6
 
3
7
  * Some basic parsing of metadata added
data/README.rdoc CHANGED
@@ -11,18 +11,24 @@ Simplest possible wrapper around FFMPEG to get metadata from movie files and do
11
11
  == Usage
12
12
 
13
13
  movie = FFMPEG::Movie.new("path/to/movie.mov")
14
- movie.duration # Duration of the movie in seconds
15
- movie.width # Width of the movie in pixels
16
- movie.height # Height of the movie in pixels
17
-
18
- == Note on Patches/Pull Requests
19
-
20
- * Fork the project.
21
- * Make your feature addition or bug fix.
22
- * Add specs for it. This is important so I don't break it in a future version unintentionally.
23
- * Commit, do not mess with rakefile, version, or history.
24
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
25
- * Send me a pull request. Bonus points for topic branches.
14
+
15
+ movie.duration # 7.5 (duration of the movie in seconds)
16
+ movie.bitrate # 481 (bitrate in kb/s)
17
+
18
+ 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)
19
+ movie.video_codec # "h264"
20
+ movie.colorspace # "yuv420p"
21
+ movie.resolution # "640x480"
22
+ movie.width # 640 (width of the movie in pixels)
23
+ movie.height # 480 (height of the movie in pixels)
24
+ movie.frame_rate # 16.72 (frames per second)
25
+
26
+ movie.audio_stream # "aac, 44100 Hz, stereo, s16, 75 kb/s" (raw audio stream info)
27
+ movie.audio_codec # "aac"
28
+ movie.audio_sample_rate # 44100
29
+ movie.audio_channels # 2
30
+
31
+ movie.valid? # true (would be false if ffmpeg fails to read the movie)
26
32
 
27
33
  == Copyright
28
34
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
data/lib/ffmpeg/movie.rb CHANGED
@@ -2,7 +2,9 @@ require 'open3'
2
2
 
3
3
  module FFMPEG
4
4
  class Movie
5
- attr_reader :duration, :video_stream, :audio_stream, :video_codec, :colorspace, :resolution
5
+ attr_reader :duration, :bitrate
6
+ attr_reader :video_stream, :video_codec, :colorspace, :resolution
7
+ attr_reader :audio_stream, :audio_codec, :audio_sample_rate
6
8
 
7
9
  def initialize(path)
8
10
  raise Errno::ENOENT, "the file '#{path}' does not exist" unless File.exists?(path)
@@ -15,6 +17,9 @@ module FFMPEG
15
17
  output[/Duration: (\d{2}):(\d{2}):(\d{2}\.\d{1})/]
16
18
  @duration = ($1.to_i*60*60) + ($2.to_i*60) + $3.to_f
17
19
 
20
+ output[/bitrate: (\d*)/]
21
+ @bitrate = $1 ? $1.to_i : nil
22
+
18
23
  output[/Video: (.*)/]
19
24
  @video_stream = $1
20
25
 
@@ -25,6 +30,11 @@ module FFMPEG
25
30
  @video_codec, @colorspace, resolution = video_stream.split(/\s?,\s?/)
26
31
  @resolution = resolution.split(" ").first # get rid of [PAR 1:1 DAR 16:9]
27
32
  end
33
+
34
+ if audio_stream
35
+ @audio_codec, audio_sample_rate, @audio_channels = audio_stream.split(/\s?,\s?/)
36
+ @audio_sample_rate = audio_sample_rate[/\d*/].to_i
37
+ end
28
38
  end
29
39
 
30
40
  def valid?
@@ -38,5 +48,15 @@ module FFMPEG
38
48
  def height
39
49
  resolution.split("x")[1].to_i rescue nil
40
50
  end
51
+
52
+ def audio_channels
53
+ return @audio_channels[/\d*/].to_i if @audio_channels["channels"]
54
+ return 1 if @audio_channels["mono"]
55
+ return 2 if @audio_channels["stereo"]
56
+ end
57
+
58
+ def frame_rate
59
+ video_stream[/(\d*\.\d*)\s?fps/] ? $1.to_f : nil
60
+ end
41
61
  end
42
62
  end
@@ -23,19 +23,19 @@ module FFMPEG
23
23
  before(:all) do
24
24
  @movie = Movie.new("#{fixture_path}/movies/awesome.mov")
25
25
  end
26
-
26
+
27
27
  it "should parse duration to number of seconds" do
28
28
  @movie.duration.should == 7.5
29
29
  end
30
+
31
+ it "should parse the bitrate" do
32
+ @movie.bitrate.should == 481
33
+ end
30
34
 
31
35
  it "should parse video stream information" do
32
36
  @movie.video_stream.should == "h264, yuv420p, 640x480 [PAR 1:1 DAR 4:3], 371 kb/s, 16.75 fps, 15 tbr, 600 tbn, 1200 tbc"
33
37
  end
34
38
 
35
- it "should parse audio stream information" do
36
- @movie.audio_stream.should == "aac, 44100 Hz, stereo, s16, 75 kb/s"
37
- end
38
-
39
39
  it "should know the video codec" do
40
40
  @movie.video_codec.should == "h264"
41
41
  end
@@ -53,6 +53,26 @@ module FFMPEG
53
53
  @movie.height.should == 480
54
54
  end
55
55
 
56
+ it "should know the framerate" do
57
+ @movie.frame_rate.should == 16.75
58
+ end
59
+
60
+ it "should parse audio stream information" do
61
+ @movie.audio_stream.should == "aac, 44100 Hz, stereo, s16, 75 kb/s"
62
+ end
63
+
64
+ it "should know the audio codec" do
65
+ @movie.audio_codec.should == "aac"
66
+ end
67
+
68
+ it "should know the sample rate" do
69
+ @movie.audio_sample_rate.should == 44100
70
+ end
71
+
72
+ it "should know the number of audio channels" do
73
+ @movie.audio_channels.should == 2
74
+ end
75
+
56
76
  it "should should be valid" do
57
77
  @movie.should be_valid
58
78
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{streamio-ffmpeg}
8
- s.version = "0.1.0"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["David Backeus"]
12
- s.date = %q{2010-02-05}
12
+ s.date = %q{2010-02-06}
13
13
  s.description = %q{Simple wrapper around ffmpeg to get metadata from movies and do transcoding}
14
14
  s.email = %q{duztdruid@gmail.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: streamio-ffmpeg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Backeus
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-05 00:00:00 +01:00
12
+ date: 2010-02-06 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency