Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get length of a video using regex and ffmpeg

Tags:

regex

ffmpeg

From the following ffmpeg -i output, how would I get the length (00:35)--

$ ffmpeg -i 1video.mp4

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/david/Desktop/1video.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 1
    compatible_brands: isomavc1
     creation_time   : 2010-01-24 00:55:16
  Duration: 00:00:35.08, start: 0.000000, bitrate: 354 kb/s
    Stream #0.0(und): Video: h264 (High), yuv420p, 640x360 [PAR 1:1 DAR 16:9], 597 kb/s, 25 fps, 25 tbr, 25k tbn, 50 tbc
    Metadata:
      creation_time   : 2010-01-24 00:55:16
    Stream #0.1(und): Audio: aac, 44100 Hz, stereo, s16, 109 kb/s
    Metadata:
      creation_time   : 2010-01-24 00:55:17
At least one output file must be specified
like image 328
David542 Avatar asked Sep 12 '11 23:09

David542


People also ask

How do I get the width of a video in FFmpeg?

-show_entries stream=width,height Just show the width and height stream information. -of option chooses the output format (default, compact, csv, flat, ini, json, xml).

How do I set video duration in FFmpeg?

Use the -t option to specify a time limit: `-t duration' Restrict the transcoded/captured video sequence to the duration specified in seconds. hh:mm:ss[.

What is FFmpeg and Ffprobe?

The FFmpeg library, ffprobe, can rightly be called the Swiss Army Knife of video information extraction or video inspection. As the FFmpeg documentation succinctly puts it, ffprobe gathers information from multimedia streams and prints it in human- and machine-readable fashion.


1 Answers

This way you get the duration in seconds. I think this is more convenient.

ffprobe -loglevel error -show_streams inputFile.mp3 | grep duration | cut -f2 -d=

ffprobe comes with ffmpeg so you should have it.


EDIT: For a more dedicated version you could use for example

ffprobe -loglevel error -show_format -show_streams inputFile.extension -print_format json

Instead of JSON you could also use e.g. CSV or XML. For more output options look here http://ffmpeg.org/ffprobe.html#Writers

like image 63
Taner Topal Avatar answered Sep 20 '22 05:09

Taner Topal