示例#1
0
 def walk_s_v2(self, segmenttimeline: SegmentTimeline,
               adaptationset: AdaptationSet, period: Period, sindex: int,
               uri_item: BaseUri):
     stream = DASHStream(sindex, uri_item, self.args.save_dir)
     stream.set_skey(adaptationset.id, None)
     sindex += 1
     return [stream]
示例#2
0
 def walk_representation(self, adaptationset: AdaptationSet, period: Period,
                         sindex: int, uri_item: BaseUri):
     '''
     每一个<Representation></Representation>都对应轨道的一/整段
     '''
     representations = adaptationset.find(
         'Representation')  # type: List[Representation]
     segmenttemplates = adaptationset.find(
         'SegmentTemplate')  # type: List[SegmentTemplate]
     streams = []
     for representation in representations:
         # 修正 Representation 节点的 BaseURL
         base_url = self.fix_dash_base_url(uri_item.base_url,
                                           representation)
         current_uri_item = uri_item.new_base_url(base_url)
         logger.debug(f'current_base_url {current_uri_item.base_url}')
         stream = DASHStream(sindex, current_uri_item, self.args.save_dir)
         sindex += 1
         self.walk_contentprotection(adaptationset, stream)
         self.walk_contentprotection(representation, stream)
         # 给流设置属性
         stream.set_skey(adaptationset.id, representation.id)
         stream.set_lang(adaptationset.lang)
         stream.set_bandwidth(representation.bandwidth)
         if representation.codecs is None:
             stream.set_codecs(adaptationset.codecs)
         else:
             stream.set_codecs(representation.codecs)
         if representation.mimeType is None:
             stream.set_stream_type(adaptationset.mimeType)
         else:
             stream.set_stream_type(representation.mimeType)
         if representation.width is None or representation.height is None:
             stream.set_resolution(adaptationset.width,
                                   adaptationset.height)
         else:
             stream.set_resolution(representation.width,
                                   representation.height)
         # 针对字幕直链类型
         Roles = adaptationset.find('Role')  # type: List[Role]
         if stream.stream_type == '' and len(Roles) > 0:
             stream.set_stream_type(Roles[0].value)
         BaseURLs = representation.find('BaseURL')  # type: List[BaseURL]
         if len(BaseURLs) == 1:
             if len(Roles) == 1 and Roles[0].value in [
                     'subtitle', 'caption'
             ]:
                 base_url = BaseURLs[0].innertext.strip()
                 if base_url.startswith('http') or base_url.startswith('/'):
                     stream.set_subtitle_url(base_url)
                 else:
                     stream.set_subtitle_url('../' + base_url)
                 streams.append(stream)
                 continue
             # if len(segmenttemplates) == 0 and len(representation.find('SegmentTimeline')) == 0:
             #     stream.base2url(period.duration)
             #     streams.append(stream)
             #     continue
         segmentlists = representation.find(
             'SegmentList')  # type: List[SegmentList]
         r_segmenttemplates = representation.find(
             'SegmentTemplate')  # type: List[SegmentTemplate]
         # 针对视频音频流处理 分情况生成链接
         if len(segmentlists) == 1:
             self.walk_segmentlist(segmentlists[0], representation, period,
                                   stream)
         elif len(segmenttemplates) == 0:
             self.walk_segmenttemplate(representation, period, stream)
         elif len(segmenttemplates) == 1 and len(
                 segmenttemplates[0].find('SegmentTimeline')) == 1:
             self.walk_segmenttimeline(segmenttemplates[0], representation,
                                       period, stream)
         elif len(r_segmenttemplates) == 1 and len(
                 r_segmenttemplates[0].find('SegmentTimeline')) == 1:
             self.walk_segmenttimeline(r_segmenttemplates[0],
                                       representation, period, stream)
         elif len(segmenttemplates
                  ) == 1 and segmenttemplates[0].initialization is None:
             # tv-player.ap1.admint.biz live
             _segmenttemplates = representation.find('SegmentTemplate')
             if len(_segmenttemplates) != 1:
                 # AdaptationSet 的 SegmentTemplate 没有 initialization
                 # Representation 没有 SegmentTemplate 则跳过
                 continue
             # assert len(_segmenttemplates) == 1, '请报告出现此异常提示的mpd/report plz'
             segmenttemplate = segmenttemplates[0]
             _segmenttemplate = _segmenttemplates[0]
             if segmenttemplate.timescale is not None:
                 _segmenttemplate.timescale = segmenttemplate.timescale
             if segmenttemplate.duration is not None:
                 _segmenttemplate.duration = segmenttemplate.timescale
             self.generate_v1(period, representation.id, _segmenttemplate,
                              stream)
         else:
             # SegmentTemplate 和多个 Representation 在同一级
             # 那么 SegmentTemplate 的时长参数等就是多个 Representation 的参数
             # 同一级的时候 只有一个 SegmentTemplate
             self.generate_v1(period, representation.id,
                              segmenttemplates[0], stream)
         streams.append(stream)
     return streams