Note: This script can be easily adapted or reduced to extract different metadata entries by modifying the findstr
lines to match the desired fields.
The metadata is saved in a text file named output.txt
.
-
FFmpeg: Ensure you have FFmpeg installed on your system.
- FFmpeg includes
ffprobe
, which is required for this script. - Add FFmpeg to your system's PATH to use it from the command line.
- Download FFmpeg
- FFmpeg includes
-
File Setup:
- Place your video files in the folder specified in the script.
- Update the
folder
variable in the script with the correct path to your video files. - Update the
file_ext
variable in the script with the correct extension for your video files.
@echo off
setlocal enabledelayedexpansion
set "file_ext=<EXT>"
set "folder=<SOURCEDIR>"
set "output_file=output.txt"
echo. > "%output_file%"
for %%A in ("%folder%\*.%file_ext%") do (
set "filename_written=false"
for /f "usebackq tokens=* delims=" %%B in (`ffprobe -v quiet -print_format json -show_format -show_streams "%%A"`) do (
set "line=%%B"
if !filename_written! == false (
echo Filename: %%~nxA >> "%output_file%"
set "filename_written=true"
)
rem Check for color_transfer
echo !line! | findstr /C:"\"color_transfer\":" > nul
if !errorlevel! == 0 (
echo !line! >> "%output_file%"
)
rem Check for color_primaries
echo !line! | findstr /C:"\"color_primaries\":" > nul
if !errorlevel! == 0 (
echo !line! >> "%output_file%"
)
rem Check for color_space
echo !line! | findstr /C:"\"color_space\":" > nul
if !errorlevel! == 0 (
echo !line! >> "%output_file%"
)
)
echo. >> "%output_file%"
)
pause
-
Batch Initialization:
setlocal enabledelayedexpansion
: Enables delayed variable expansion to process variables dynamically within loops.
-
Variables:
file_ext
: The extension of the video files to be processed (e.g.,mov
,mp4
,avi
).folder
: The path to the folder containing video files.output_file
: The name of the output text file where results are saved.
-
Main Logic:
- The outer
for
loop iterates over each video file matching the specified extension in the folder. - The inner
for /f
loop reads metadata output fromffprobe
for the current file.
- The outer
-
Metadata Filtering:
- The script checks for lines containing
color_transfer
,color_primaries
, andcolor_space
usingfindstr
. - If a match is found, it appends the filename and the matching line to the output file.
- The script checks for lines containing
-
Output:
- Metadata is written to
output.txt
, located in the same directory as the script. - Each video file's metadata is separated by a blank line for clarity.
- Metadata is written to
-
Pause:
- The script pauses at the end, allowing you to review any output in the command prompt.
-
Edit the Script:
-
Open the script in a text editor (e.g., Notepad).
-
Update the
folder
variable with the full path to the folder containing your video files.Example:
set "folder=C:\Users\<YOURUSERNAME>\Videos"
-
Update the
file_ext
variable with the extension of your video files.Example:
set "file_ext=mp4"
-
-
Save the Script:
- Save the file with a
.bat
extension, e.g.,extract_metadata.bat
.
- Save the file with a
-
Run the Script:
- Double-click the
.bat
file to execute it. - Alternatively, you can run it from the command prompt:
path\to\extract_metadata.bat
- Double-click the
-
Check the Output:
- After the script completes, open
output.txt
in a text editor to review the extracted metadata.
- After the script completes, open
-
Change the Output File: Modify the
output_file
variable to use a different file name or location.Example:
set "output_file=C:\Users\<YOURUSERNAME>\Desktop\metadata_output.txt"
-
Filter Additional Metadata: Add more
findstr
conditions for other metadata fields.Example:
rem Check for Codec echo !line! | findstr /C:"\"codec_tag_string\":" > nul if !errorlevel! == 0 ( echo !line! >> "%output_file%" )
-
FFmpeg Not Recognized: Ensure FFmpeg is installed and added to your system's PATH.
-
Empty Output File: Verify that:
- Files with the specified extension exist in the folder.
ffprobe
is functioning properly by testing it manually:ffprobe -v quiet -print_format json -show_format -show_streams path\to\video.ext
-
Script Errors: Check for syntax errors in the script and ensure the paths are correct.