aviglitch 0.1.6 → 0.2.2

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.
@@ -3,23 +3,12 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
3
  describe AviGlitch, 'datamosh cli' do
4
4
 
5
5
  before :all do
6
- FileUtils.mkdir OUTPUT_DIR unless File.exist? OUTPUT_DIR
7
- @in = FILES_DIR + 'sample.avi'
8
- @out = OUTPUT_DIR + 'out.avi'
9
6
  here = File.dirname(__FILE__)
10
7
  lib = Pathname.new(File.join(here, '..', 'lib')).realpath
11
8
  datamosh = Pathname.new(File.join(here, '..', 'bin/datamosh')).realpath
12
9
  @cmd = "ruby -I%s %s -o %s " % [lib, datamosh, @out]
13
10
  end
14
11
 
15
- after :each do
16
- FileUtils.rm Dir.glob((OUTPUT_DIR + '*').to_s)
17
- end
18
-
19
- after :all do
20
- FileUtils.rmdir OUTPUT_DIR
21
- end
22
-
23
12
  it 'should correctly process files' do
24
13
  a = AviGlitch.open @in
25
14
  keys = a.frames.inject(0) do |c, f|
@@ -27,12 +16,13 @@ describe AviGlitch, 'datamosh cli' do
27
16
  c
28
17
  end
29
18
  total = a.frames.size
19
+ first_keyframe = a.frames.index(a.frames.first_of(:keyframe))
30
20
  a.close
31
21
 
32
22
  system [@cmd, @in].join(' ')
33
23
  o = AviGlitch.open @out
34
24
  o.frames.size.should == total
35
- o.frames.first.is_keyframe?.should be true
25
+ o.frames[first_keyframe].is_keyframe?.should be true
36
26
  o.has_keyframe?.should be true
37
27
  o.close
38
28
  AviGlitch::Base.surely_formatted?(@out, true).should be true
@@ -40,7 +30,7 @@ describe AviGlitch, 'datamosh cli' do
40
30
  system [@cmd, '-a', @in].join(' ')
41
31
  o = AviGlitch.open @out
42
32
  o.frames.size.should == total
43
- o.frames.first.is_keyframe?.should be false
33
+ o.frames[first_keyframe].is_keyframe?.should be false
44
34
  o.has_keyframe?.should be false
45
35
  o.close
46
36
  AviGlitch::Base.surely_formatted?(@out, true).should be true
@@ -48,7 +38,7 @@ describe AviGlitch, 'datamosh cli' do
48
38
  system [@cmd, @in, @in, @in].join(' ')
49
39
  o = AviGlitch.open @out
50
40
  o.frames.size.should == total * 3
51
- o.frames.first.is_keyframe?.should be true
41
+ o.frames[first_keyframe].is_keyframe?.should be true
52
42
  o.close
53
43
  AviGlitch::Base.surely_formatted?(@out, true).should be true
54
44
 
data/spec/frames_spec.rb CHANGED
@@ -1,30 +1,28 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- describe AviGlitch::Frames do
3
+ # Since Ruby 3.3.x, Windows frequently fails to close the Tempfile on GC.
4
+ # Although not a fatal error, it should be better to remove them manually in such cases.
5
+ # Now this spec is skipped in Windows because it could generate a lot of warning messages and undeleted temp files.
6
+ describe AviGlitch::Frames, :skip => Gem.win_platform? do
4
7
 
5
8
  before :all do
6
9
  AviGlitch::Frames.class_eval do
7
10
  define_method(:get_real_id_with) do |frame|
8
- pos = @io.pos
9
- @io.pos -= frame.data.size
10
- @io.pos -= 8
11
- id = @io.read 4
12
- @io.pos = pos
11
+ movi = @avi.get_movi
12
+ pos = movi.pos
13
+ movi.pos -= frame.data.size
14
+ movi.pos -= 8
15
+ id = movi.read 4
16
+ movi.pos = pos
13
17
  id
14
18
  end
15
19
  end
16
20
 
17
- FileUtils.mkdir OUTPUT_DIR unless File.exist? OUTPUT_DIR
18
- @in = FILES_DIR + 'sample.avi'
19
- @out = OUTPUT_DIR + 'out.avi'
20
- end
21
-
22
- after :each do
23
- FileUtils.rm Dir.glob((OUTPUT_DIR + '*').to_s)
24
- end
25
-
26
- after :all do
27
- FileUtils.rmdir OUTPUT_DIR
21
+ AviGlitch::Avi.class_eval do
22
+ define_method(:get_movi) do
23
+ @movi
24
+ end
25
+ end
28
26
  end
29
27
 
30
28
  it 'should save the same file when nothing is changed' do
@@ -85,15 +83,6 @@ describe AviGlitch::Frames do
85
83
  avi.close
86
84
  end
87
85
 
88
- it 'should hide the inner variables' do
89
- avi = AviGlitch.open @in
90
- frames = avi.frames
91
- lambda { frames.meta }.should raise_error(NoMethodError)
92
- lambda { frames.io }.should raise_error(NoMethodError)
93
- lambda { frames.frames_data_as_io }.should raise_error(NoMethodError)
94
- avi.close
95
- end
96
-
97
86
  it 'should save video frames count in header' do
98
87
  avi = AviGlitch.open @in
99
88
  c = 0
@@ -493,8 +482,7 @@ describe AviGlitch::Frames do
493
482
  expect(File.size(@out)).to be < File.size(@in)
494
483
  end
495
484
 
496
- it 'should use Enumerator as an external iterator',
497
- :skip => Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('1.9.0') || RUBY_PLATFORM == 'java' do
485
+ it 'should use Enumerator as an external iterator' do
498
486
  a = AviGlitch.open @in
499
487
  e = a.frames.each
500
488
  expect {
@@ -557,4 +545,27 @@ describe AviGlitch::Frames do
557
545
  expect(ac2).to eq(ac)
558
546
  end
559
547
 
548
+ it 'should pick the first / last frame with a method' do
549
+ a = AviGlitch.open @in
550
+ fkidx = -1
551
+ lkidx = -1
552
+ faidx = -1
553
+ laidx = -1
554
+ a.frames.each_with_index do |f, i|
555
+ if f.is_keyframe?
556
+ fkidx = i if fkidx == -1
557
+ lkidx = i
558
+ end
559
+ if f.is_audioframe?
560
+ faidx = i if faidx == -1
561
+ laidx = i
562
+ end
563
+ end
564
+ a.frames.index(a.frames.first_of(:keyframe)).should eq(fkidx)
565
+ a.frames.rindex(a.frames.last_of(:keyframe)).should eq(lkidx)
566
+ a.frames.index(a.frames.first_of(:audioframe)).should eq(faidx)
567
+ a.frames.rindex(a.frames.last_of(:audioframe)).should eq(laidx)
568
+ a.close
569
+ end
570
+
560
571
  end
data/spec/spec_helper.rb CHANGED
@@ -2,6 +2,7 @@ require 'rspec'
2
2
  require 'aviglitch'
3
3
  require 'pathname'
4
4
  require 'fileutils'
5
+ require 'net/http'
5
6
 
6
7
  FILES_DIR = Pathname.new(File.dirname(__FILE__)).realpath + 'files'
7
8
  OUTPUT_DIR = FILES_DIR + 'output'
@@ -11,4 +12,48 @@ RSpec.configure do |config|
11
12
  config.expect_with :rspec do |c|
12
13
  c.syntax = [:should, :expect]
13
14
  end
15
+
16
+ config.before(:all) do
17
+ FileUtils.mkdir FILES_DIR unless File.exist? FILES_DIR
18
+ FileUtils.mkdir OUTPUT_DIR unless File.exist? OUTPUT_DIR
19
+ @in = FILES_DIR + 'sample1.avi'
20
+ @in2 = FILES_DIR + 'sample2.avi'
21
+ @out = OUTPUT_DIR + 'out.avi'
22
+ [
23
+ [@in2, 'http://a.ucnv.org/sample2.avi'], [@in, 'http://a.ucnv.org/sample1.avi']
24
+ ].each do |file, url|
25
+ unless File.exist? file
26
+ if file == @in2
27
+ puts 'At first test it needs to download a file over 1GB. It will take a while.'
28
+ end
29
+ puts 'Downloading ' + url
30
+ $stdout.sync = true
31
+ u = URI.parse url
32
+ Net::HTTP.start(u.host, u.port) do |http|
33
+ res = http.request_head u.path
34
+ max = res['content-length'].to_i
35
+ len = 0
36
+ bl = 75
37
+ File.open(file, 'w') do |file|
38
+ http.get(u.path) do |chunk|
39
+ file.write chunk
40
+ len += chunk.length
41
+ pct = '%3.1f' % (100.0 * len / max)
42
+ bar = ('#' * (bl * len / max)).ljust(bl)
43
+ print "\r#{bar} #{'%5s' % pct}%" unless ENV['CI']
44
+ end
45
+ end
46
+ end
47
+ puts
48
+ end
49
+ end
50
+ end
51
+
52
+ config.after(:each) do
53
+ begin
54
+ FileUtils.rm_r Dir.glob((OUTPUT_DIR + '*').to_s)
55
+ rescue => e
56
+ # Sometimes windows can't remove files.
57
+ end
58
+ end
14
59
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aviglitch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ucnv
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-21 00:00:00.000000000 Z
11
+ date: 2024-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -73,15 +73,16 @@ files:
73
73
  - aviglitch.gemspec
74
74
  - bin/datamosh
75
75
  - lib/aviglitch.rb
76
+ - lib/aviglitch/avi.rb
76
77
  - lib/aviglitch/base.rb
77
78
  - lib/aviglitch/frame.rb
78
79
  - lib/aviglitch/frames.rb
80
+ - spec/avi2_spec.rb
79
81
  - spec/aviglitch_spec.rb
80
82
  - spec/datamosh_spec.rb
81
- - spec/files/sample.avi
82
83
  - spec/frames_spec.rb
83
84
  - spec/spec_helper.rb
84
- homepage: http://ucnv.github.com/aviglitch/
85
+ homepage: https://github.com/ucnv/aviglitch
85
86
  licenses:
86
87
  - MIT
87
88
  metadata: {}
@@ -102,13 +103,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
103
  - !ruby/object:Gem::Version
103
104
  version: '0'
104
105
  requirements: []
105
- rubygems_version: 3.2.22
106
+ rubygems_version: 3.5.11
106
107
  signing_key:
107
108
  specification_version: 4
108
109
  summary: A Ruby library to destroy your AVI files.
109
110
  test_files:
111
+ - spec/avi2_spec.rb
110
112
  - spec/aviglitch_spec.rb
111
113
  - spec/datamosh_spec.rb
112
- - spec/files/sample.avi
113
114
  - spec/frames_spec.rb
114
115
  - spec/spec_helper.rb
Binary file