1

I'm looking for a way to get the video duration from avi file path in Node-Webkit, one that does not involve using ffmpeg.

ffprobe.exe is a large file (30mb) and it seems a bit to much to keep it all when this is the only thing I would need it for.

Jaruba
  • 1,055
  • 11
  • 22

2 Answers2

0

Reading the video properties of a file, such as duration, bitrate, resolution, etc, requires some decoding. So, yes, you need ffmpeg.

Once you have it, you can use the HTML5 audio and video features.

https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Using_HTML5_audio_and_video

javorosas
  • 759
  • 1
  • 12
  • 22
0

There is a node module : avprober which is a wrapper around the command line tool avprobe which comes bundled with install of avconv

It reveals details of given media file like Duration

... alternatively, here is some python which uses hachoir to parse media header info ... and it does handle video files (AVI,mp4, etc) to reveal Duration

import sys

from hachoir_core.cmd_line import unicodeFilename
from hachoir_core.i18n import getTerminalCharset
from hachoir_metadata import extractMetadata
from hachoir_parser import createParser


filename = sys.argv[1]
charset = getTerminalCharset()
filename, real_filename = unicodeFilename(filename, charset), filename
parser = createParser(filename, real_filename=real_filename)
metadata = extractMetadata(parser)
print("Duration (hh:mm:ss.f): %s" % metadata.get('duration'))
Scott Stensland
  • 26,870
  • 12
  • 93
  • 104
  • I've downloaded the libav package, but it has 160mb, is there any way to strip libav to the minimum required to use avprobe? – Jaruba Feb 18 '15 at 00:27
  • Once you compile libav the executable avprobe is just 64 kbytes yet it dynamically links with *MANY* object files which must be available on any target system ... it is open source ... possibly Duration is a field in some header and can be read directly with minimal code dunno without digging further – Scott Stensland Feb 18 '15 at 17:59
  • here are some leads on header format https://stackoverflow.com/questions/3057157/anyone-familiar-with-mp4-data-structure – Scott Stensland Feb 18 '15 at 18:02
  • I'll try any solution out, I'm doing this with ".avi" files, vlc doesn't ever update the duration through playback and I'm using a libvlc based plugin. ffprobe is 30mb big, it doesn't get the right duration at the start, it takes about 2-4 minutes until it can get the correct duration (depending on downloading speed, because I'm using it on partially downloaded files). So I'm looking for the smallest, fastest way to getting the duration in this scenario. – Jaruba Feb 18 '15 at 19:22
  • looks like HTML5 File API can access Duration ... also here is come code which retrieves Duration given a mp4 file http://jsfiddle.net/derickbailey/s4P2v/ – Scott Stensland Feb 18 '15 at 19:27
  • doesn't work for avi files, I don't think avi files include duration in the header. I'm a bit unsure on how it is calculated by ffprobe correctly from partially downloaded files. – Jaruba Feb 18 '15 at 19:52