ffprobe select audio and video streams
Solution 1
I know that I'm late to the party, but in case anybody else searches for something similar (from here):
ffprobe -show_streams -select_streams a INPUT
where a stands for audio and could of course be replaced by:
- v for video;
- a:1 for the audio packets belonging to audio stream with index 1;
- v:99 for the video packets belonging to video stream with index 99 and so on.
Note that if you want to view 2 different streams (like audio and video) you need to run ffprobe twice.
For more goodies, although very generally written, you can also check: https://trac.ffmpeg.org/wiki/FFprobeTips
Solution 2
I had a similar scenario where I wanted to limit the output of ffprobe -show_frames to a specific audio and video streams.
It seems that -select_streams cannot accept more than 1 stream_specifier nor can it be provided multiple times for the same ffprobe command.
Moreover, ffprobe do not accept the -map parameter like ffmpeg does. This parameters allows ffmpeg to process specific streams and can be provided multiple times.
What I ended up doing is filtering the required streams using ffmpeg -map and piping the output to ffprobe -show_frames as follows:
ffmpeg -i INPUT -map 0:0 -map 0:1 -c copy -f matroska - | ffprobe -show_frames -
Several notes:
- I used -f matroska in ffmpeg command since this muxer support non-seekable output (stdout)
- the -c copy is necessary to avoid transcoding of the selected streams.
Solution 3
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
![Amin Fazlali](https://i.stack.imgur.com/faa0h.jpg?s=256&g=1)
Amin Fazlali
Updated on July 06, 2022Comments
-
Amin Fazlali almost 2 years
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 argumentsv:0
anda:0
or using it twice? -
jpillora over 3 yearsFurthermore, if you want all
stream
andformat
information, you can omit=field,field,field...
and just useffprobe -show_streams -show_entries "format:stream" -of json -v quiet -i input.mp4