Cutting MP4 Into smaller Files.

To make some awesome videos, I’m using my GoPro Hero8 with 2K7 (2704×1520) resolution. This is because I’m using a green screen and although the end videos are in FullHD, with this resolution I can easily crop, resize parts of the video without losing any quality. Cutting MP4 into smaller files would make life easier.

I’m using a video editing program and it’s possible to export your whole project incl media files to a zip file. Nice and easy. The biggest problem is that the media files are huge! About 4 Gig for 5 minutes. I don’t want to upload everything.

One solution is to cut the videos into 1 minute videos, so they are smaller and all the videos which are not being used, aren’t going to be in the zip file. This saves me a ton of GB uploading to the cloud.

Windows Free Lossless Cut Program

There is a nice application at Github that you can use to cut your videos into segments. There is even an option to have the video sliced into same segments. And this without re-encoding = fast. You can find it on : https://github.com/mifi/lossless-cut

If you download it NOT via the Windows Store, it’s free 🙂

Lossles Cutting Application
Lossless-cut

FFMPEG

The application is nice, but I have a lot of Videos and I was looking for a way to have them automatically cut the large videos into smaller pieces, without re-encoding.

To install FFMPEG just use the command:

sudo apt-get install ffmpeg

I am working on a windows machine and the command above can be executed via the Windows Linux Subsystem. In my case this is Ubuntu. (Install it via the windows store.)

With FFMPEG you can do a lot of things, so my starting point was:

ffmpeg -ss 00:00:00 -i GX010484.mp4 -t 00:01:00 -c copy out.mp4 

The problem with this command, is that it will cut only the first x seconds of the video and the rest of the file, well nothing happens with it.

The following command will cut your video into smaller pieces of 60 seconds.:

ffmpeg -i input.mp4 -c copy -f segment -segment_time 60 output_segment-%02d.mp4

Automation via Bash Script

When you try to segment a video that is smaller then the amount of your segment, you will get an error. So for the Bash Script it would be nice to know how long the video is in advance. You can get this info with the command FFPROBE. This is automatically installed with FFMPEG.

ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 input.mp4

This will give the result of the video in seconds.

My Bash Script is running in Ubuntu on my windows machine. When I created the Bash Script I have the error :

This is because it’s edited on a Windows based system. To make sure youre script will be running, convert the \r with :

awk '{ sub("\r$", ""); print }' convert.sh > convert2.sh

Now you can execute via : Bash convert2.sh.

Here is my script that automatically is capable of cutting mp4 videos into 60 sec pieces, when the video is longer as 90 seconds.

#!/bin/bash
segmentsec=60

for f in *.MP4; do
    # do some stuff here with "$f"
	echo "$f"
    # remember to quote it or spaces may misbehave
	fflength=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$f") 
    length=$(echo "$fflength" | cut -d "$(locale decimal_point)" -f 1)
	segment=90 
	echo "Lenght-> $length"
	if (( length > segment )); then
     echo "Over 90 sec"
     ffmpeg -i "$f" -c copy -f segment -segment_time "$segmentsec" "$f"_%02d.mp4
    fi
    echo
done

Here are other Tips and Tricks posts:

Leave a Comment