我有一堆带有元数据的音频文件(比如 ogg 或 mp3)。
我希望将它们的元数据读入 R,以便创建一个 data.frame:
你知道有什么方法可以做到这一点吗?
您采用现有的 mp3 或 ogg 客户端,查看它使用的库,然后为所述库编写到 R 的绑定,使用现有客户端作为该侧的指南 - 以及 Rcpp 之类的东西作为另一侧的指南向您展示如何将 C/C++ 库连接到 R。
没有灵丹妙药。
一种更便宜且不太可靠的方法是使用 cmdline 工具来执行您想要的操作,并编写一些小帮助函数,使用
system()
在文件上运行该工具,重新读取 R 中的输出。不漂亮,不可靠,但可能不那么具有挑战性。
您可以将
exiftool
与 R 中可用的 system
命令一起使用。或者,您可以创建正则表达式来处理您需要的字段...如果我是你,我会坚持 Dirk 的建议(像往常一样)=)!
2021 年,我想这样做,所以我做了以下事情......
按照本答案中的建议,您可以使用 exiftool。
要在 R 中使用它,您可以使用exifr
(
exiftoolr
也不错):
# download a public domain mp3 file from The Internet Archive
download.file("https://archive.org/download/Jazz_Sampler-9619/Kevin_MacLeod_-_AcidJazz.mp3", "jazz.mp3", mode = "wb")
install.packages("exifr") # if necessary
exifr::read_exif("jazz.mp3") |>
mutate(location = ls()) |> # this is assuming that the file is in the working directory. If not, then you want to replace ls() with "Directory"
select(name = SourceFile,
location,
artist = Artist,
album = Album)
# Output:
# A tibble: 1 × 4
name location artist album
<chr> <chr> <chr> <chr>
1 jazz.mp3 ~ Kevin MacLeod Jazz Sampler