4

Every answer I've found to get a video's duration with ffmpeg contains grep, which cmd doesn't natively have.

I know there's a "Grep for windows" thing, but I'd rather use a function that comes with the command line.

So when I do ffmpeg -i input I get

Input #0, flv, from 'vid_test001.flv':
  Metadata:
    creationdate    : Fri Sep 19 15:58:17
  Duration: 00:00:12.44, start: 0.000000, bitrate: 806 kb/s
    Stream #0:0: Video: flv1, yuv420p, 320x240, 1k tbr, 1k tbn, 1k tbc
    Stream #0:1: Audio: nellymoser, 22050 Hz, mono, flt

I'd like to to get the Duration from this, which is "00:00:12.44" in this case

2 Answers2

4
ffmpeg -i "inputFile" 2>&1 | for /f "tokens=2 delims=, " %a in ('findstr /r /c:"^ *Duration:"') do echo %a

Execute ffmpeg on the input file, sending the output of stderr (where ffmpeg writes its information by default) to the standard output. Filter the list with findstr to retrieve the lines that begin with spaces followed by Duration:. For each line found, spaces and commas as considered as field delimiters and the second token in the line is requested, that is, the time after the Duration: label. This value is retrieved into the for replaceable parameter %a that is echoed to console.

To use from batch file, escape percent signs, replacing % with %%

MC ND
  • 1,561
1

If you're not opposed to using Powershell (comes standard in recent versions of Windows), you can make use of the Select-String command.

Here's a great post from another Superuser question - link

Basically, you can take the output of the command and pipe the results to select-string.