aviglitch 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,3 +1,10 @@
1
+ == 0.1.2 / 2011-04-10
2
+
3
+ * Fix to be able to handle data with offsets from 0 of the file.
4
+ * Added clear_keyframes! method to AviGlitch::Frames and AviGlitch::Base.
5
+ * Changed to be able to access frame's meta data.
6
+ * Changed datamosh command to handle wildcard char.
7
+
1
8
  == 0.1.1 / 2010-09-09
2
9
 
3
10
  * Fixed a bug with windows.
data/Rakefile CHANGED
@@ -7,11 +7,12 @@ begin
7
7
  gem.name = "aviglitch"
8
8
  gem.summary = "A Ruby library to destroy your AVI files."
9
9
  gem.email = "ucnvvv@gmail.com"
10
- gem.homepage = "http://github.com/ucnv/aviglitch"
10
+ gem.homepage = "http://ucnv.github.com/aviglitch/"
11
11
  gem.authors = ["ucnv"]
12
12
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
13
  gem.files = %w(README.rdoc ChangeLog Rakefile VERSION) +
14
14
  Dir.glob("{bin,spec,lib}/**/*")
15
+ gem.add_development_dependency "rspec", ">= 2.0.0"
15
16
 
16
17
  end
17
18
 
@@ -19,14 +20,12 @@ rescue LoadError
19
20
  puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
20
21
  end
21
22
 
22
- require 'spec/rake/spectask'
23
- Spec::Rake::SpecTask.new(:spec) do |spec|
24
- spec.libs << 'lib' << 'spec'
25
- spec.spec_files = FileList['spec/**/*_spec.rb']
23
+ require 'rspec/core/rake_task'
24
+ RSpec::Core::RakeTask.new(:spec) do |spec|
25
+ spec.pattern = FileList['spec/**/*_spec.rb']
26
26
  end
27
27
 
28
- Spec::Rake::SpecTask.new(:rcov) do |spec|
29
- spec.libs << 'lib' << 'spec'
28
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
30
29
  spec.pattern = 'spec/**/*_spec.rb'
31
30
  spec.rcov = true
32
31
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -26,7 +26,7 @@ opts = OptionParser.new do |opts|
26
26
  end
27
27
  end
28
28
 
29
- input = opts.parse!
29
+ input = Dir.glob opts.parse!
30
30
  if input.empty?
31
31
  puts opts
32
32
  exit 1
@@ -34,13 +34,16 @@ end
34
34
 
35
35
  a = AviGlitch.open input.shift
36
36
  a.glitch_with_index :keyframe do |frame, i|
37
- (!all && i == 0) ? frame : nil # keep the first frame
37
+ (!all && i == 0) ? frame : "" # keep the first frame
38
38
  end
39
+ a.clear_keyframes!(!all ? 1..a.frames.size : nil)
40
+
39
41
  input.each do |file|
40
42
  b = AviGlitch.open file
41
43
  b.glitch :keyframe do |frame|
42
- nil
44
+ ""
43
45
  end
46
+ b.clear_keyframes!
44
47
  a.frames.concat b.frames
45
48
  end
46
49
 
@@ -35,7 +35,7 @@ require 'aviglitch/tempfile'
35
35
  #
36
36
  module AviGlitch
37
37
 
38
- VERSION = '0.1.1'
38
+ VERSION = '0.1.2'
39
39
 
40
40
  class << self
41
41
  ##
@@ -33,9 +33,10 @@ module AviGlitch
33
33
 
34
34
  ##
35
35
  # Outputs the glitched file to +path+, and close the file.
36
- def output path
36
+ def output path, do_file_close = true
37
37
  FileUtils.cp @file.path, path
38
- close
38
+ close if do_file_close
39
+ self
39
40
  end
40
41
 
41
42
  ##
@@ -81,7 +82,13 @@ module AviGlitch
81
82
  self
82
83
  end
83
84
 
84
- alias_method :write, :output
85
+ ##
86
+ # Clears all (or in +range+) keyframes to deltaframes.
87
+ # It's an alias for Frames#clear_keyframes!
88
+ def clear_keyframes! range = nil
89
+ self.frames.clear_keyframes! range
90
+ self
91
+ end
85
92
 
86
93
  ##
87
94
  # Swaps the frames with other Frames data.
@@ -91,6 +98,8 @@ module AviGlitch
91
98
  @frames.concat other
92
99
  end
93
100
 
101
+ alias_method :write, :output
102
+
94
103
  def valid_target? target, frame #:nodoc:
95
104
  return true if target == :all
96
105
  begin
@@ -9,8 +9,7 @@ module AviGlitch
9
9
  AVIIF_KEYFRAME = 0x00000010
10
10
  AVIIF_NO_TIME = 0x00000100
11
11
 
12
- attr_accessor :data
13
- attr_reader :id, :flag
12
+ attr_accessor :data, :id, :flag
14
13
 
15
14
  ##
16
15
  # Creates a new AviGlitch::Frame object.
@@ -45,8 +45,9 @@ module AviGlitch
45
45
  :size => io.read(4).unpack('V').first,
46
46
  }
47
47
  end
48
+ fix_offsets_if_needed io
48
49
  unless safe_frames_count? @meta.size
49
- @io.close!
50
+ io.close!
50
51
  exit
51
52
  end
52
53
  io.rewind
@@ -78,6 +79,8 @@ module AviGlitch
78
79
  unless frame.data.nil?
79
80
  m[:offset] = io.pos + 4 # 4 for 'movi'
80
81
  m[:size] = frame.data.size
82
+ m[:flag] = frame.flag
83
+ m[:id] = frame.id
81
84
  io.print m[:id]
82
85
  io.print [frame.data.size].pack('V')
83
86
  io.print frame.data
@@ -320,6 +323,17 @@ module AviGlitch
320
323
  self.slice! n
321
324
  end
322
325
 
326
+ ##
327
+ # Modify keyframes to deltaframes at given range, or all.
328
+ def clear_keyframes! range = nil
329
+ range = 0..self.size if range.nil?
330
+ self.each_with_index do |frame, i|
331
+ if range.include? i
332
+ frame.flag = 0 if frame.is_keyframe?
333
+ end
334
+ end
335
+ end
336
+
323
337
  ##
324
338
  # Returns true if +other+'s frames are same as self's frames.
325
339
  def == other
@@ -332,6 +346,10 @@ module AviGlitch
332
346
  AviGlitch.open @io.path
333
347
  end
334
348
 
349
+ def inspect # :nodec:
350
+ "#<#{self.class.name}:#{sprintf("0x%x", object_id)} @io=#{@io.inspect} size=#{self.size}>"
351
+ end
352
+
335
353
  def get_beginning_and_length *args #:nodoc:
336
354
  b, l = args
337
355
  if args.first.kind_of? Range
@@ -362,7 +380,21 @@ module AviGlitch
362
380
  r
363
381
  end
364
382
 
383
+ def fix_offsets_if_needed io #:nodoc:
384
+ # rarely data offsets begin from 0 of the file
385
+ return if @meta.empty?
386
+ pos = io.pos
387
+ m = @meta.first
388
+ io.pos = @pos_of_movi + m[:offset]
389
+ unless io.read(4) == m[:id]
390
+ @meta.each do |x|
391
+ x[:offset] -= @pos_of_movi
392
+ end
393
+ end
394
+ io.pos = pos
395
+ end
396
+
365
397
  protected :frames_data_as_io, :meta
366
- private :overwrite, :get_beginning_and_length
398
+ private :overwrite, :get_beginning_and_length, :fix_offsets_if_needed
367
399
  end
368
400
  end
@@ -143,4 +143,24 @@ describe AviGlitch do
143
143
  AviGlitch::Base.surely_formatted?(@out, true).should be true
144
144
  end
145
145
 
146
+ it 'should clear keyframes with one method' do
147
+ a = AviGlitch.open @in
148
+ a.clear_keyframes!
149
+ a.output @out
150
+ a = AviGlitch.open @out
151
+ a.frames.each do |f|
152
+ f.is_keyframe?.should be false
153
+ end
154
+
155
+ a = AviGlitch.open @in
156
+ a.clear_keyframes! 0..50
157
+ a.output @out
158
+ a = AviGlitch.open @out
159
+ a.frames.each_with_index do |f, i|
160
+ if i <= 50
161
+ f.is_keyframe?.should be false
162
+ end
163
+ end
164
+ end
165
+
146
166
  end
@@ -31,21 +31,21 @@ describe AviGlitch, 'datamosh cli' do
31
31
 
32
32
  system [@cmd, @in].join(' ')
33
33
  o = AviGlitch.open @out
34
- o.frames.size.should == total - keys + 1
34
+ o.frames.size.should == total
35
35
  o.frames.first.is_keyframe?.should be true
36
36
  o.close
37
37
  AviGlitch::Base.surely_formatted?(@out, true).should be true
38
38
 
39
39
  system [@cmd, '-a', @in].join(' ')
40
40
  o = AviGlitch.open @out
41
- o.frames.size.should == total - keys
41
+ o.frames.size.should == total
42
42
  o.frames.first.is_keyframe?.should be false
43
43
  o.close
44
44
  AviGlitch::Base.surely_formatted?(@out, true).should be true
45
45
 
46
46
  system [@cmd, @in, @in, @in].join(' ')
47
47
  o = AviGlitch.open @out
48
- o.frames.size.should == 1 + (total - keys) * 3
48
+ o.frames.size.should == total * 3
49
49
  o.frames.first.is_keyframe?.should be true
50
50
  o.close
51
51
  AviGlitch::Base.surely_formatted?(@out, true).should be true
@@ -446,5 +446,38 @@ describe AviGlitch::Frames do
446
446
  x.should be_nil
447
447
  end
448
448
 
449
+ it 'can modify frame flag and frame id' do
450
+ a = AviGlitch.open @in
451
+ a.frames.each do |f|
452
+ f.flag = 0
453
+ f.id = "02dc"
454
+ end
455
+ a.output @out
456
+ a = AviGlitch.open @out
457
+ a.frames.each do |f|
458
+ f.flag.should == 0
459
+ f.id.should == "02dc"
460
+ end
461
+ end
462
+
463
+ it 'should clear keyframes with one method' do
464
+ a = AviGlitch.open @in
465
+ a.frames.clear_keyframes!
466
+ a.output @out
467
+ a = AviGlitch.open @out
468
+ a.frames.each do |f|
469
+ f.is_keyframe?.should be false
470
+ end
471
+
472
+ a = AviGlitch.open @in
473
+ a.frames.clear_keyframes! 0..50
474
+ a.output @out
475
+ a = AviGlitch.open @out
476
+ a.frames.each_with_index do |f, i|
477
+ if i <= 50
478
+ f.is_keyframe?.should be false
479
+ end
480
+ end
481
+ end
449
482
 
450
483
  end
@@ -1,7 +1,4 @@
1
- require 'spec'
2
-
3
- $LOAD_PATH.unshift(File.dirname(__FILE__))
4
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
1
+ require 'rspec'
5
2
  require 'aviglitch'
6
3
  require 'pathname'
7
4
  require 'fileutils'
@@ -9,6 +6,6 @@ require 'fileutils'
9
6
  FILES_DIR = Pathname.new(File.dirname(__FILE__)).realpath + 'files'
10
7
  OUTPUT_DIR = FILES_DIR + 'output'
11
8
 
12
- Spec::Runner.configure do |config|
9
+ RSpec.configure do |config|
13
10
 
14
11
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ version: 0.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - ucnv
@@ -14,10 +14,24 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-09-09 00:00:00 +09:00
17
+ date: 2011-04-10 00:00:00 +09:00
18
18
  default_executable: datamosh
19
- dependencies: []
20
-
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 2
30
+ - 0
31
+ - 0
32
+ version: 2.0.0
33
+ type: :development
34
+ version_requirements: *id001
21
35
  description:
22
36
  email: ucnvvv@gmail.com
23
37
  executables:
@@ -43,16 +57,15 @@ files:
43
57
  - spec/datamosh_spec.rb
44
58
  - spec/files/sample.avi
45
59
  - spec/frames_spec.rb
46
- - spec/spec.opts
47
60
  - spec/spec_helper.rb
48
61
  - LICENSE
49
62
  has_rdoc: true
50
- homepage: http://github.com/ucnv/aviglitch
63
+ homepage: http://ucnv.github.com/aviglitch/
51
64
  licenses: []
52
65
 
53
66
  post_install_message:
54
- rdoc_options:
55
- - --charset=UTF-8
67
+ rdoc_options: []
68
+
56
69
  require_paths:
57
70
  - lib
58
71
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -1,2 +0,0 @@
1
- -c
2
- -fs