Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FFmpeg: Read profile level information from mp4

Tags:

ffmpeg

h.264

mp4

I have a mp4 file and need the profile level of it. FFmpeg says, it has baseline profile, which is what I need, but I need also the level.

Here is what I get from FFmpeg:

ffmpeg version 0.8, Copyright (c) 2000-2011 the FFmpeg developers
  built on Jul 20 2011 13:32:19 with gcc 4.4.3
  configuration: --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-libfaac --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264
  libavutil    51.  9. 1 / 51.  9. 1
  libavcodec   53.  7. 0 / 53.  7. 0
  libavformat  53.  4. 0 / 53.  4. 0
  libavdevice  53.  1. 1 / 53.  1. 1
  libavfilter   2. 23. 0 /  2. 23. 0
  libswscale    2.  0. 0 /  2.  0. 0
  libpostproc  51.  2. 0 / 51.  2. 0
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test-show.mp4':
  Metadata:
    major_brand     : f4v 
    minor_version   : 0
    compatible_brands: isommp42m4v 
    creation_time   : 2012-03-21 16:00:00
  Duration: 00:56:07.40, start: 0.000000, bitrate: 2004 kb/s
    Stream #0.0(eng): Video: h264 (Baseline), yuv420p, 854x480 [PAR 1:1 DAR 427:240], 1904 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc
    Metadata:
      creation_time   : 2012-03-21 16:00:00
    Stream #0.1(eng): Audio: aac, 48000 Hz, stereo, s16, 96 kb/s
    Metadata:
      creation_time   : 2012-03-21 16:00:00
At least one output file must be specified

Is there any option other than -i I can use to get the level information?

like image 294
Martin Avatar asked Apr 20 '12 08:04

Martin


2 Answers

ffprobe with show_entries command should be faster, and it has more options to show only relevant data and to filter only video stream.

to filter only video (add also :0 to filter only first video stream)

ffprobe -v error -select_streams v:0 -show_entries stream=level -of default=noprint_wrappers=1 <filepath>

e.g. OUTPUT:
level=50


to output only the value (add :nokey=1):

ffprobe -v error -select_streams v:0 -show_entries stream=level -of default=noprint_wrappers=1:nokey=1 <filepath>

e.g. OUTPUT:
50


to output both Profile and Level in one go:

ffprobe -v error -select_streams v:0 -show_entries stream=profile,level -of default=noprint_wrappers=1 <filepath>

e.g. OUTPUT:
profile=High
level=50


to output in json format:

ffprobe -v error -select_streams v:0 -show_entries stream=profile,level -of json <filepath>

e.g. OUTPUT:

{
    "programs": [

    ],
    "streams": [
        {
            "profile": "High",
            "level": 41
        }
    ]
}

in a MS batch file (as fake function):
call :ffprobeGetFormatProfile ffprobe.exe file.mp4 txtFormat

:ffprobeGetFormatProfile <exe> <infile> <outStr>
echo.
echo FILE: %2

set tmpProfile=
set tmpLevel=
for /f "usebackq delims== tokens=1-2" %%a in (`%~s1 -v error -select_streams v:0 -show_entries stream^=profile^,level -of default^=noprint_wrappers^=1 %2`) do (
    if /I %%a == profile set tmpProfile=%%b
    if /I %%a == level set tmpLevel=%%b
)
if not defined tmpLevel set tmpLevel=??
echo on
set %3=%tmpProfile%@%tmpLevel:~0,1%.%tmpLevel:~1%
@echo off

exit /b %errorlevel%

e.g. OUTPUT (in a variable txtFormat passed as 3rd argument):
[email protected]


You can get some more ideas from ffmpeg.org - Tips

like image 171
papo Avatar answered Oct 24 '22 20:10

papo


Try ffprobe -show_streams.

ffprobe is bundled with FFmpeg and gives lots of information about video files including level information, e.g.:

$ ffprobe -loglevel error -show_streams Test.mp4 
[STREAM]
index=0
codec_name=h264
codec_long_name=H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
codec_type=video
codec_time_base=1001/48000
codec_tag_string=avc1
codec_tag=0x31637661
width=704
height=400
has_b_frames=0
sample_aspect_ratio=N/A
display_aspect_ratio=N/A
pix_fmt=yuv420p
level=51                 <== level!
timecode=N/A
is_avc=1
nal_length_size=4
id=N/A
r_frame_rate=24000/1001
avg_frame_rate=1384898760/57761819
time_base=1/44100
start_time=0.000000
duration=6548.959070
bit_rate=701946
nb_frames=157018
nb_read_frames=N/A
nb_read_packets=N/A
TAG:creation_time=2006-08-17 18:14:49
TAG:language=eng
TAG:handler_name=
[/STREAM]
like image 22
blahdiblah Avatar answered Oct 24 '22 20:10

blahdiblah