简体   繁体   English

如何从 a.yuv 视频文件中提取某些帧并使用 FFmpeg、OpenCV 和 python 创建新视频?

[英]How to extract certain frames from a .yuv video file and create a new video using FFmpeg, OpenCV and python?

I have a.yuv video file and a list containing some frame numbers.我有一个 .yuv 视频文件和一个包含一些帧号的列表。 I need to make a new video with the frame numbers in the list and another video with the frame numbers that are not on the list.我需要用列表中的帧号制作一个新视频,并用不在列表中的帧号制作另一个视频。 How can I do this using FFmpeg and subprocess module in python?如何使用 FFmpeg 和 python 中的子进程模块来执行此操作? I'm also using OpenCV in the program.我也在程序中使用 OpenCV。 I need the new videos in both.yuv and.avi formats.我需要 .yuv 和 .avi 格式的新视频。

Something like this:像这样的东西:

Open the YUV file in `rb` mode.
Open `inlist.yuv` and `notinlist.yuv` in `wb` mode.
Zero frame counter
Repeat until no more data in input file
    Read `framesize` bytes
    if framenumber in list:
        write to "inlist.yuv"
    else:
        write to "notinlist.yuv"
    Increment frame counter
Close files

As Rotem suggests, use ffmpeg to convert your 2 output files to AVI at the end.正如 Rotem 建议的那样,最后使用ffmpeg将您的 2 个 output 文件转换为 AVI。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 python 和 openCV 从 .yuv 视频文件 (YUV420) 中提取帧? - How to extract frames from a .yuv video file (YUV420) using python and openCV? 如何使用python从帧创建视频? - How to create video from frames using python? OpenCV + python - 从视频文件中获取帧 - OpenCV + python — grab frames from a video file FFmpeg stream 视频从帧 OpenCV Z23EEEB4347BDD265DFC6B7EE9AB3B7 到 rtmp - FFmpeg stream video to rtmp from frames OpenCV python 使用opencv和python从视频中提取帧 - extracting frames from a video using opencv and python 如何使用 FFmpeg 和 python 中的子进程模块将.mp4视频文件转换为.yuv(YUV420),反之亦然? - How to convert .mp4 video file to .yuv (YUV420) and vice-versa using FFmpeg and subprocess module in python? 使用纯python将视频提取到帧中(不使用openCV) - Extract video into frames using pure python(without using openCV) OpenCV 和 Python:如何记录和保存一定数量的视频帧? - OpenCV and Python: How to record and save certain number of video frames? 如何使用ffmpeg从视频中提取帧并在内存中作为python中的图像列表读取而不写入文件 - How to use ffmpeg to extract frames from video and read as a list of images in python in memory without writing files 如何使用Opencv和Python从视频流中提取特定帧 - how to extract a particular frame from video stream using Opencv & Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM