简体   繁体   English

获取上传的音频/视频文件的持续时间

[英]Get duration of an uploaded audio/video file

I want to get the duration of audio/video files that are being uploaded into the system. 我想获取上传到系统中的音频/视频文件的持续时间。 Earlier I had used hachoir-metadata , but it's not maintained anymore I guess, as there is no python 3 compatible module for that. 之前我使用过hachoir-metadata ,但是我猜它不再维护了,因为没有python 3兼容模块。

  • IS there any other light weight alternative to it? 还有其他轻巧的替代品吗?
  • In case if I wish to write something of my own to do it, what would be the prerequisites? 如果我想编写自己的东西来做,那么先决条件是什么?

For anyone looking for this particular thing, follow following steps: 对于寻找此特定事物的任何人,请执行以下步骤:

  • Make sure you have libav-tools package installed. 确保已安装libav-tools软件包。 You can check it by typing and trying to execute avconv command. 您可以通过键入并尝试执行avconv命令来检查它。 If not present, do sudo apt-get install libav-tools 如果不存在,请执行sudo apt-get install libav-tools
  • Then, try this command ffmpeg -i myvideo 2>&1 | grep Duration | cut -d ' ' -f 4 | sed s/,// 然后,尝试使用此命令ffmpeg -i myvideo 2>&1 | grep Duration | cut -d ' ' -f 4 | sed s/,// ffmpeg -i myvideo 2>&1 | grep Duration | cut -d ' ' -f 4 | sed s/,// ffmpeg -i myvideo 2>&1 | grep Duration | cut -d ' ' -f 4 | sed s/,// (I found this command here ). ffmpeg -i myvideo 2>&1 | grep Duration | cut -d ' ' -f 4 | sed s/,// (我在这里找到此命令)。
  • If you want to use it in python script, you can probably use subprocess module to your effect 如果要在python脚本中使用它,则可以使用subprocess模块​​发挥作用

Correct me if I am wrong somewhere 如果我在某个地方错了,请纠正我

if you know about ffmpeg , you can use ffmpeg to read the audio or video, it will output the duration of audio or video 如果您了解ffmpeg ,则可以使用ffmpeg读取音频或视频,它将输出音频或视频的持续时间

$ ffmpeg -i  "Gotye - Somebody That I Used To Know (feat. Kimbra) - official video.mp4" 2>&1 | grep -E -o "Duration: \S+" 
Duration: 00:04:03.90,

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

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