Quantcast
Channel: Stream #0 » How-To
Viewing all articles
Browse latest Browse all 7

How-To: Find and Extract Video File Details

$
0
0

Using FFMpeg it is relatively simple to query an existing video file to find details such as video codec, audio codec, bitrates, duration and dimensions.

Use the following FFmpeg command in a terminal window:

ffmpeg -i input_file.extension

FFmpeg will just open your input file without doing anything to it. Something like this will be returned in the terminal window:

phillc@phillc-laptop:~$ ffmpeg -i 848_Termi.mov
FFmpeg version SVN-r11213, Copyright (c) 2000-2007 Fabrice Bellard, et al.
configuration: –enable-gpl –enable-pp –enable-libvorbis
–enable-libtheora –enable-liba52 –enable-libdc1394 –enable-libgsm
–enable-libmp3lame –enable-libfaad –enable-libfaac –enable-libxvid
–enable-pthreads –enable-libx264
libavutil version: 49.6.0
libavcodec version: 51.49.0
libavformat version: 52.2.0
built on Dec 13 2007 20:20:36, gcc: 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from ’848_Termi.mov’:
Duration: 00:00:51.7, start: 0.000000, bitrate: 862 kb/s
Stream #0.0(eng): Video: h264, yuv420p, 480×360 [PAR 0:1 DAR 0:1], 25.00 tb(r)
Stream #0.1(eng): Audio: mpeg4aac, 44100 Hz, stereo
Must supply at least one output file

All very interesting, but what if you want to do something more with this information, like write it to a file for use in another program, or just want a more convenient way of viewing the details without having to remember an FFmpeg command? Write a small script to do the work for you. Here’s one I created earlier in Perl…….

#!/usr/bin/perl

# Read command line input file

 
$input_file = shift;

 
# Read details of input file and display to user

 
$ffmpeg_input_details="ffmpeg -i ${input_file} 2>input_file.txt";

system($ffmpeg_input_details);

 
open(INPUTFILE,"input_file.txt");

@inputfile = <INPUTFILE>;

@input_file_video = grep (/Video:/i, @inputfile);

@input_file_audio = grep (/Audio:/i, @inputfile);
@input_file_duration = grep (/Duration:/i, @inputfile); 
 
print "Details for the file $input_file.\n";

print "It contains the following video data:\n"; 

print "@input_file_video\n";

print "It contains the following audio data:\n"; 

print "@input_file_audio\n";
print "It has a duration and bitrate of:\n"; 

print "@input_file_duration\n";

To use this script simply type the following at your command prompt:

perl scriptname.pl input_file.extension

Good luck extending this small script for your own uses.



Viewing all articles
Browse latest Browse all 7

Trending Articles