Linux: Cutting then Slowing Down Video Clips.
linux mint terminal
Sometimes when I'm editing videos, it's more practical to cut up raw videos into smaller clips before importing them into my favorite video editor, ie kdenlive for linux. Using the terminal command is quick
ffmpeg -ss <start-time> -i <input filename> -to <duration-time> -vf yadif <output filename>
I make up lots of cut clips in this manner, adding an extra 10secs to allow post editing cuts, ie cutting final length based on the musics beat.
Even though you can also change the speed of a video clip on kdenlive, I prefer to do it in the terminal using a BASH script clipvid.sh
The script asks for 3 user inputs
- filename of the clip
- time where you want to start the cut eg 00:05
- duration of how many seconds to clip should go for eg 00:25
example used
Script: clipvid.sh
`
#!/bin/bash
#Creating A SloMo(x3) Video Clip (remove sound track)-
#by kiwibloke 12 February 2020
#Define Variables
infile=""
outfile=""
outfile1="_cut.mp4"
outfile2="_slowdown.mp4"
outfile3="_slow(x3).mp4"
cstart=""
cduration=""
cspeed=""
csound=""
echo "CLIPVID Version 0001 by Philip Taramai 12 February 2020 (kiwibloke)"
echo "-------------------------------------------------------------------<"
echo "Input Filename: default C0001.MP4"
read infile
if [ -z "$infile" ]
then
infile="C0001.MP4"
fi
#remove filename extension then convert to lowercase
outfile=$(basename "$infile")
outfile="${outfile%.*}"
outfile=${outfile,,}
echo " "
echo "-------------------------------------------------------------------<"
echo "Input Start Position: default 00:00 seconds"
read cstart
if [ -z "$cstart" ]
then
cstart="00:00"
fi
echo " "
echo "-------------------------------------------------------------------<"
echo "Input Cut Duration: default 00:12 seconds"
read cduration
if [ -z "$cduration" ]
then
cduration="00:12"
fi
ffmpeg -ss "$cstart" -i $infile -to $cduration -vf yadif $outfile$outfile1
ffmpeg -i $outfile$outfile1 -filter:v "setpts=3.0*PTS" $outfile$outfile2
ffmpeg -i $outfile$outfile2 -vcodec copy -an $outfile$outfile3
#delete temporary files
rm $outfile$outfile1
rm $outfile$outfile2
`
Important to note, this script is set to adjust the speed of a video clip to run 3x slower. Also feel free to change this script, my programming skills are pretty basic I'm sure you can make this far more efficient. There is some handy snippets in this code you should use in your own scripts.
To use, just copy and paste the above script into a text file, rename it clipvid.sh (or any name you prefer) and store in the /Bin folder. With the file manager, change the properties permissions to run as a program
Just an example of a creating a cut slowed down clip then a creating a final video by adding other clips.
CRYPTO | Wallet Support |
---|---|
ETHEREUM | 0x23Bd7B699383D96513636bf145dCc272a1502076 |
STEEM | 0x4493de75192e5210091c71506465E31BF5038338 |
BAT | 0x6fE7EC6B8bB98210468a15B3235abC80edB70b3d |
click on image to take you to my Steemit page
- with every post comes experience, as we all strive to do better.
- curate/up vote, let's encourage and inspire each other.
Congratulations @kiwibloke! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :
You can view your badges on your Steem Board and compare to others on the Steem Ranking
If you no longer want to receive notifications, reply to this comment with the word
STOP
That's awesome, I learn best by trying to understand other peoples script. I have now installed shellcheck into my Linux Mint and it really does help. It also good to go check out shellcheck.net.
I really like how you set up the default values variables in your above example, simplifies things. Time to play around with some SHELL scriting over the next few nights.