Rajesh Yogeshwar
Rajesh Yogeshwar

Reputation: 2179

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.

Upvotes: 1

Views: 1214

Answers (2)

Rajesh Yogeshwar
Rajesh Yogeshwar

Reputation: 2179

For anyone looking for this particular thing, follow following steps:

  • Make sure you have libav-tools package installed. You can check it by typing and trying to execute avconv command. If not present, do sudo apt-get install libav-tools
  • Then, try this command ffmpeg -i myvideo 2>&1 | grep Duration | cut -d ' ' -f 4 | sed s/,// (I found this command here).
  • If you want to use it in python script, you can probably use subprocess module to your effect

Correct me if I am wrong somewhere

Upvotes: 1

Hackaholic
Hackaholic

Reputation: 19733

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 -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,

Upvotes: 1

Related Questions