1

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.

  • 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?
icedwater
  • 4,701
  • 3
  • 35
  • 50
Rajesh Yogeshwar
  • 2,111
  • 2
  • 18
  • 37
  • If you have ffmpeg installed you can use ffprobe, as shown in [this answer](http://stackoverflow.com/a/31025482/4014959); it should work on any audio or video file that ffmpeg supports, which is just about everything. – PM 2Ring Jan 18 '16 at 07:03

2 Answers2

1

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,
Hackaholic
  • 19,069
  • 5
  • 54
  • 72
1

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

Community
  • 1
  • 1
Rajesh Yogeshwar
  • 2,111
  • 2
  • 18
  • 37