- 1 year ago
Windows Batch - Extract values for ffmpeg processing
To extract values for FFmpeg processing in a Windows batch script, you can use the ffprobe
command, which is a part of the FFmpeg package. ffprobe
allows you to extract metadata and information from media files.
Here's an example of a Windows batch script that extracts the duration and resolution of a video file using ffprobe
:
batch@echo off
setlocal
set video_file=path/to/video.mp4
REM Run ffprobe to extract video information
for /f "usebackq delims=" %%i in (`ffprobe -v error -select_streams v:0 -show_entries stream=duration,width,height -of csv=p=0 "%video_file%"`) do (
set "info=%%i"
)
REM Parse the extracted information
for /f "tokens=1,2,3 delims=," %%a in ("%info%") do (
set duration=%%a
set width=%%b
set height=%%c
)
echo Duration: %duration%
echo Width: %width%
echo Height: %height%
endlocal
Make sure to replace path/to/video.mp4
with the actual path to your video file.
Explanation of the script:
The
ffprobe
command is used to extract video information from the specified video file. In this example, we're extracting the duration, width, and height of the video.The
for /f
loop captures the output of theffprobe
command and assigns it to theinfo
variable.The second
for /f
loop parses theinfo
variable, splitting it into individual values for duration, width, and height.The values are assigned to their respective variables (
duration
,width
,height
).Finally, the script echoes the extracted values.
You can modify the script to extract other information as needed by adjusting the show_entries
parameter in the ffprobe
command and updating the parsing logic accordingly.