使用 R 检索视频文件持续时间(时间) [英] Retrieve video file duration (time) using R

查看:31
本文介绍了使用 R 检索视频文件持续时间(时间)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个代码来删除一些我不需要的视频文件.这些视频来自闭路电视录像,它们是 24/7 全天候录制的.然而,录制视频的软件将文件保存在大约 1 小时的视频中,这就是问题所在(不是确切的持续时间).我只对保留一天中特定时间段的视频感兴趣(这会有所不同),而且由于视频的时长不准确,这给我带来了问题.

I’m creating a code to delete some video files that I don’t need. The videos are from CCTV footage and they record 24/7. However the software that records the video saves the files in ~1 hour videos and this is the problem (not being exact duration). I’m only interested in keeping videos from a particular part of the day (which varies) and because the duration of the video is not exact this is causing me problems.

视频文件名有日期和时间戳,但仅用于开始,所以如果我能找到持续时间,一切都变得简单代数.

The video file name has a date and time stamp but only for the start so if I could find the duration everything becomes simple algebra.

所以我的问题很简单,是否可以使用 R 获取视频文件的持续时间(时间)?

So my question is simple is it possible to get the duration (time) of video files using R?

只有一些其他有用的信息,视频来自多个摄像机,每个摄像机作为不同的录制帧速率,因此使用 file.info 返回文件大小并导出视频长度不是一种选择.视频文件也是 .avi 格式.

Just a couple of other useful information the videos are from several cameras and each camera as a different recording frame rate so using file.info to return the file size and derive the length of the video is not an option. Also the video files are in .avi format.

干杯帕特劳

推荐答案

据我所知,没有现成的包可以处理 R 中的视频文件(就像 matlab 那样).这不是纯 R 解决方案,但可以完成工作.我将 CLI 界面安装到 MediaInfo 并从R. 我使用 system 调用它.

As far as I know, there are no ready packages that handle video files in R (like matlab does). This isn't a pure R solution, but gets the job done. I installed CLI interface to MediaInfo and called it from R. I called it using system.

wolf <- system("q:/mi_cli/mediainfo.exe Krofel_video2volk2.AVI", intern = TRUE)
wolf # output by MediaInfo

[1] "General"                                                            
 [2] "Complete name                            : Krofel_video2volk2.AVI"  
 [3] "Format                                   : AVI"                     
 [4] "Format/Info                              : Audio Video Interleave"  
 [5] "File size                                : 10.7 MiB"                
 [6] "Duration                                 : 11s 188ms"               
 [7] "Overall bit rate                         : 8 016 Kbps"              
 ...        
[37] "Channel count                            : 1 channel"               
[38] "Sampling rate                            : 8 000 Hz"                
[39] "Bit depth                                : 16 bits"                 
[40] "Stream size                              : 174 KiB (2%)"            
[41] "Alignment                                : Aligned on interleaves"  
[42] "Interleave, duration                     : 63 ms (1.00 video frame)"

# Find where Duration is (general) and extract it.
find.duration <- grepl("Duration", wolf)
wolf[find.duration][1]# 1 = General, 2 = Video, 3 = Audio
[1] "Duration                                 : 11s 188ms"

享受解析时间的乐趣.

这篇关于使用 R 检索视频文件持续时间(时间)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆