微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

设置视频和音频数据包的 DTS

如何解决设置视频和音频数据包的 DTS

所以我正在努力使用 PyAV 在 python 中将 5s 视频片段连接成一个 .mp4。视频片段存储为 BytesIO 对象(因此我可以将它们存储在 RAM 中)。我循环遍历每个段中的每个数据包,因此很自然地,它们的 PTS 和 DTS 不是唯一的,并且在每个段中都重复。因此,我决定将每个数据包的 PTS/DTS 设置为不断增加的值,以便它们的顺序正确。

    def mux_to_file(self,output_file_name,vid):
        vid.seek(0) #BytesIO object
        video = av.open(vid,"r"). #av InputContainer
        output = av.open(output_file_name,"w")  #av OutputContainer
        
        v_in = video.streams.video[0]  #information about the stream (bit rate,res...)
        video_p = video.demux(v_in)
        output_video = output.add_stream(template=v_in)


        self.last_pts = 0
        self.step = 0
        for packet in video_p:  #looping through every packet
            if packet.dts is None:
                continue

            packet.dts = self.last_pts   #setting new pts and dts
            packet.pts = self.last_pts
            self.last_pts += packet.duration  #old one+duration of the prevIoUs one

            packet.stream = output_video     #assigns information of the new packet
            output.mux(packet)               # muxing,her occurs the warning
        
        output.close()
        video.close()

警告如下:

Found duplicated MOOV Atom. Skipped it
Found duplicated MOOV Atom. Skipped it
 (repeated 58 more times)
Found duplicated MOOV Atom. Skipped it
Found duplicated MOOV Atom. Skipped it
 (repeated 58 more times)
DTS 0 < 447000 out of order
DTS 0 < 447000 out of order
 (repeated 58 more times)

我想设置数据包的 PTS/DTS,以免出现警告。当然,关闭 av lib 的日志记录是一个选项, av.logging.set_level(av.logging.PANIC) 但是,我正在寻找更优雅、更好的解决方案。我如何将 DTS 设置为正确的值,为什么我的解决方案仍然抛出错误

提前致谢。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。