Advertisement
jowijo

ATSC Configuration

Aug 6th, 2014
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.82 KB | None | 0 0
  1. #!/usr/bin/env python
  2. #
  3. # PSIP DATA
  4. #
  5. import os
  6.  
  7. from dvbobjects.PSI.PAT import *
  8. from dvbobjects.PSI.PMT import *
  9. from dvbobjects.PSI.MGT import *
  10. from dvbobjects.PSI.TVCT import *
  11. from dvbobjects.PSI.ATSC_EIT import *
  12.  
  13. #
  14. # Shared values
  15. #
  16. atsc_original_transport_stream_id = 0x0027
  17. atsc_transport_stream_id = 0x0027
  18. atsc1_service_id = 1
  19. atsc1_pmt_pid = 1031
  20. #
  21. # Terrestrial Virtual Channel Table
  22. #
  23. tvct = terrestrial_virtual_channel_section(
  24.     transport_stream_id = atsc_transport_stream_id,
  25.     ATSC_protocol_version = 0,
  26.     channels_loop = [
  27.         channel_loop_item(
  28.             short_name = "\x00\x4B\x00\x42\x00\x4B\x00\x49\x00\x2D\x00\x48\x00\x44",
  29.             major_channel_number = 5,
  30.             minor_channel_number = 1,
  31.             modulation_mode = 0x04,
  32.             carrier_frequency = 77000000, # Channel 5
  33.             channel_TSID = atsc_transport_stream_id,
  34.             program_number = atsc1_service_id,
  35.             ETM_location = 0,
  36.             access_controlled = 0,
  37.             hidden = 0,
  38.             hide_guide = 0,
  39.             service_type = 0x2,
  40.             source_id = 0x1,
  41.             descriptors_loop = [
  42. ],
  43.         )
  44.  
  45.     ],
  46.     additional_descriptors_loop = [],
  47.     version_number = 1,
  48.     section_number = 0,
  49.     last_section_number = 0,
  50.     )
  51.  
  52.  
  53. #
  54. # Master Guide Table
  55. #
  56.  
  57. mgt = master_guide_section(
  58.     ATSC_protocol_version = 0,
  59.     tables_loop = [
  60.         table_loop_item(
  61.             table_type = 0x0, # terrestrial vct
  62.             table_type_pid = 0x1FFB,
  63.             table_type_version_number = tvct.version_number,
  64.             number_bytes = len(tvct.pack()),
  65.             descriptors_loop = [],
  66.         ),
  67.        
  68.     ],
  69.     descriptors_loop = [],
  70.     version_number = 1,
  71.     section_number = 0,
  72.     last_section_number = 0,
  73.     )
  74.  
  75.  
  76.  
  77. #
  78. # Program Association Table (ISO/IEC 13818-1 2.4.4.3)
  79. #
  80.  
  81. pat = program_association_section(
  82.     transport_stream_id = atsc_transport_stream_id,
  83.         program_loop = [
  84.             program_loop_item(
  85.             program_number = atsc1_service_id,
  86.             PID = atsc1_pmt_pid,
  87.             ),  
  88.         ],
  89.         version_number = 1,
  90.         section_number = 0,
  91.         last_section_number = 0,
  92.         )  
  93.  
  94. #
  95. # Program Map Table (ISO/IEC 13818-1 2.4.4.8)
  96. #  
  97.  
  98. pmt = program_map_section(
  99.     program_number = atsc1_service_id,
  100.     PCR_PID = 260,
  101.     program_info_descriptor_loop = [],
  102.     stream_loop = [
  103.         stream_loop_item(
  104.             stream_type = 2, # MPEG-2 Video
  105.             elementary_PID = 260,
  106.             element_info_descriptor_loop = [
  107.            
  108.            
  109.             ]
  110.         ),
  111.         stream_loop_item(
  112.             stream_type = 129, # AC3 (Dolby) Audio
  113.             elementary_PID = 265,
  114.             element_info_descriptor_loop = [
  115.                 registration_descriptor(
  116.                     format_identifier="AC-3",
  117.                 ),
  118.                    
  119.                 ISO_639_language_descriptor(
  120.                      ISO_639_language_code = "eng",
  121.                      Audio_type = 0x00,
  122.                 ),
  123.             ],
  124.         ),
  125.     ],
  126.         version_number = 1,
  127.         section_number = 0,
  128.         last_section_number = 0,
  129.         )    
  130.  
  131.  
  132. ################## TEST
  133. eit = event_information_section(
  134.     table_id = 0x12,
  135.     service_id = atsc1_service_id,
  136.     transport_stream_id = atsc_transport_stream_id,
  137.         source_id = 0x1,
  138.             event_loop = [
  139.                 event_loop_item(
  140.                     event_id = 0x1,
  141.                     title_length = 0x11,
  142.                     start_time = 1091399416,
  143.                     length_in_seconds = 3600,
  144.                     title_text = multiple_string_structure(
  145.                             number_strings = 0x1,
  146.                             string_loop = [
  147.                                 string_loop_item(
  148.                                     ISO639_language_code = "eng",
  149.                                     number_segments = 0x1,
  150.                                     segment_loop = [
  151.                                         segment_loop_item(
  152.                                             compression_type = 0x0,
  153.                                             mode = 0x0,
  154.                                             number_bytes = 0x11,
  155.                                             compressed_string = "\x43\x61\x72\x64\x63\x61\x70\x74\x6F\x72\x20\x53\x61\x6B\x75\x72\x61",
  156.                                         ),
  157.                                     ],
  158.                                 ), #End string loop
  159.                             ],
  160.                         ), #End MSS
  161.                     ETM_location = 0x0,
  162.                     descriptor_loop = [],
  163.             ),
  164.     ],
  165.         version_number = 1,
  166.         section_number = 0,
  167.         last_section_number = 0,
  168.         )  
  169.                
  170.  
  171. ##################################END########################
  172.  
  173. out = open("1080/pat.sec", "wb")
  174. out.write(pat.pack())
  175. out.close
  176. out = open("1080/pat.sec", "wb") # python   flush bug
  177. out.close
  178. os.system('/usr/bin/sec2ts 0 < 1080/pat.sec > 1080/pat.ts')
  179.  
  180. out = open("1080/pmt.sec", "wb")
  181. out.write(pmt.pack())
  182. out.close
  183. out = open("1080/pmt.sec", "wb") # python   flush bug
  184. out.close
  185. os.system('/usr/bin/sec2ts ' + str(atsc1_pmt_pid) + ' < 1080/pmt.sec > 1080/pmt.ts')
  186.  
  187.  
  188. out = open("1080/mgt.sec", "wb")
  189. out.write(mgt.pack())
  190. out.close
  191. out = open("1080/mgt.sec", "wb") # python   flush bug
  192. out.close
  193. os.system('/usr/bin/sec2ts 8187 < 1080/mgt.sec > 1080/8187.ts')
  194.  
  195. out = open("1080/tvct.sec", "wb")
  196. out.write(tvct.pack())
  197. out.close
  198. out = open("1080/tvct.sec", "wb") # python   flush bug
  199. out.close
  200. os.system('/usr/bin/sec2ts 8187 < 1080/tvct.sec >> 1080/8187.ts')
  201.  
  202. out = open("1080/eit.sec", "wb")
  203. out.write(eit.pack())
  204. out.close
  205. out = open("1080/eit.sec", "wb") # python   flush bug
  206. out.close
  207. os.system('/usr/bin/sec2ts < 1080/eit.sec > 1080/eit.ts')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement