OpenCV保存的视频文件已损坏

问题描述 投票:1回答:1
The following code snippet is used to save a video file using OpenCV:

from multiprocessing import Process
from .streams import InputStream
from .camera import *
import cv2
import imutils
import logging
import time
import os
import numpy as np
import skvideo.io

log = logging.getLogger('igate')

class RecordWorker:

  def __init__(self, camera, config):
    self.config = config
    self.process = Process(target = self.save, args = (camera, ))


  def start(self):
    self.process.start()
    return self


  def save(self, camera):
    log.debug(f'{camera.id} RecordWorker SAVE started')
    fourcc = cv2.VideoWriter_fourcc(*"MJPG")
    videofile_count = self.get_start_videofile_number()
    video_filepath = self.config['video_save_path'] + camera.view + '_' +  f'{videofile_count:03d}' + '.avi'

    log.info(f'Saving video: {video_filepath}')
    video_writer = cv2.VideoWriter(video_filepath, fourcc, 25.0, (640,360), True)          
    #writer = skvideo.io.FFmpegWriter(video_filepath + '.avi')

    while True:
      frame, index = camera.inputStream.read()
      if frame is not None:
        log.info("got frame...");
        video_writer.write(np.uint8(255*frame)) 
    camera.inputStream.stop()  
    video_writer.release()  

  def get_start_videofile_number(self):
    return 2

问题是保存在输出位置中的文件已损坏,文件大小为6 KB,并且不包含任何内容(看起来最初没有读取任何帧)。有人可以帮我解决这里可能出了什么问题吗?

python python-3.x opencv computer-vision opencv3.0
1个回答
0
投票

我不知道您为什么需要那么多代码,但我在这里https://github.com/Abdulkereem/legendary-dollop/blob/master/opcv_6.py帮助通过打开cv简化了视频录制>

© www.soinside.com 2019 - 2024. All rights reserved.