Free DIY Mass Video Trimming Program in 2021

Has it ever happened to you that you have multiple videos and want to trim a certain portion of their ending (maybe an outro) but are too lazy to trim them all individually? Today, for you lazy folks, I have a solution which trims specified seconds of ending from all the videos present in a folder without any reduction is quality.

This simple software program lets you do mass editing without having to click through each one hence Batch trimming a folder full of video files within a matter of minutes without compromising frame rate or video quality.

For Mass Video Trimming we will be using FFmpeg and write a shell script to automate it.

Logic for mass video trimming

  • FFmpeg takes file name without and white-space, so first we will replace them with an underscore.
  • Calculate total length of the video.
  • Subtract the seconds we need to trim from the total duration.
  • Cut the video at the time obtained from above step.
  • Make an output folder and save the processed videos there.
  • Remove underscore from the name of the videos.
  • And to do these steps for all the videos inside the folder we will be using a for loop.

Note

Here we have used .mp4 files, you can replace them with any other format in the code.



How to trim the ending of all the videos in a folder

Make an output folder

Use mkdir <folder name> to create an output folder for all the processed videos to be stored in.

Take user input for seconds he/she wants to trim

You can also directly give this value, but it’s good to have a little flexibility.

Replace all the whitespace characters with underscore

As explained above FFmpeg has issues with whitespace, so we have to do this or one can also put the filename inside inverted commas for the same result.

Start a loop

This will convert all the video files (.mp4), you can use any other format too.

Calculate length of each video and subtract seconds obtained from user input from it

We will use ffprobe to find duration and bc command to accommodate floating point operation.

Trim each video and store it in output folder

We will use FFmpeg for this.

Remove underscores from the name

After the processing of videos we will remove all the underscores from the file names.

Extra (adding progress bar and notification)

For some aesthetics we can add progress bar and notification using Zenity or KDialog or any other tool you want.

Run the Shell script

how to run shell script

Run the Shell script (first make it executable) inside the desired folder.
If you don’t know how to run a Shell script read How to run a Shell script.



Full Script

! /bin/bash
mkdir outputs
ipt=$(zenity --entry --text "How many seconds do you want to clip from the end")
for k in *; do mv "$k" echo $k | tr ' ' '_'; done
for f in *.mp4
do
  x=$(ffprobe -i "$f" -show_entries format=duration -v quiet -of csv="p=0")
  trim=$(bc <<< "$x - $ipt")
  ffmpeg -t $trim -i "$f" outputs/${f%.mp4}.mp4|y
done | zenity --progress --pulsate --title "Processing " \
             --text "Clipping please wait, this may take some time" \
             --pulsate --no-cancel --auto-close \
             --width 500 
for f in * ; do mv "$f" "${f//_/ }" ; done
cd \outputs 
for f in * ; do mv "$f" "${f//_/ }" ; done
zenity --notification --text "Videos have been clipped"

Conclusion

The article shows how to trim videos in a folder at once by using a simple program in a time and resource efficient manner. You can always modify the script according to your requirement, if you need to trim bulk videos from beginning or end. Leave a comment if you have any problem down below.

Thank you for reading.