@echo off
setlocal enabledelayedexpansion

set "input_dir=%cd%"
set "output_dir=Console"

rem Clear previous cached files
forfiles /S /M "Console_*" /C "cmd /c del @file"

rem Make directory to avoid dynamically making copies
if not exist "%output_dir%" (
	mkdir "%output_dir%"
	)
	


rem Loop through all mp4 files in the current directory
for %%f in ("%input_dir%\*.mp4") do (
    set "input_file=%%f"
    set "output_file=%input_dir%\!output_dir!\!output_dir!_%%~nxf"

    rem Construct and run the ffmpeg command
    ffmpeg -i "!input_file!" -pix_fmt nv12 "!output_file!"

    rem Check if the conversion was successful
    if errorlevel 1 (
        echo Error converting "!input_file!"
    ) else (
        echo Successfully converted "!input_file!" to "!output_file!"
    )
)

rem move and clean up

for %%f in ("%input_dir%\!output_dir!\*.mp4") do (

	move /Y "%%f" "%input_dir%"

)

rmdir /S /Q "!output_dir!"

endlocal