Using FFMPEG to Slice a Video

There’s plenty of software out there that will allow you to record a slice of a video. I like command line tools for this sort or thing because I find they often are a little more flexible and precise.

I also hope to use some of these command line tools in a future automation. That will hopefully come in the near future.

Assuming you have FFMPEG installed, you can create the following batch script:

@echo off
setlocal

REM Check if FFmpeg is installed
where ffmpeg >nul 2>&1
if %errorlevel% neq 0 (
    echo FFmpeg is not installed or not in PATH.
    echo Please install FFmpeg and try again.
    exit /b
)

REM Check if enough parameters are provided
if "%~4"=="" (
    echo Usage: %0 input_video start_time clip_length output_video
    exit /b
)

REM Set input parameters
set input_video=%1
set start_time=%2
set clip_length=%3
set output_vid=%4

ffmpeg -ss %start_time% -i "%input_video%" -c copy -t %clip_length% "%output_vid%"

echo Video clip creation completed: %output_vid%

This is just a very simple script that will slice out a video from the given start time, and length you wish it to be. Example:

.\clip_video.bat ".\input.mp4" 00:02:51.000 7 ".\output.mp4"

The 3rd input there is the length of the video in case you were wondering. I’ll probably find some dynamic way of creating the output file so I didn’t bother trying to extract the extension to reuse. Also ffmpeg could probably save it as a different type, but I don’t care about that at the moment.

Leave me a comment with any suggestions on how to improve this!


Posted

in

by

Tags:

Comments

One response to “Using FFMPEG to Slice a Video”

  1. Tony Hines Avatar
    Tony Hines

    One useful addition for the batch script: check FFmpeg’s exit code before printing “Video clip creation completed”. A small `if errorlevel 1` block immediately after the FFmpeg line can print a failure message and `exit /b 1`; the success message then runs only when FFmpeg succeeds. That would also make a future automation able to tell a failed cut from a completed one. This is a suggestion from reading the script, not a tested result. Tony Hines, Project Manager at UseFreeTools; posted with AI assistance.

Leave a Reply

Your email address will not be published. Required fields are marked *