I can get number of audio streams and number of "All" streams but cannot output the number of video streams.
I use this ...
REM Get the number of "All" and "audio" streams. Video stream is calculated from those two. i.e. Video = All - Audio.
for /F "delims=" %%I in ('ffprobe -v error -show_entries format^=nb_streams -of default^=noprint_wrappers^=1:nokey^=1 "%_INPUT_FILE%" 2^>^&1') do set "_NUM_OF_ALL_STREAMS=%%I"
for /F "delims=" %%I in ('ffprobe -v error -select_streams a -show_entries stream^=index -of default^=noprint_wrappers^=1:nokey^=1 "%_INPUT_FILE%" 2^>^&1') do set "_NUM_OF_AUDIO_STREAMS=%%I"
REM for /F "delims=" %%I in ('ffprobe -v error -select_streams v -show_entries stream^=index -of default^=noprint_wrappers^=1:nokey^=1 "%_INPUT_FILE%" 2^>^&1') do set "_NUM_OF_VIDEO_STREAMS=%%I"
It always returns 0 for video streams.
+ Reply to Thread
Results 1 to 30 of 46
-
-
Sure, thanks. That command returns the following ...
ffmpeg version 2024-11-25-git-04ce01df0b-full_build-www.gyan.dev Copyright (c) 2000-2024 the FFmpeg developers
built with gcc 14.2.0 (Rev1, Built by MSYS2 project)
configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libaribb24 --enable-libaribcaption --enable-libdav1d --enable-libdavs2 --enable-libopenjpeg --enable-libquirc --enable-libuavs3d --enable-libxevd --enable-libzvbi --enable-libqrencode --enable-librav1e --enable-libsvtav1 --enable-libvvenc --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxeve --enable-libxvid --enable-libaom --enable-libjxl --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-dxva2 --enable-d3d11va --enable-d3d12va --enable-ffnvcodec --enable-libvpl --enable-nvdec --enable-nvenc --enable-vaapi --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libcodec2 --enable-libilbc --enable-libgsm --enable-liblc3 --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
libavutil 59. 47.101 / 59. 47.101
libavcodec 61. 25.103 / 61. 25.103
libavformat 61. 9.100 / 61. 9.100
libavdevice 61. 4.100 / 61. 4.100
libavfilter 10. 6.101 / 10. 6.101
libswscale 8. 12.100 / 8. 12.100
libswresample 5. 4.100 / 5. 4.100
libpostproc 58. 4.100 / 58. 4.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '4s.mov':
Metadata:
major_brand : qt
minor_version : 512
compatible_brands: qt
date : 2013-07-21T13:55:57+0100
date-eng : 2013-07-21T13:55:57+0100
encoder : Lavf58.48.100
make : Apple
make-eng : Apple
model : iPhone 5
model-eng : iPhone 5
Duration: 00:00:04.02, start: 0.000000, bitrate: 17919 kb/s
Stream #0:0[0x1]: Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1920x1080, 17906 kb/s, 29.98 fps, 29.97 tbr, 19200 tbn (default)
Metadata:
handler_name : Core Media Video
vendor_id : FFMP
encoder : H.264
Stream #0:1[0x2]: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 63 kb/s (default)
Metadata:
handler_name : Core Media Audio
vendor_id : [0][0][0][0]
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> wrapped_avframe (native))
Stream #0:1 -> #0:1 (aac (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Output #0, null, to 'pipe:':
Metadata:
major_brand : qt
minor_version : 512
compatible_brands: qt
date : 2013-07-21T13:55:57+0100
date-eng : 2013-07-21T13:55:57+0100
model-eng : iPhone 5
make : Apple
make-eng : Apple
model : iPhone 5
encoder : Lavf61.9.100
Stream #0:0: Video: wrapped_avframe, yuv420p(tv, bt709, progressive), 1920x1080, q=2-31, 200 kb/s, 29.97 fps, 29.97 tbn (default)
Metadata:
encoder : Lavc61.25.103 wrapped_avframe
handler_name : Core Media Video
vendor_id : FFMP
Stream #0:1: Audio: pcm_s16le, 44100 Hz, mono, s16, 705 kb/s (default)
Metadata:
encoder : Lavc61.25.103 pcm_s16le
handler_name : Core Media Audio
vendor_id : [0][0][0][0]
[out#0/null @ 00000286b86aa340] video:52KiB audio:346KiB subtitle:0KiB other streams:0KiB global headers:0KiB muxing overhead: unknown
frame= 120 fps=0.0 q=-0.0 Lsize=N/A time=00:00:04.00 bitrate=N/A speed=27.9x -
I was thinking in terms of returning a single value such as 0 or 1 or 2 etc as per my "ALL" and "Audio" syntax.
-
OK. I see some of the errors. The 1st. of the 3 syntax returns the number of all streams, Audio, Video etc.
The 2nd. and 3rd. syntax lines actually are returning the "index", not the count of any audio and video streams.
So my question needs to be restated: How can I modify the 2nd. and 3rd. syntax lines to return the count of audio/video streams.
This was my starting point … https://superuser.com/questions/1381642/ffprobe-count-video-and-audio-streams-tracks -
According to the link above the "count" of items other than "ALL" may not be available. So it's a case of using the index values to establish it.
-
simple. pipe output to grep -c
........ | grep -c "Video"
........ | grep -c "Audio" -
I think grep is Linux? I am only using Windows.
Google grep for windows ... cygwin64 -
https://stackoverflow.com/questions/1416241/is-there-a-pattern-matching-utility-like-grep-in-windows
"Thanks! It's not grep, but I like to be able to function without installing additional software on other people's machines and this will let me."
If Findstr could do it then good. It's built in. Like the above quote from link I don't wish to use non-windows utils. Thanks. -
-
I don't wish to use non-windows utils
-
Fair point. I should have been more specific, clearer. With the exception of using the ffmpeg utils in my batch files I prefer to only use the Windows utils.
That way if I pass on my batch files to anyone else they will work as is, but clear instructions for locating the ffmpeg utils and adding to the PATH are included in the readme/Help. -
Code:
@echo off setlocal EnableDelayedExpansion for %%a in ("*.mkv") do ( ffmpeg -i "%%a" -y nul 2>&1 | find /c "Video:" > count.txt set /p count= < count.txt echo Video count for "%%a" is: !count! del count.txt ) pause
-
Enhancement!
Write output to Video-List.txt. Skip if only one video in the mkv.
Code:@echo off setlocal EnableDelayedExpansion if exist Video-List.txt del Video-List.txt for %%a in ("*.mkv") do ( ffmpeg -i "%%a" -y nul 2>&1 | find /c "Video:" > count.txt set /p count= < count.txt if !count! gtr 1 echo Video count for "%%a" is: !count! >> Video-List.txt del count.txt ) pause
-
Thanks.
I tried doing a drag and drop of a single file using this but it returns 0 video, any ideas ?
@echo off
mode CON:cols=228 lines=30
color 0A
SETLOCAL EnableDelayedExpansion
SET _INPUT_FILE=%~n1%~x1
SET _INPUT_FILENAME=%~n1
SET _INPUT_EXTN=%~x1
for %%a in ("%_INPUT_FILE%") do (
ffmpeg -i "%%a" -y nul 2>&1 | find /c "Video:">count.txt
set /p count=<count.txt
echo Video count for "%%a" is: !count!
echo "%%a" !count!>>Count-of-video-streams.txt
REM del count.txt
)
pause
exit -
It's NOT drag and drop.
All the mkv files in the folder the batch file is run from are processed. -
If I remove all spaces in input file it works.
I would have thought that the "%_INPUT_FILE%" would take care of that. -
-
Got it, have it now for single plus multiple, happy days. many thanks pcspeak
@echo off
mode CON:cols=228 lines=30
color 0A
SETLOCAL EnableDelayedExpansion
REM If SET _INPUT_FILE="%~n1%~x1" is used then all program code references to input file should be so ... %_INPUT_FILE%. File will display as "My File.mp4"
REM If SET _INPUT_FILE=%~n1%~x1 is used then all program code references to input file should be so ... "%_INPUT_FILE%". File will display as My File.mp4
REM If SET "_INPUT_FILE=%~n1%~x1" is used then all program code references to input file should be so ... "%_INPUT_FILE%". File will display as My File.mp4
SET _INPUT_FILE="%~n1%~x1"
SET _INPUT_FILENAME=%~n1
SET _INPUT_EXTN=%~x1
ffmpeg -i %_INPUT_FILE% -y nul 2>&1 | find /c "Video:">count.txt
set /p count=<count.txt
echo Video count for %_INPUT_FILE% is: !count!
echo %_INPUT_FILE% !count!>>Count-of-video-streams.txt
del count.txt
pause
exit -
he issue you're facing is due to how you're using ffprobe with the -select_streams v option. Unlike -select_streams a, which lists audio streams, -select_streams v filters video streams but doesn't directly provide a count unless used with specific entries or techniques.
Here’s how you can correctly calculate the number of video streams:
Corrected Approach
Use ffprobe to count the total streams (nb_streams).
Use -select_streams a to count audio streams.
Use -select_streams v to count video streams directly.
Here’s an updated script:
REM Get the total number of streams (all types)
for /F "delims=" %%I in ('ffprobe -v error -show_entries format^=nb_streams -of default^=noprint_wrappers^=1:nokey^=1 "%_INPUT_FILE%" 2^>^&1') do set "_NUM_OF_ALL_STREAMS=%%I"
REM Get the number of audio streams
for /F "delims=" %%I in ('ffprobe -v error -select_streams a -show_entries stream^=index -of csv=p^=0 -of csv^=s^=, "%_INPUT_FILE%" 2^>^&1 ^| find /C ","') do set "_NUM_OF_AUDIO_STREAMS=%%I"
REM Get the number of video streams
for /F "delims=" %%I in ('ffprobe -v error -select_streams v -show_entries stream^=index -of csv=p^=0 -of csv^=s^=, "%_INPUT_FILE%" 2^>^&1 ^| find /C ","') do set "_NUM_OF_VIDEO_STREAMS=%%I"
REM Debug output
echo Total Streams: %_NUM_OF_ALL_STREAMS%
echo Audio Streams: %_NUM_OF_AUDIO_STREAMS%
echo Video Streams: %_NUM_OF_VIDEO_STREAMS% -
Impressive indeed. I'd never have got there. Thanks.
However. It doesn't return the correct number of video streams in a test file with 2 video streams. It returns only a value of 1.
In case an error has crept in on my part this is what I used.
REM Get the total number of streams (all types)
for /F "delims=" %%I in ('ffprobe -v error -show_entries format^=nb_streams -of default^=noprint_wrappers^=1:nokey^=1 "%_INPUT_FILE%" 2^>^&1') do set "_NUM_OF_ALL_STREAMS=%%I"
REM Get the number of audio streams
for /F "delims=" %%I in ('ffprobe -v error -select_streams a -show_entries stream^=index -of csv=p^=0 -of csv^=s^=, "%_INPUT_FILE%" 2^>^&1 ^| find /C ","') do set "_NUM_OF_AUDIO_STREAMS=%%I"
REM Get the number of video streams
for /F "delims=" %%I in ('ffprobe -v error -select_streams v -show_entries stream^=index -of csv=p^=0 -of csv^=s^=, "%_INPUT_FILE%" 2^>^&1 ^| find /C ","') do set "_NUM_OF_VIDEO_STREAMS=%%I"
REM Debug output
echo Total Streams: %_NUM_OF_ALL_STREAMS%
echo Audio Streams: %_NUM_OF_AUDIO_STREAMS%
echo Video Streams: %_NUM_OF_VIDEO_STREAMS%
pause
exitLast edited by JN-; 11th Dec 2024 at 04:54.
-
This is a sample file with 2 video streams. https://www.dropbox.com/scl/fo/jm62of70hdlgogwab0c4l/AIkVHEseqimENB4vOn-CaCg?rlkey=2so...xbz8bumz7&dl=0
Perhaps your code is only returning the video index? But thats unlikely as with a single video stream it returns 1 not 0.Last edited by JN-; 11th Dec 2024 at 04:55.
-
I had a think overnight.
Not tested thoroughly. Put the batch file in with a bunch of mkv videos, run it and see what you get.
stream-count.cmdCode:@echo off setlocal EnableDelayedExpansion if exist Video-List.txt del Video-List.txt for %%a in ("*.mkv") do ( for %%b in (Video: Audio: Subtitle:) do ( ffmpeg -i "%%a" -y nul 2>&1 | find /c "%%b" > count.txt set /p count= < count.txt if %%b equ Video: (echo "%%a" >> Video-List.txt && echo %%b !count! >> Video-List.txt ) else ( echo %%b !count! >> Video-List.txt set count= ) ) echo. >> Video-List.txt ) start "" /I Video-List.txt
-
Definitely works as far as I can see. Tested on:
A "Pretend" empty video file
A video file with subtitles
A video file with one or multiple audio
A video file with audio, no video
A video file with 2 video streams
All above .mp4.
A video file with video, no audio, .asf.
Typical output:
"#PRETEND video file.mp4"
Video: 0
Audio: 0
Subtitle: 0
"01 - Dancing Queen.mp4"
Video: 0
Audio: 1
Subtitle: 0
"2-video-streams.MP4"
Video: 2
Audio: 1
Subtitle: 0
"Conv #Has 12 audio streams.mp4"
Video: 1
Audio: 12
Subtitle: 0
"DJI_0033, two video streams, one audio,.MP4"
Video: 2
Audio: 1
Subtitle: 0
"No Audio, 1 video only, - Original, DJI_0796_000.MP4"
Video: 1
Audio: 0
Subtitle: 0
"Subtitles.mp4"
Video: 1
Audio: 2
Subtitle: 1
"z-2-video-streams.MP4"
Video: 2
Audio: 1
Subtitle: 0Last edited by JN-; 11th Dec 2024 at 15:48.
Similar Threads
-
StaxRip, x265, and multiple video streams
By Mr Chris in forum Video ConversionReplies: 1Last Post: 6th Mar 2023, 16:43 -
Adding 2 audio streams to a video
By Jawz22 in forum EditingReplies: 9Last Post: 4th Nov 2022, 20:31 -
Nero Video has hard limit on number of menu entries
By ravenswd in forum Authoring (DVD)Replies: 5Last Post: 17th Jan 2022, 04:46 -
BluRay with 2 video streams
By JosephTocco in forum Newbie / General discussionsReplies: 2Last Post: 4th Sep 2021, 08:35 -
Downloading video streams from Iqiyi
By Sori in forum Video Streaming DownloadingReplies: 18Last Post: 14th May 2021, 12:48