在R

时间:2015-09-27 20:02:59

标签: r ffmpeg data.table

我正在研究使用ffprobedata.table包在R中提取胶片持续时间的最快方法。

设置示例源媒体

wget https://ia801403.us.archive.org/13/items/AboutBan1935/AboutBan1935_512kb.mp4
mv AboutBan1935_512kb.mp4 one.mp4
for file in two.mp4 three.mp4 four.mp4 five.mp4 ; do cp one.mp4 "$file" ; done

各种方法

library(data.table)
library(parallel)

# Get locations
executables <- Sys.which(c('ffprobe', 'ffmpeg'))

# Duration Function
get_duration_parallel <- function(files){
  mclapply(X = files, FUN = function(file){
    ffprobe_duration <- paste(executables['ffprobe'],
                              " -v quiet -print_format compact=print_section=0:nokey=1:escape=csv -show_entries format=duration ",
                              '"', file, '"', sep = "")

    file_duration <- as.numeric(system(command = ffprobe_duration, intern = TRUE))
    return(file_duration)
  }, mc.cores = detectCores())
}

get_duration <- function(files){
  sapply(X = files, FUN = function(file){
    ffprobe_duration <- paste(executables['ffprobe'],
                              " -v quiet -print_format compact=print_section=0:nokey=1:escape=csv -show_entries format=duration ",
                              '"', file, '"', sep = "")

    file_duration <- as.numeric(system(command = ffprobe_duration, intern = TRUE))
    return(file_duration)
  })
}

# Example table
dt <- data.table(Path = list.files(path = ".", pattern = "*.mp4$"))


system.time(
  dt[, Seconds := get_duration_parallel(Path)]
)
# 9.667 seconds    

system.time(
  dt[, Seconds := get_duration(Path)]
)
# 0.078 seconds

我错过了任何明显的加速吗?扫描500个档案的ffprobe统计档案需要大约5分钟的测试时间。

0 个答案:

没有答案