-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_v2.rb
More file actions
62 lines (50 loc) · 2.16 KB
/
Copy pathexample_v2.rb
File metadata and controls
62 lines (50 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require 'axlsx'
require 'pry'
require './source/source'
require './parser/parser'
require './mp4/mp4'
require './layout/layout'
# mp4_file_path = './examples/keyint_30_02_converted.mp4'
# mp4_file_path = './examples/small_linus_example.mp4'
# mp4_file_path = './examples/03_ctts.mp4'
# mp4_file_path = './examples/keyint_30_example_google.mp4'
mp4_file_path = './examples/02.mp4'
# mp4_file_path = './examples/example_google.mp4'
file_name = File.basename(mp4_file_path)
source = Source.load_from_local(mp4_file_path)
parsed_mp4 = Parser.parse(source)
mp4 = MP4.load_v2(parsed_mp4)
# res = mp4.parts.all
mp4_layout = Layout.build(mp4, source)
File.write("./out/result_#{file_name}", mp4_layout.pack)
# return
package = Axlsx::Package.new
package.workbook do |workbook|
mp4.get_tracks.each do |track|
workbook.add_worksheet name: "trak_#{track['track_id']} (#{track['track_type']})" do |sheet|
# sheet.add_row(['keyframe', 'sample_number', 'sample_size', 'chunk_number', 'chunk_offset', 'stts', 'timestamp'])
sheet.add_row(['Chunk ID', 'Chunk Offset', 'Sample Number', 'Sample Size', 'Sample Delta', 'Sample C Delta', 'timestamp', 'Keyframe'])
delta_counter = 0.0
samples_list = mp4.get_samples_of(track['track_id'])
until (row = samples_list.next).nil?
sheet.add_row([
row['chunk_index'],
row['chunk_offset'],
row['sample_index'],
row['size'],
row['delta'],
row['c_delta'],
Time.at(row['delta_sum'] / row['timescale'].to_f).utc.strftime('%H:%M:%S,%L'),
row['keyframe']
])
end
grouped_chunks = mp4.cache_db.execute('SELECT chunk_index, min(sample_index) as min_sample_index, max(sample_index) as max_sample_index from samples WHERE track_id = ? GROUP BY chunk_index', track['track_id'])
grouped_chunks.each do |grouped_chunk|
_chunk_index, min_sample_index, max_sample_index = *grouped_chunk.values
sheet.merge_cells "A#{min_sample_index + 1}:A#{max_sample_index + 1}"
sheet.merge_cells "B#{min_sample_index + 1}:B#{max_sample_index + 1}"
end
end
end
end
package.serialize "fragmented/new.fragmented_#{file_name}.xlsx"