FFmpeg: Read profile level information from mp4

佐手、 提交于 2019-12-03 13:09:51

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]

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):
High@4.1


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

alrama

You could use MP4Box with option -info for this kind of output:

Track # 2 Info - TrackID 2 - TimeScale 25000 - Duration 01:29:42.160
Media Info: Language "Undetermined" - Type "vide:avc1" - 134554 samples
MPEG-4 Config: Visual Stream - ObjectTypeIndication 0x21
AVC/H264 Video - Visual Size 1280 x 720 - **Profile High @ Level 3.1**
NAL Unit length bits: 32
Pixel Aspect Ratio 1:1 - Indicated track size 1280 x 720
Synchronized on stream 1
Harit Vishwakarma

try the following to get the more detailed output in json

$ ffprobe -print_format json -show_streams -show_format <filepath>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!