简体   繁体   English

仅从 OpenCV 的视频捕获中读取 mp4 文件的一部分

[英]Reading only part of mp4 file from OpenCV's videocapture

I want to read only a part of mp4 file using Videocapture, this is my sample code to read whole mp4 in Videocapture object.我只想使用 Videocapture 读取 mp4 文件的一部分,这是我在 Videocapture 对象中读取整个 mp4 的示例代码。

VideoCapture cap("demo.mp4");

Is it possible to read only a part of file ,ie from 10 seconds to 50 seconds.是否可以只读取文件的一部分,即从 10 秒到 50 秒。 As the demo.mp4 is much big file so I don't want to load the remaining part in object which increases memory usage of program.由于 demo.mp4 文件很大,所以我不想加载对象中的剩余部分,这会增加程序的内存使用量。

I also used cap.set(CAP_PROP_POS_FRAMES, start_frame);我也用过cap.set(CAP_PROP_POS_FRAMES, start_frame); ,this works but it doesn't solve the memory usage issue. ,这有效,但不能解决内存使用问题。

Thank You谢谢你

You could try to cut your video with ffmpeg before opening with VideoCapture .在使用VideoCapture打开之前,您可以尝试使用ffmpeg剪切视频。 For example, to get 40 seconds fragment from 00:10 to 00:50, the command is例如,要获取从 00:10 到 00:50 的 40 秒片段,命令是

ffmpeg -i 'input.mp4' -ss '00:00:10' -t '00:00:40' output.mp4

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM