I recommend opening the video in a media player to find the time where you want to split it. Then you can use ffmpeg with the following script. It does not re-encode the video.
#!/bin/bash
# Split Video Script
# Usage: script_name file_name split-point
# Example: split_video_script bugs_bunny.mp4 31:23
# Instructions:
# 1. Type the name of your script (if it is already added to ~/bin and marked as executable).
# 2. Type the file name including path to it if necessary.
# 3. Type the time where you want to split the video. It goes in minutes:seconds
# Get length in seconds
length=$(echo "$2" | awk -F: '{print ($1 * 60) + $2}')
# Get filename without extension
fname="${1%.*}"
# First half
ffmpeg -i "${fname}.mp4" -c copy -t "$length" "${fname}1.mp4"
# Second half
ffmpeg -i "${fname}.mp4" -c copy -ss "$length" "${fname}2.mp4"
Update: I recently needed to update this script because of an issue with the second half. So, now I have to process the second half of it. You would add in the parameters that are specific to your original video. You can use mediainfo
, ffprobe
or ffmpeg -i
to find the needed information about your original video.
#!/bin/bash
if [ -z "$1" ]; then
echo "Usage: $0 file-name"
exit 1
fi
read -p "Enter time to split video (hh:mm:ss.mmm) " split_time
ext="${1##*.}"
fname="${1%.*}"
# First half
ffmpeg -i "$1" -c copy -t "$split_time" -c:s copy "${fname}1.${ext}"
# Second half
ffmpeg -ss "$split_time" -i "$1" -c:v libx264 -crf 17 -preset veryfast -r 30 -s 1920x1080 -c:a aac -ac 2 -b:a 256k -ar 44100 -pix_fmt yuv420p -movflags faststart -c:s copy "${fname}2.${ext}"