【问题标题】:Reading a video file without openCV in python在python中读取没有openCV的视频文件
【发布时间】:2020-10-28 11:27:48
【问题描述】:

我想读取一个视频文件并将帧保存在 python 列表中,类似于缓冲区读取。我不想使用 opencv (cv2.VideoCapture) 或任何其他库来读取视频文件。任何线索我该怎么做?

提前致谢。

【问题讨论】:

  • 谁对这个问题投了反对票,你能解释一下原因吗?
  • 对不起,在这里请求图书馆认可是题外话,因为它会导致基于意见的答案。尝试研究该主题并尝试一些您偶然发现的方法,如果您有关于该主题的特定问题,请回来。
  • 谷歌搜索 python read video without opencv 提供了一些线索:stackoverflow.com/questions/44140354/…scikit-image.org/docs/dev/user_guide/video.html
  • 对不起,我不是在寻找任何库,我想看看除了使用opencv库之外是否还有其他方法,是否可以使用python直接读取帧。
  • 大约 90 年代的谷歌搜索会为您提供至少 5 种选择(参见上面的第二个链接)...所以...您的问题是否显示了研究成果?

标签: python video bufferedreader


【解决方案1】:

你考虑过使用 ffmpeg 吗?从技术上讲,它是一个命令行工具,但可以与 Python 一起使用,如 this post 所示。这也使用了 PIL 库。

有关逐帧捕获的信息,请查看this out

【讨论】:

    【解决方案2】:

    您可以使用subprocess 模块并调用ffmpeg。您可以使用 ffmpeg 读取和写入大量不同的视频格式。

    如果您想要更符合人体工程学的界面,您还可以使用 Python 的 ffmpeg 绑定(例如,ffmpeg-python)。

    def read_frames(path, res):
        """Read numpy arrays of video frames. Path is the file path
           and res is the resolution as a tuple."""
        args = [
            "ffmpeg",
            "-i",
            path,
            "-f",
            "image2pipe",
            "-pix_fmt",
            "rgb24",
            "-vcodec",
            "rawvideo",
            "-",
        ]
    
        pipe = subprocess.Popen(
            args,
            stdout=subprocess.PIPE,
            stderr=subprocess.DEVNULL,
            bufsize=res[0] * res[1] * 3,
        )
    
        while pipe.poll() is None:
            frame = pipe.stdout.read(res[0] * res[1] * 3)
            if len(frame) > 0:
                array = np.frombuffer(frame, dtype="uint8")
                yield array.reshape((res[1], res[0], 3))
    

    【讨论】:

      猜你喜欢
      • 2012-01-06
      • 1970-01-01
      • 1970-01-01
      • 2017-05-17
      • 2023-02-04
      • 2018-03-09
      • 1970-01-01
      • 2018-03-29
      • 2014-04-30
      相关资源
      最近更新 更多