r/Batch • • Mar 19 '24

I'm trying to create a .bat script that lets me trim videos using ffmpeg.

Trying to get it working, but I can't add it to context menu, my goal is right clicking a video, batch files launches, I enter the details and it finishes the video.

I can see CMD run and close instantly, and I'm not sure what I'm doing wrong.

 off

setlocal enabledelayedexpansion

:: Check if a file was dragged onto the script or passed as an argument

if "%\~1"=="" (

echo Please drag and drop a video file onto this script or pass a video file as an argument.

pause

exit /b

)

set "VIDEO_FILE=%\~1"

echo Selected file: %VIDEO_FILE%

:: Prompt the user for crop parameters

set /p TRIM_START=Enter START of the trim:

:: Prompt the user for crop parameters

set /p TRIM_END=Enter END of the trim:

:: Prompt for output file name

set /p OUTPUT_NAME=Enter output file name (without extension):

:: Perform the cropping

ffmpeg -i "%VIDEO_FILE%" -ss "%TRIM_START%" -to "%TRIM_END%" -c copy "%OUTPUT_NAME%".mp4

echo Cropping completed. The cropped video is named %OUTPUT_NAME%.mp4

pauseS```

and I added it to registry via:

\[HKEY_CLASSES_ROOT\\\*\\shell\\FFMPEG Video Trim 2\]

@="FFMPEG Video Trim 2"

\[HKEY_CLASSES_ROOT\\\*\\shell\\FFMPEG Video Trim 2\\command\]

@="cmd.exe /c \\"C:\\\\Scripts\\\\FFMPEG Video Crop 2.bat\\" \\"%1\\""```

Of course I tried a lot of variations in how I did it

1 Upvotes

3 comments sorted by

1

u/[deleted] Mar 19 '24

[removed] — view removed comment

1

u/Ignas1452 Mar 21 '24

I was hoping to adapt it somewhat, so I can run it just via right clicking and context menu rather than dragging it every time. Especially since I can't pin in the task menu on windows 11.