I use this code for extracting video information by ffprobe :
ffprobe -show_streams -of json -v quiet -i input.mp4
The information of all streams appears in the output while I need only the information of v:0 and a:0 streams.
I know that there is -select_streams
option for stream selection but it accepts only one argument like: -select_streams v:0
.
Can I use -select_streams
by two arguments v:0
and a:0
or using it twice?
You can simply omit the -select_streams
argument and use the -show_entries
argument to pass
the fields you would like to see in the output, like so:
ffprobe -show_streams -show_entries format=bit_rate,filename,start_time:stream=duration,width,height,display_aspect_ratio,r_frame_rate,bit_rate -of json -v quiet -i input.mp4
That should give you an output similar to this:
{
"programs": [
],
"streams": [
{
"width": 360,
"height": 202,
"display_aspect_ratio": "16:9",
"r_frame_rate": "2997/100",
"duration": "68.601935",
"bit_rate": "449366",
"disposition": {
"default": 1,
"dub": 0,
"original": 0,
"comment": 0,
"lyrics": 0,
"karaoke": 0,
"forced": 0,
"hearing_impaired": 0,
"visual_impaired": 0,
"clean_effects": 0,
"attached_pic": 0
},
"tags": {
"language": "eng",
"handler_name": "VideoHandler"
}
},
{
"r_frame_rate": "0/0",
"duration": "68.475646",
"bit_rate": "65845",
"disposition": {
"default": 1,
"dub": 0,
"original": 0,
"comment": 0,
"lyrics": 0,
"karaoke": 0,
"forced": 0,
"hearing_impaired": 0,
"visual_impaired": 0,
"clean_effects": 0,
"attached_pic": 0
},
"tags": {
"language": "eng",
"handler_name": "SoundHandler"
}
}
],
"format": {
"filename": "input.mp4",
"start_time": "0.000000",
"bit_rate": "522013"
}
}
From which you can just index into the stream you want, as shown in Powershell, with the JSON object streams that is returned:
PS C:\Users\User> $json.streams[0]
width : 360
height : 202
display_aspect_ratio : 16:9
r_frame_rate : 2997/100
duration : 68.601935
bit_rate : 449366
disposition : @{default=1; dub=0; original=0; comment=0; lyrics=0; karaoke=0; forced=0; hearing_impaired=0; visual_impaired=0; clean_effects=0; attached_pic=0}
tags : @{language=eng; handler_name=VideoHandler}
PS C:\Users\User> $json.streams[1]
r_frame_rate : 0/0
duration : 68.475646
bit_rate : 65845
disposition : @{default=1; dub=0; original=0; comment=0; lyrics=0; karaoke=0; forced=0; hearing_impaired=0; visual_impaired=0; clean_effects=0; attached_pic=0}
tags : @{language=eng; handler_name=SoundHandler}
There are a list of the key field names that you can get from the different types of streams here: https://trac.ffmpeg.org/wiki/FFprobeTips
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With