设置视频和音频数据包的 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 (将#修改为@)