m2ts_parser 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/lib/m2ts_parser/appendix/arib_duration.rb +23 -0
- data/lib/m2ts_parser/appendix/arib_string.rb +27 -0
- data/lib/m2ts_parser/appendix/arib_time.rb +46 -0
- data/lib/m2ts_parser/appendix/ca_system_id.rb +34 -0
- data/lib/m2ts_parser/appendix/content_nibble.rb +160 -0
- data/lib/m2ts_parser/appendix/crc32.rb +73 -0
- data/lib/m2ts_parser/application/epg_parse.rb +66 -0
- data/lib/m2ts_parser/application/out.txt +844 -0
- data/lib/m2ts_parser/common.rb +28 -0
- data/lib/m2ts_parser/descriptor.rb +364 -0
- data/lib/m2ts_parser/mpeg_transport_stream.rb +95 -0
- data/lib/m2ts_parser/table.rb +131 -0
- data/lib/m2ts_parser/test.rb +21 -0
- data/lib/m2ts_parser/version.rb +3 -0
- data/lib/m2ts_parser.rb +23 -0
- data/m2ts_parser.gemspec +27 -0
- metadata +121 -0
@@ -0,0 +1,131 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
# ARIB-STD-B10 第2部 (v4_9), 5.2項に従うテーブルの定義
|
4
|
+
|
5
|
+
module M2TSParser
|
6
|
+
class Table < BinaryParser::TemplateBase
|
7
|
+
include Appendix::CRC32Decoder
|
8
|
+
end
|
9
|
+
|
10
|
+
# 5.2.1 プログラムアソシエーションテーブル (PAT) (Program Association Table)
|
11
|
+
# * ISO/IEC 13818-1(22), 2.4.4項
|
12
|
+
|
13
|
+
# 5.2.2 限定受信テーブル (CAT) (Conditional Access Table)
|
14
|
+
# * ISO/IEC 13818-1(22), 2.4.4項
|
15
|
+
|
16
|
+
# 5.2.3 プログラムマップテーブル (PMT) (Program Map)
|
17
|
+
# * ISO/IEC 13818-1(22), 2.4.4項
|
18
|
+
|
19
|
+
# 5.2.4 ネットワーク情報テーブル (NIT) (Network Information Table)
|
20
|
+
|
21
|
+
# 5.2.5 ブーケアソシエーションテーブル (BAT) (Bouquet Association Table)
|
22
|
+
class BouquetAssociationSection < Table
|
23
|
+
Def do
|
24
|
+
data :table_id, UInt, 8
|
25
|
+
data :section_syntax_indicator, UInt, 1
|
26
|
+
data :reserved_future_use1, UInt, 1
|
27
|
+
data :reserved1, UInt, 2
|
28
|
+
data :section_length, UInt, 12
|
29
|
+
data :bouquet_id, UInt, 16
|
30
|
+
data :reserved2, UInt, 2
|
31
|
+
data :version_number, UInt, 5
|
32
|
+
data :current_next_indicator, UInt, 1
|
33
|
+
data :section_number, UInt, 8
|
34
|
+
data :last_section_number, UInt, 8
|
35
|
+
data :reserved_future_use2, UInt, 4
|
36
|
+
data :bouquet_descriptors_length, UInt, 12
|
37
|
+
|
38
|
+
SPEND var(:bouquet_descriptors_length) * 8, :descriptors, Descriptor
|
39
|
+
|
40
|
+
data :reserved_future_user3, UInt, 4
|
41
|
+
data :transport_stream_loop_length, UInt, 12
|
42
|
+
|
43
|
+
SPEND var(:transport_stream_loop_length) * 8, :transport_stream_loop do
|
44
|
+
data :transport_stream_id, UInt, 16
|
45
|
+
data :original_network_id, UInt, 16
|
46
|
+
data :reserved_future_use4, UInt, 4
|
47
|
+
data :transport_descriptors_length, UInt, 12
|
48
|
+
SPEND var(:transport_descriptors_length) * 8, :descriptors, Descriptor
|
49
|
+
end
|
50
|
+
|
51
|
+
data :crc_32, UInt, 32
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# 5.2.6 サービス記述テーブル (SDT) (Service Description Table)
|
56
|
+
|
57
|
+
# 5.2.7 イベント情報テーブル (EIT) (Event Information Table)
|
58
|
+
class EventInformationSection < Table
|
59
|
+
Def do
|
60
|
+
data :table_id, UInt, 8
|
61
|
+
data :section_syntax_indicator, UInt, 1
|
62
|
+
data :reserved_future_use, UInt, 1
|
63
|
+
data :reserved1, UInt, 2
|
64
|
+
data :section_length, UInt, 12
|
65
|
+
data :service_id, UInt, 16
|
66
|
+
data :reserved2, UInt, 2
|
67
|
+
data :version_number, UInt, 5
|
68
|
+
data :current_next_indicator, UInt, 1
|
69
|
+
data :section_number, UInt, 8
|
70
|
+
data :last_section_number, UInt, 8
|
71
|
+
data :transport_stream_id, UInt, 16
|
72
|
+
data :original_network_id, UInt, 16
|
73
|
+
data :segment_last_section_number, UInt, 8
|
74
|
+
data :last_table_id, UInt, 8
|
75
|
+
|
76
|
+
SPEND var(:section_length) * 8 - 88 - 32, :events do
|
77
|
+
data :event_id, UInt, 16
|
78
|
+
data :start_time, Appendix::AribTime, 40
|
79
|
+
data :duration, Appendix::AribDuration, 24
|
80
|
+
data :running_status, UInt, 3
|
81
|
+
data :free_ca_mode, UInt, 1
|
82
|
+
data :descriptors_loop_length, UInt, 12
|
83
|
+
SPEND var(:descriptors_loop_length) * 8, :descriptors, Descriptor
|
84
|
+
end
|
85
|
+
|
86
|
+
data :crc_32, UInt, 32
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# 未定義テーブル
|
91
|
+
class UndefinedSection < Table
|
92
|
+
Def do
|
93
|
+
data :table_id, UInt, 8
|
94
|
+
data :section_syntax_indicator, UInt, 1
|
95
|
+
data :reserved_future_use, UInt, 1
|
96
|
+
data :reserved1, UInt, 2
|
97
|
+
data :section_length, UInt, 12
|
98
|
+
data :rest, UInt, rest
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
class TableSelector < BinaryParser::TemplateBase
|
103
|
+
class AbstractSection < BinaryParser::TemplateBase
|
104
|
+
# ARIB STD-B10 第2部 表5-2 「テーブルID の割当および送出の基準」による定義
|
105
|
+
def self.TableMapping(table_id)
|
106
|
+
case table_id
|
107
|
+
when 0x4e, 0x4f, 0x50..0x5f, 0x60..0x6f
|
108
|
+
EventInformationSection
|
109
|
+
else
|
110
|
+
UndefinedSection
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def self.new(binary, parent_scope=nil)
|
115
|
+
table_id = binary.sub(:byte_length => 1).to_i
|
116
|
+
return TableMapping(table_id).new(binary)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
# ISO13818-1 Table 2-24 – Program specific information pointer
|
121
|
+
# > The beginning of a section is indicated by a pointer_field in the Transport Stream
|
122
|
+
# > packet payload. The syntax of this field is specified in Table 2-24.
|
123
|
+
# * from page 41
|
124
|
+
Def do
|
125
|
+
data :pointer_field, UInt, 8
|
126
|
+
data :padding, UInt, var(:pointer_field) * 8
|
127
|
+
data :section, AbstractSection, rest
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require '../m2ts_parser.rb'
|
3
|
+
|
4
|
+
module M2TSParser
|
5
|
+
File.open('16ch20sec.ts', 'rb') do |f|
|
6
|
+
stream = MPEGTransportStream.new(f).filter{|packet| packet.pid == 0x12}
|
7
|
+
while stream.rest?
|
8
|
+
packets = stream.get_sequence{|packet| packet.payload_unit_start_indicator == 1 }
|
9
|
+
valid = packets.each_cons(2).all?{|a, b| (a.continuity_counter + 1) % 16 == b.continuity_counter }
|
10
|
+
|
11
|
+
if valid
|
12
|
+
data = packets.map{|p| p.data_bytes.to_s}.inject{|acc, p| acc + p}
|
13
|
+
if data && data.length > 0
|
14
|
+
eit = TableSelector.new(data).section
|
15
|
+
eit.show(true)
|
16
|
+
p eit.check_crc32
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/m2ts_parser.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module M2TSParser
|
2
|
+
DEF_FILES =
|
3
|
+
[
|
4
|
+
'common.rb',
|
5
|
+
'descriptor.rb',
|
6
|
+
'mpeg_transport_stream.rb',
|
7
|
+
'table.rb',
|
8
|
+
]
|
9
|
+
|
10
|
+
LIB_ROOT = File.expand_path(File.dirname(__FILE__))
|
11
|
+
|
12
|
+
# switching for development
|
13
|
+
if File::exist?(LIB_ROOT + '/../../ruby-binary-parser/lib/binary_parser.rb')
|
14
|
+
require LIB_ROOT + '/../../ruby-binary-parser/lib/binary_parser.rb'
|
15
|
+
else
|
16
|
+
require 'binary_parser'
|
17
|
+
end
|
18
|
+
|
19
|
+
require LIB_ROOT + '/m2ts_parser/version'
|
20
|
+
Dir::glob(LIB_ROOT + '/m2ts_parser/appendix/*.rb').each{|f| require f}
|
21
|
+
DEF_FILES.each{|file_name| require LIB_ROOT + '/m2ts_parser/' + file_name}
|
22
|
+
Dir::glob(LIB_ROOT + '/m2ts_parser/application/*.rb').each{|f| require f}
|
23
|
+
end
|
data/m2ts_parser.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# -*- mode: ruby -*-
|
3
|
+
|
4
|
+
lib = File.expand_path('../lib', __FILE__)
|
5
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
require 'm2ts_parser/version'
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = "m2ts_parser"
|
10
|
+
spec.version = M2TSParser::VERSION
|
11
|
+
spec.authors = ["sawaken"]
|
12
|
+
spec.email = ["sasasawada@gmail.com"]
|
13
|
+
spec.summary = %q{An elegant MPEG2-TS file Parser.}
|
14
|
+
spec.homepage = ""
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
|
25
|
+
spec.add_dependency "binary_parser", ">= 1.2.1"
|
26
|
+
spec.add_dependency "tsparser", ">= 0.0.0"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: m2ts_parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- sawaken
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: binary_parser
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.2.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.2.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: tsparser
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.0.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.0.0
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- sasasawada@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- lib/m2ts_parser.rb
|
82
|
+
- lib/m2ts_parser/appendix/arib_duration.rb
|
83
|
+
- lib/m2ts_parser/appendix/arib_string.rb
|
84
|
+
- lib/m2ts_parser/appendix/arib_time.rb
|
85
|
+
- lib/m2ts_parser/appendix/ca_system_id.rb
|
86
|
+
- lib/m2ts_parser/appendix/content_nibble.rb
|
87
|
+
- lib/m2ts_parser/appendix/crc32.rb
|
88
|
+
- lib/m2ts_parser/application/epg_parse.rb
|
89
|
+
- lib/m2ts_parser/application/out.txt
|
90
|
+
- lib/m2ts_parser/common.rb
|
91
|
+
- lib/m2ts_parser/descriptor.rb
|
92
|
+
- lib/m2ts_parser/mpeg_transport_stream.rb
|
93
|
+
- lib/m2ts_parser/table.rb
|
94
|
+
- lib/m2ts_parser/test.rb
|
95
|
+
- lib/m2ts_parser/version.rb
|
96
|
+
- m2ts_parser.gemspec
|
97
|
+
homepage: ''
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
metadata: {}
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 2.2.2
|
118
|
+
signing_key:
|
119
|
+
specification_version: 4
|
120
|
+
summary: An elegant MPEG2-TS file Parser.
|
121
|
+
test_files: []
|