web_video 1.0.0 → 1.1.0

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.
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 Brainberry
1
+ Copyright (c) 2011 Aimbulance
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -78,8 +78,9 @@ Generate flv file. Next example will generate "demo.flv" from "demo.avi".
78
78
 
79
79
  Generate images from video
80
80
  By default screenshot starts at '00:00:01', to change it pass option :at => '00:05:00' (at five minutes)
81
+ Or you can pass :at => :center, to get screenshot from video center
81
82
 
82
- transcoder.screenshot("demo.jpg", :resolution => "480x360")
83
+ transcoder.screenshot("demo.jpg", :resolution => "480x360", :at => :center)
83
84
 
84
85
  Next code will generate five images: demo_01.jpg, demo_02.jpg, demo_03.jpg ...
85
86
 
@@ -104,4 +105,4 @@ Next code will generate five images: demo_01.jpg, demo_02.jpg, demo_03.jpg ...
104
105
  4. Write more documentation
105
106
  5. Write tests
106
107
 
107
- Copyright (c) 2010 Brainberry, released under the MIT license
108
+ Copyright (c) 2011 Aimbulance, released under the MIT license
data/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'rake'
2
2
  require 'rake/testtask'
3
3
  require 'rake/rdoctask'
4
+ require File.join(File.dirname(__FILE__), 'lib', 'web_video', 'version')
4
5
 
5
6
  desc 'Default: run unit tests.'
6
7
  task :default => :test
@@ -26,13 +27,13 @@ begin
26
27
  require 'jeweler'
27
28
  Jeweler::Tasks.new do |gemspec|
28
29
  gemspec.name = "web_video"
29
- gemspec.version = '1.0.0'
30
+ gemspec.version = WebVideo::VERSION.dup
30
31
  gemspec.summary = "WebVideo allows you to inspect and process video files"
31
32
  gemspec.description = "WebVideo allows you to inspect, convert and take screenshots from video files"
32
33
  gemspec.email = "galeta.igor@gmail.com"
33
34
  gemspec.homepage = "http://github.com/galetahub/web_video"
34
35
  gemspec.authors = ["Igor Galeta"]
35
- gemspec.files = FileList["[A-Z]*", "{lib}/**/*"]
36
+ gemspec.files = FileList["[A-Z]*", "{lib, test}/**/*"]
36
37
  gemspec.rubyforge_project = "web_video"
37
38
  end
38
39
 
@@ -1,7 +1,7 @@
1
1
  module WebVideo
2
2
  module Adapters
3
3
  class AbstractAdapter
4
- attr_accessor :filepath, :filename, :path
4
+ attr_accessor :filepath, :filename, :path, :video_streams
5
5
 
6
6
  def initialize(filepath, options = {})
7
7
  @filepath = filepath
@@ -33,6 +33,14 @@ module WebVideo
33
33
  @metadata[:streams]
34
34
  end
35
35
 
36
+ def video_stream
37
+ video_streams.first
38
+ end
39
+
40
+ def video_streams
41
+ @video_streams ||= streams.select{ |stream| stream.video? }
42
+ end
43
+
36
44
  def command_name
37
45
  ''
38
46
  end
@@ -52,7 +52,7 @@ module WebVideo
52
52
  if installed?
53
53
  metadata = {}
54
54
 
55
- ffmpeg_output = WebVideo::Tools.run(command_name, "-i #{@filepath}", [0,1])
55
+ ffmpeg_output = WebVideo::Tools.run(command_name, "-i #{@filepath.inspect}", [0,1])
56
56
 
57
57
  metadata[:duration] = $1 if ffmpeg_output =~ /Duration\: ([0-9][0-9]\:[0-9][0-9]\:[0-9][0-9]\.[0-9][0-9])\,/
58
58
  metadata[:bitrate] = $1 if ffmpeg_output =~ /\, bitrate\: (.*)$/
@@ -1,6 +1,6 @@
1
1
  module WebVideo
2
2
  class Stream
3
- attr_accessor :type, :codec, :details
3
+ attr_accessor :type, :codec, :details, :resolution
4
4
 
5
5
  #
6
6
  # stream = Stream.new :type => 'Video', :codec => 'mpeg4', :details => 'yuv420p, 640x480 [PAR 1:1 DAR 4:3], 30 tbr, 30 tbn, 30 tbc'
@@ -13,6 +13,7 @@ module WebVideo
13
13
  @type = options[:type].to_s.downcase
14
14
  @codec = options[:codec]
15
15
  @details = options[:details]
16
+ @resolution = extract_resolution_from_details(@details)
16
17
  end
17
18
 
18
19
  def video?
@@ -22,5 +23,21 @@ module WebVideo
22
23
  def audio?
23
24
  @type == 'audio'
24
25
  end
26
+
27
+ def width
28
+ @resolution ? @resolution[/^\d+/] : nil
29
+ end
30
+
31
+ def height
32
+ @resolution ? @resolution[/\d+$/] : nil
33
+ end
34
+
35
+ private
36
+ def extract_resolution_from_details(details)
37
+ return nil if details.blank?
38
+
39
+ result = details[/\s\d+x\d+\s/]
40
+ result.blank? ? nil : result.strip
41
+ end
25
42
  end
26
43
  end
@@ -41,14 +41,19 @@ module WebVideo
41
41
  # options:
42
42
  # :count - count images to generate
43
43
  # :format - image decoder
44
- # :at - time to start make screenshots from
44
+ # :at - sets that image should be taken from the point x seconds from the beginning
45
45
  # :resolution - image resolution
46
46
  def screenshot(destination, options = {}, &block)
47
- options.symbolize_keys!
47
+ options = {
48
+ :count => 1,
49
+ :format => "image2",
50
+ :at => "00:00:01"
51
+ }.merge(options.symbolize_keys)
48
52
 
49
- options[:count] ||= 1
50
- options[:format] ||= "image2"
51
- options[:at] ||= "00:00:01"
53
+ # Calculate middle video position
54
+ if options[:at].is_a?(Symbol) && [:center, :middle].include?(options[:at])
55
+ options[:at] = @source.duration_in_seconds / 2
56
+ end
52
57
 
53
58
  process(destination, @source.screenshot_command, options, &block)
54
59
  end
@@ -0,0 +1,3 @@
1
+ module WebVideo
2
+ VERSION = "1.1.0".freeze
3
+ end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web_video
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 19
5
+ prerelease:
5
6
  segments:
6
7
  - 1
8
+ - 1
7
9
  - 0
8
- - 0
9
- version: 1.0.0
10
+ version: 1.1.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Igor Galeta
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-05-07 00:00:00 +03:00
18
+ date: 2011-05-06 00:00:00 +03:00
18
19
  default_executable:
19
20
  dependencies: []
20
21
 
@@ -36,36 +37,40 @@ files:
36
37
  - lib/web_video/stream.rb
37
38
  - lib/web_video/tools.rb
38
39
  - lib/web_video/transcoder.rb
40
+ - lib/web_video/version.rb
39
41
  has_rdoc: true
40
42
  homepage: http://github.com/galetahub/web_video
41
43
  licenses: []
42
44
 
43
45
  post_install_message:
44
- rdoc_options:
45
- - --charset=UTF-8
46
+ rdoc_options: []
47
+
46
48
  require_paths:
47
49
  - lib
48
50
  required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
49
52
  requirements:
50
53
  - - ">="
51
54
  - !ruby/object:Gem::Version
55
+ hash: 3
52
56
  segments:
53
57
  - 0
54
58
  version: "0"
55
59
  required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
56
61
  requirements:
57
62
  - - ">="
58
63
  - !ruby/object:Gem::Version
64
+ hash: 3
59
65
  segments:
60
66
  - 0
61
67
  version: "0"
62
68
  requirements: []
63
69
 
64
70
  rubyforge_project: web_video
65
- rubygems_version: 1.3.6
71
+ rubygems_version: 1.6.2
66
72
  signing_key:
67
73
  specification_version: 3
68
74
  summary: WebVideo allows you to inspect and process video files
69
- test_files:
70
- - test/web_video_test.rb
71
- - test/test_helper.rb
75
+ test_files: []
76
+
@@ -1,3 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'active_support'
@@ -1,8 +0,0 @@
1
- require 'test_helper'
2
-
3
- class WebVideoTest < ActiveSupport::TestCase
4
- # Replace this with your real tests.
5
- test "the truth" do
6
- assert true
7
- end
8
- end