如何解决opencv中的“[mov,mp4,m4a,3gp,3g2,mj2 @ 0000021c356d9e00] moov原子未找到”

Dan*_*tos 5 python opencv ffmpeg

我正在尝试使用 OpenCV 在 kivy 应用程序中创建视频上传器。但是,当我尝试上传视频时,出现以下错误

[mov,mp4,m4a,3gp,3g2,mj2 @ 0000021c356d9e00] moov atom not found
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000021c356d9e00] moov atom not found
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000021c356d9e00] moov atom not found
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000021c356d9e00] moov atom not found
...
Run Code Online (Sandbox Code Playgroud)

在此期间屏幕变得无响应。我最近编辑了 save() 函数并添加了 uploadClass() 因为我收到了另一个错误。

主要.py

...

class SaveDialog(Screen):
    save = ObjectProperty(None)
    text_input = ObjectProperty(None)
    cancel = ObjectProperty(None)

    def save(self, path, filename):

        for letter in os.path.join(path, filename):
            print(letter)

        def find(s, ch):
            return [i for i, letter in enumerate(s) if letter == ch]

        os_path_simpl = list(os.path.join(path, filename))

        for t in range(len(find(os.path.join(path, filename), '\\'))):
            os_path_simpl[find(os.path.join(path, filename), '\\')[t]] = '\\'

        class uploadClass(object):
            video = ''.join(os_path_simpl)

            def __init__(self, src=video):
                self.video_selected = cv2.VideoCapture(src)

                self.vid_cod = cv2.VideoWriter_fourcc(*'mp4v')
                self.out = cv2.VideoWriter('media/testOne.mp4', self.vid_cod, 20.0, (640,480))

                self.thread = Thread(target=self.update, args=())
                self.thread.daemon = True
                self.thread.start()

            def update(self):
                while True:
                    if self.video_selected.isOpened():
                        (self.status, self.frame) = self.video_selected.read()

            def show_frame(self):
                if self.status:
                    cv2.imshow('uploading', self.frame)

                if cv2.waitKey(10) & 0xFF == ord('q'):
                    self.video_selected.release()
                    self.out.release()
                    cv2.destroyAllWindows()
                    exit(1)

            def save_frame(self):
                self.out.write(self.frame)

        rtsp_stream_link = 'media/testOne.mp4'
        upload_Class = uploadClass(rtsp_stream_link)
        while True:
            try:
                upload_Class.__init__()
                upload_Class.show_frame()
                upload_Class.save_frame()
            except AttributeError:
                pass

        sm.current = "home"

...

Run Code Online (Sandbox Code Playgroud)

Fra*_*ser 4

Moovatom 包含播放视频所需的各种信息,您收到的错误表明该信息丢失或损坏。

例如,当您创建视频然后在创建过程仍在运行时尝试移动/上传文件时,可能会发生这种情况。

在您的情况下,我认为您需要在尝试上传文件之前释放 cv2.VideoWriter/cv2.VideoCapture 对象。IE

self.video_selected.release()
self.out.release()
Run Code Online (Sandbox Code Playgroud)

需要在视频上传前调用。