vidibus-mp4_encoder 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/Rakefile +0 -8
  2. data/lib/vidibus/mp4_encoder.rb +55 -35
  3. metadata +96 -120
data/Rakefile CHANGED
@@ -7,12 +7,6 @@ require 'rspec/core/rake_task'
7
7
 
8
8
  Bundler::GemHelper.install_tasks
9
9
 
10
- RSpec::Core::RakeTask.new(:rcov) do |t|
11
- t.pattern = 'spec/**/*_spec.rb'
12
- t.rcov = true
13
- t.rcov_opts = ['--exclude', '^spec,/gems/']
14
- end
15
-
16
10
  Rake::RDocTask.new do |rdoc|
17
11
  rdoc.rdoc_dir = 'rdoc'
18
12
  rdoc.title = 'Vidibus::Mp4Encoder'
@@ -20,5 +14,3 @@ Rake::RDocTask.new do |rdoc|
20
14
  rdoc.rdoc_files.include('lib/**/*.rb')
21
15
  rdoc.options << '--charset=utf-8'
22
16
  end
23
-
24
- task :default => :rcov
@@ -2,15 +2,15 @@ module Vidibus
2
2
  class Mp4Encoder < Vidibus::Encoder::Base
3
3
  class ProfileError < Vidibus::Encoder::ProfileError; end
4
4
 
5
- VERSION = '0.1.1'
6
-
7
- DEFAULT_AUDIO_CODEC = 'aac'
8
- DEFAULT_VIDEO_CODEC = 'h264'
9
- DEFAULT_VIDEO_PROFILE = 'main'
10
- DEFAULT_VIDEO_CODEC_LEVEL = '3.1'
11
- DEFAULT_PRESETS = {
12
- :baseline => 'coder=0 bf=0 flags2=-wpred-dct8x8',
13
- :main => 'coder=1 flags=+loop cmp=+chroma partitions=+parti8x8+parti4x4+partp8x8+partb8x8 me_method=hex subq=7 i_qfactor=0.71 directpred=1 flags2=+wpred+fastpskip-dct8x8'
5
+ VERSION = '0.1.2'
6
+
7
+ AUDIO_CODEC = 'aac'
8
+ VIDEO_CODEC = 'h264'
9
+ VIDEO_PROFILE = 'main'
10
+ VIDEO_CODEC_LEVEL = '3.2'
11
+ VIDEO_FILTER = {
12
+ :baseline => 'yadif=0:-1:1,hqdn3d=1.5:1.5:6:6',
13
+ :main => 'yadif=0:-1:1'
14
14
  }
15
15
 
16
16
  # Common profile settings.
@@ -97,12 +97,14 @@ module Vidibus
97
97
 
98
98
  private
99
99
 
100
+ flag(:offset) { |value| "-ss #{value}" }
101
+ flag(:duration) { |value| "-t #{value}" }
100
102
  flag(:audio_bit_rate) { |value| "-ab #{value}" }
101
103
  flag(:audio_channels) { |value| "-ac #{value}" }
102
104
  flag(:audio_sample_rate) { |value| "-ar #{value}" }
103
105
  flag(:aspect_ratio) { |value| "-aspect #{value}" }
104
- flag(:video_profile) { |value| "-vprofile #{value}" }
105
- flag(:video_codec_level) { |value| "-vlevel #{value}" }
106
+ flag(:video_profile) { |value| "-profile:v #{value}" }
107
+ flag(:video_codec_level) { |value| "-level:v #{value}" }
106
108
 
107
109
  flag(:video_bit_rate) do |value|
108
110
  output = "-vb #{value}"
@@ -114,9 +116,11 @@ module Vidibus
114
116
 
115
117
  # Set dimensions and aspect ratio to remove anamorphosis.
116
118
  flag(:dimensions) do
117
- modulus = profile.dimensions_modulus || 8
118
- value = profile.dimensions(modulus)
119
- "-s #{value} -aspect #{profile.aspect_ratio(modulus)}"
119
+ unless copy_video?
120
+ modulus = profile.dimensions_modulus || 8
121
+ value = profile.dimensions(modulus)
122
+ "-s #{value} -aspect #{profile.aspect_ratio(modulus)}"
123
+ end
120
124
  end
121
125
 
122
126
  # Try to find a matching frame rate, if several ones are given. If no
@@ -131,42 +135,55 @@ module Vidibus
131
135
  "-r #{value} -g #{gop} -keyint_min #{gop}"
132
136
  end
133
137
 
134
- # Convert the preset args
135
- flag(:preset) do |value|
136
- '-' + value.gsub(/\s+/, ' -').gsub(/\=/, ' ')
137
- end
138
-
139
138
  flag(:audio_codec) do |value|
140
- if value == 'aac'
141
- 'libfaac'
139
+ case value
140
+ when 'copy' then 'copy'
141
+ when 'aac', 'libfaac' then 'libfaac'
142
+ when 'mp3', 'libmp3lame' then 'libmp3lame'
143
+ when 'libfdk_aac' then 'libfdk_aac'
142
144
  else
143
- raise 'aac is the only audio codec supported right now'
145
+ raise 'unsupported audio codec'
144
146
  end
145
147
  end
146
148
 
147
149
  flag(:video_codec) do |value|
148
- if value == 'h264'
149
- 'libx264'
150
+ case value
151
+ when 'copy' then 'copy'
152
+ when 'h264', 'libx264' then 'libx264'
150
153
  else
151
- raise 'h264 is the only video codec supported right now'
154
+ raise 'Unsupported video codec'
152
155
  end
153
156
  end
154
157
 
158
+ flag(:video_filter) do |value|
159
+ %(-filter:v "#{value}")
160
+ end
161
+
162
+ def copy_video?
163
+ profile.settings[:video_codec] == 'copy'
164
+ end
165
+
166
+ def copy_audio?
167
+ profile.settings[:audio_codec] == 'copy'
168
+ end
169
+
155
170
  # Set default options for current profile:
156
171
  #
157
172
  # audio_codec: 'aac'
158
173
  # video_codec: 'h264'
159
174
  # video_profile: 'main'
160
- # video_codec_level: '3.1'
175
+ # video_codec_level: '3.2'
161
176
  # preset: [the :main present]
162
177
  def preprocess
163
- profile.settings[:audio_codec] ||= DEFAULT_AUDIO_CODEC
164
- profile.settings[:video_codec] ||= DEFAULT_VIDEO_CODEC
165
- profile.settings[:video_profile] ||= DEFAULT_VIDEO_PROFILE
166
- profile.settings[:video_codec_level] ||= begin
167
- profile.video_profile.to_s == 'baseline' ? '3.0': DEFAULT_VIDEO_CODEC_LEVEL
178
+ profile.settings[:audio_codec] ||= AUDIO_CODEC
179
+ profile.settings[:video_codec] ||= VIDEO_CODEC
180
+ unless copy_video?
181
+ profile.settings[:video_profile] ||= VIDEO_PROFILE
182
+ profile.settings[:video_codec_level] ||= begin
183
+ profile.video_profile.to_s == 'baseline' ? '3.0': VIDEO_CODEC_LEVEL
184
+ end
185
+ profile.settings[:video_filter] ||= VIDEO_FILTER[profile.video_profile.to_sym]
168
186
  end
169
- profile.settings[:preset] ||= DEFAULT_PRESETS[profile.video_profile.to_sym]
170
187
  super
171
188
  end
172
189
 
@@ -181,9 +198,12 @@ module Vidibus
181
198
 
182
199
  # The encoding recipe.
183
200
  def recipe
184
- audio = %(-acodec %{audio_codec} %{audio_sample_rate} %{audio_bit_rate} %{audio_channels} -async 2)
185
- video = %(-vcodec %{video_codec} %{dimensions} %{video_bit_rate} %{frame_rate} %{video_profile} %{video_codec_level} -deinterlace %{preset})
186
- "ffmpeg -i %{input} #{audio} #{video} -y -threads 0 %{output}"
201
+ audio = %(-acodec %{audio_codec} %{audio_sample_rate} %{audio_bit_rate} %{audio_channels})
202
+ unless copy_audio?
203
+ audio << ' -async 2'
204
+ end
205
+ video = %(-vcodec %{video_codec} %{dimensions} %{video_filter} %{video_bit_rate} %{frame_rate} %{video_profile} %{video_codec_level})
206
+ "ffmpeg -i %{input} %{offset} %{duration} #{audio} #{video} -y -threads 0 %{output}"
187
207
  end
188
208
  end
189
209
  end
metadata CHANGED
@@ -1,172 +1,148 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: vidibus-mp4_encoder
3
- version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
13
- - "Andr\xC3\xA9 Pankratz"
7
+ authors:
8
+ - André Pankratz
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-04-21 00:00:00 +02:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2013-08-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: vidibus-encoder
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
33
22
  type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: bundler
37
23
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
39
33
  none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 23
44
- segments:
45
- - 1
46
- - 0
47
- - 0
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
48
37
  version: 1.0.0
49
38
  type: :development
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: rake
53
39
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
55
41
  none: false
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- hash: 3
60
- segments:
61
- - 0
62
- version: "0"
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.0.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
63
54
  type: :development
64
- version_requirements: *id003
65
- - !ruby/object:Gem::Dependency
66
- name: rdoc
67
55
  prerelease: false
68
- requirement: &id004 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
69
57
  none: false
70
- requirements:
71
- - - ">="
72
- - !ruby/object:Gem::Version
73
- hash: 3
74
- segments:
75
- - 0
76
- version: "0"
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rdoc
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
77
70
  type: :development
78
- version_requirements: *id004
79
- - !ruby/object:Gem::Dependency
80
- name: rcov
81
71
  prerelease: false
82
- requirement: &id005 !ruby/object:Gem::Requirement
72
+ version_requirements: !ruby/object:Gem::Requirement
83
73
  none: false
84
- requirements:
85
- - - ">="
86
- - !ruby/object:Gem::Version
87
- hash: 3
88
- segments:
89
- - 0
90
- version: "0"
91
- type: :development
92
- version_requirements: *id005
93
- - !ruby/object:Gem::Dependency
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
94
79
  name: rspec
95
- prerelease: false
96
- requirement: &id006 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
97
81
  none: false
98
- requirements:
82
+ requirements:
99
83
  - - ~>
100
- - !ruby/object:Gem::Version
101
- hash: 7
102
- segments:
103
- - 2
104
- version: "2"
84
+ - !ruby/object:Gem::Version
85
+ version: '2'
105
86
  type: :development
106
- version_requirements: *id006
107
- - !ruby/object:Gem::Dependency
108
- name: rr
109
87
  prerelease: false
110
- requirement: &id007 !ruby/object:Gem::Requirement
88
+ version_requirements: !ruby/object:Gem::Requirement
111
89
  none: false
112
- requirements:
113
- - - ">="
114
- - !ruby/object:Gem::Version
115
- hash: 3
116
- segments:
117
- - 0
118
- version: "0"
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '2'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rr
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
119
102
  type: :development
120
- version_requirements: *id007
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
121
110
  description: MP4 (H.264) Encoder
122
111
  email: andre@vidibus.com
123
112
  executables: []
124
-
125
113
  extensions: []
126
-
127
114
  extra_rdoc_files: []
128
-
129
- files:
115
+ files:
130
116
  - lib/vidibus/mp4_encoder.rb
131
117
  - lib/vidibus-mp4_encoder.rb
132
118
  - LICENSE
133
119
  - README.md
134
120
  - Rakefile
135
- has_rdoc: true
136
121
  homepage: https://github.com/vidibus/vidibus-mp4_encoder
137
122
  licenses: []
138
-
139
123
  post_install_message:
140
124
  rdoc_options: []
141
-
142
- require_paths:
125
+ require_paths:
143
126
  - lib
144
- required_ruby_version: !ruby/object:Gem::Requirement
127
+ required_ruby_version: !ruby/object:Gem::Requirement
145
128
  none: false
146
- requirements:
147
- - - ">="
148
- - !ruby/object:Gem::Version
149
- hash: 3
150
- segments:
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ segments:
151
134
  - 0
152
- version: "0"
153
- required_rubygems_version: !ruby/object:Gem::Requirement
135
+ hash: -4467260920181881587
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
154
137
  none: false
155
- requirements:
156
- - - ">="
157
- - !ruby/object:Gem::Version
158
- hash: 23
159
- segments:
160
- - 1
161
- - 3
162
- - 6
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
163
141
  version: 1.3.6
164
142
  requirements: []
165
-
166
143
  rubyforge_project: vidibus-mp4_encoder
167
- rubygems_version: 1.3.7
144
+ rubygems_version: 1.8.24
168
145
  signing_key:
169
146
  specification_version: 3
170
147
  summary: MP4 (H.264) Encoder
171
148
  test_files: []
172
-