video_converter 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -31,7 +31,7 @@ module VideoConverter
31
31
  self.split_command = '%{bin} -fflags +genpts -i %{input} %{options} %{output} 1>>%{log} 2>&1 || exit 1'
32
32
  self.concat_command = "%{bin} -f concat -i %{input} %{options} %{output} 1>>%{log} 2>&1 || exit 1"
33
33
  self.mux_command = "%{bin} %{inputs} %{maps} %{options} %{output} 1>>%{log} 2>&1 || exit 1"
34
- self.volume_detect_command = "%{bin} -i %{input} -af volumedetect -f null - 2>&1"
34
+ self.volume_detect_command = "%{bin} -i %{input} -af volumedetect -c:v copy -f null - 2>&1"
35
35
 
36
36
  def self.split(input, output)
37
37
  output.options = { :format => 'segment', :map => 0, :codec => 'copy' }.merge(output.options)
@@ -71,12 +71,14 @@ module VideoConverter
71
71
  filter_complex = [output.options[:filter_complex]].compact
72
72
  filter_complex << "crop=#{output.crop}" if output.crop
73
73
  if output.width || output.height
74
- video_stream = input.metadata[:video_streams].first
75
- width, height = (video_stream[:dar_width] || video_stream[:width]).to_f, (video_stream[:dar_height] || video_stream[:height]).to_f
76
- output.width = (output.height * width / height / 2).to_i * 2 if output.height && !output.width
77
- output.height = (output.width * height / width / 2).to_i * 2 if output.width && !output.height
74
+ output.width = (output.height * aspect(input, output)).ceil / 2 * 2 if output.height && !output.width
75
+ output.height = (output.width / aspect(input, output)).ceil / 2 * 2 if output.width && !output.height
78
76
  filter_complex << "scale=#{scale(output.width, :w)}:#{scale(output.height, :h)}"
79
- filter_complex << "setdar=#{video_stream[:dar_width]}:#{video_stream[:dar_height]}" if video_stream[:dar_width] && video_stream[:dar_height]
77
+ if output.options[:aspect]
78
+ filter_complex << "setdar=#{output.options.delete(:aspect)}"
79
+ elsif input.video_stream[:dar_width] && input.video_stream[:dar_height]
80
+ filter_complex << "setdar=#{input.video_stream[:dar_width]}:#{input.video_stream[:dar_height]}"
81
+ end
80
82
  end
81
83
  if output.watermarks && (output.watermarks[:width] || output.watermarks[:height])
82
84
  filter_complex = ["[0:v] #{filter_complex.join(',')} [main]"]
@@ -222,5 +224,17 @@ module VideoConverter
222
224
  level
223
225
  end
224
226
  end
227
+
228
+ def aspect(input, output)
229
+ if aspect = output.options[:aspect]
230
+ if matches = aspect.to_s.match(/^(\d+):(\d+)$/)
231
+ matches[1].to_f / matches[2].to_f
232
+ else
233
+ Float(aspect)
234
+ end
235
+ else
236
+ (input.video_stream[:dar_width] || input.video_stream[:width]).to_f / (input.video_stream[:dar_height] || input.video_stream[:height]).to_f
237
+ end
238
+ end
225
239
  end
226
240
  end
@@ -66,6 +66,10 @@ module VideoConverter
66
66
  @metadata
67
67
  end
68
68
 
69
+ def video_stream
70
+ metadata[:video_streams].first
71
+ end
72
+
69
73
  def mean_volume
70
74
  @mean_volume ||= Command.new(Ffmpeg.volume_detect_command, :bin => Ffmpeg.bin, :input => input).capture.match(/mean_volume:\s([-\d.]+)\sdB/).to_a[1]
71
75
  end
@@ -1,3 +1,3 @@
1
1
  module VideoConverter
2
- VERSION = "0.8.0"
2
+ VERSION = "0.8.1"
3
3
  end
@@ -25,6 +25,42 @@ class VideoConverterTest < Test::Unit::TestCase
25
25
  assert_equal %w(. .. scr004.jpg scr004_norm.jpg scr005.jpg scr005_norm.jpg).sort, Dir.entries(File.join(@c.outputs.first.work_dir, 'thumbnails')).sort
26
26
  end
27
27
  end
28
+
29
+ context 'with aspect' do
30
+ setup do
31
+ (@c = VideoConverter.new(
32
+ :input => 'test/fixtures/test (1).mp4',
33
+ :outputs => [
34
+ { :video_bitrate => 300, :filename => 'res.mp4', :aspect => '4:3' },
35
+ ]
36
+ )).run
37
+ end
38
+
39
+ should 'change aspect' do
40
+ m = VideoConverter.new(:input => @c.outputs.first.ffmpeg_output).inputs.first.video_stream
41
+ assert_equal 4, m[:dar_width].to_i
42
+ assert_equal 3, m[:dar_height].to_i
43
+ end
44
+ end
45
+
46
+ context 'with aspect and resize' do
47
+ setup do
48
+ (@c = VideoConverter.new(
49
+ :input => 'test/fixtures/test (1).mp4',
50
+ :outputs => [
51
+ { :video_bitrate => 300, :filename => 'res.mp4', :aspect => '4:3', :height => 240 },
52
+ ]
53
+ )).run
54
+ end
55
+
56
+ should 'change aspect and resolution' do
57
+ m = VideoConverter.new(:input => @c.outputs.first.ffmpeg_output).inputs.first.video_stream
58
+ assert_equal 4, m[:dar_width].to_i
59
+ assert_equal 3, m[:dar_height].to_i
60
+ assert_equal 320, m[:width].to_i
61
+ assert_equal 240, m[:height].to_i
62
+ end
63
+ end
28
64
  end
29
65
 
30
66
  context 'segmentation' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: video_converter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-24 00:00:00.000000000 Z
12
+ date: 2014-11-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: video_screenshoter
@@ -142,7 +142,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
142
142
  version: '0'
143
143
  segments:
144
144
  - 0
145
- hash: 2160906061662950076
145
+ hash: -2686683982963894083
146
146
  required_rubygems_version: !ruby/object:Gem::Requirement
147
147
  none: false
148
148
  requirements:
@@ -151,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
151
  version: '0'
152
152
  segments:
153
153
  - 0
154
- hash: 2160906061662950076
154
+ hash: -2686683982963894083
155
155
  requirements:
156
156
  - ffmpeg, version 1.2 or greated configured with libx264 and libfaac
157
157
  - live_segmenter to convert to hls