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
62
63
64
65
66
|
# File 'lib/torchcodec/core/metadata.rb', line 14
def self.get_container_metadata(decoder)
container_dict = JSON.parse(_get_container_json_metadata(decoder))
streams_metadata = []
container_dict["numStreams"].times do |stream_index|
stream_dict = JSON.parse(_get_stream_json_metadata(decoder, stream_index))
common_meta = {
duration_seconds_from_header: stream_dict["durationSecondsFromHeader"],
duration_seconds: stream_dict["durationSeconds"],
bit_rate: stream_dict["bitRate"],
begin_stream_seconds_from_header: stream_dict["beginStreamSecondsFromHeader"],
begin_stream_seconds: stream_dict["beginStreamSeconds"],
codec: stream_dict["codec"],
stream_index: stream_index
}
if stream_dict["mediaType"] == "video"
streams_metadata << {
begin_stream_seconds_from_content: stream_dict["beginStreamSecondsFromContent"],
end_stream_seconds_from_content: stream_dict["endStreamSecondsFromContent"],
end_stream_seconds: stream_dict["endStreamSeconds"],
num_frames: stream_dict["numFrames"],
average_fps: stream_dict["averageFps"],
width: stream_dict["width"],
height: stream_dict["height"],
num_frames_from_header: stream_dict["numFramesFromHeader"],
num_frames_from_content: stream_dict["numFramesFromContent"],
average_fps_from_header: stream_dict["averageFpsFromHeader"],
pixel_aspect_ratio: _get_optional_par_fraction(stream_dict),
**common_meta
}
elsif stream_dict["mediaType"] == "audio"
streams_metadata << {
sample_rate: stream_dict["sampleRate"],
num_channels: stream_dict["numChannels"],
sample_format: stream_dict["sampleFormat"],
**common_meta
}
else
streams_metadata << common_meta
end
end
{
duration_seconds_from_header: container_dict["durationSecondsFromHeader"],
bit_rate_from_header: container_dict["bitRate"],
best_video_stream_index: container_dict["bestVideoStreamIndex"],
best_audio_stream_index: container_dict["bestAudioStreamIndex"],
streams: streams_metadata
}
end
|