Is it possible to get video length from an uploaded file (EXIF data for videos?)

416
3
03-07-2023 07:13 AM
MaryGraceMcClellan
New Contributor III

I have a survey that provides users the option to upload a file, with the assumption that the file will be a video. I would like to be able to automatically pull in how long the video is, but it seems like EXIF data is only available for static images. Is there any way to get this information? 

0 Kudos
3 Replies
quillaja
New Contributor III

I'm working on a survey where we collect sound, usually recorded in the browser using the survey123 widget. It doesn't include duration(or anything else) in the metadata. I am using ffmpeg on the backend to basically copy the audio into the identical format ("-c:a copy" flag), and ffmpeg adds the duration metadata. I then use ffprobe with flags to that produce json output containing various info about the audio file, including the duration. It's an annoying work around, but perhaps something similar would work for your video files (even just ffprobe itself might).

MaryGraceMcClellan
New Contributor III

That's an interesting solution - are you referencing that through a javascript code/ffmpeg api (?) in the survey or are you doing that on your desktop once the data has been collected? 

0 Kudos
quillaja
New Contributor III

Short answer: on my desktop.

I'm not sure if ffmpeg has any javascript libraries. I'm only familiar with it as a command line tool for linux, windows, and mac. https://ffmpeg.org/

ffmpeg and ffprobe are executable programs installed on my system. Another program that downloads the audio submitted through survey123 runs these programs on the audio.

In my original post I was just copying the audio with ffmpeg, but in the end I decided to transcode it all to mp3 to make everything a uniform format. The specific ffmpeg and ffprobe commands I'm using are:

ffmpeg -y -i ORIGINAL.m4a -c:a mp3 NEW_FILE.mp3
ffprobe -i NEW_FILE.mp3 -v quiet -hide_banner -show_format -print_format json

The program gets the stuff from ffprobe that's usually printed to the screen, then parses the json to get the audio duration which I save in a database.

0 Kudos