×

Pages

Labels

Search

×

Pages

×
×

Notice

The site is currently undergoing scheduled maintenance, and may not function correctly. Please come back later.

Advertisement

advertisement

Edit Video i1 v1

#!/bin/bash
#Name:Edit Video i1 v1
#Description:Using the source video recordings created the completed edited version
#Usage:Enter a directory where temporary files can be written, and the finished video can be saved. Edit the 'SOURCE' and 'TYPE' variables to have correct details. Add in commands for extracting video segments. Run the script.
#Notes:Tested on Debian 10. There is technically double conversion, but the first conversion should be visually lossless so it doesn't really matter. This script was made for my own use so it's not very user friendly, and doesn't do error checking. I'm sharing it as an example. You'll almost certainly want to edit it before using it.
#License:Ritchey Permissive License v10
#Task:
##Installing dependencies
sudo apt-get install -y ffmpeg coreutils findutils bash
##Convert source videos to a single video file in a highly seekable form to ensure accurate editing cuts
echo "Converting sources files to single video"
SOURCE='/home/user1/Videos/Source/'
TYPE='MOV'
FILES=$(find "$SOURCE" -type f -iname "*.$TYPE" -exec echo -n "{}," \;)
IFS=','
if [ -e source_videos.txt ]; then
    rm source_videos.txt
fi
for f in $FILES; do
    echo "FOUND: '${f}'"
    echo "file '${f}'" >> source_videos.txt
done
cat source_videos.txt | sort -n > source_videos_sorted.txt
mv source_videos_sorted.txt source_videos.txt
if [ ! -f single_video_file.mkv ]; then
    ffmpeg -f concat -safe 0 -i source_videos.txt -vcodec libx264 -x264-params keyint=30:min-keyint:30:scenecut=0 -preset ultrafast -crf 17 -tune film -profile:v high -filter:v fps=fps=30 -c:a flac -ar 48000 single_video_file.mkv
fi
rm source_videos.txt
echo ""
##Create clips by extracting portions of the video [Example: ffmpeg -y -i single_video_file.mkv -ss 00:20:14 -to 00:20:44 -codec copy clip_#.mkv]
echo "Extracting clips from video"
ffmpeg -y -i single_video_file.mkv -ss 00:00:10 -to 00:00:49 -codec copy clip_1.mkv
ffmpeg -y -i single_video_file.mkv -ss 00:20:00 -to 00:20:15 -codec copy clip_2.mkv
ffmpeg -y -i single_video_file.mkv -ss 00:33:14 -to 00:33:57 -codec copy clip_3.mkv

echo ""
##Generate completed video by combining finished clips
echo "Generating completed video"
FILES=$(find "$PWD" -type f -iname "clip*.mkv" -exec echo -n "{}," \;)
IFS=','
if [ -e clip_videos.txt ]; then
    rm clip_videos.txt
fi
for f in $FILES; do
    echo "FOUND: '${f}'"
    echo "file '${f}'" >> clip_videos.txt
done
cat clip_videos.txt | sort -n > clip_videos_sorted.txt
mv clip_videos_sorted.txt clip_videos.txt
if [ -e finished_edited_video.mp4 ]; then
    rm finished_edited_video.mp4
fi
ffmpeg -f concat -safe 0 -i clip_videos.txt -vcodec libx264 -preset ultrafast -tune film -profile:v high -b:v 880k -filter:v fps=fps=30 -vsync 2 -c:a aac -b:a 256k -ar 48000 -ac 2 finished_edited_video.mp4
rm clip_videos.txt
FILES=$(find "$PWD" -type f -iname "clip*.mkv" -exec echo -n "{}," \;)
IFS=','
for f in $FILES; do
    rm "${f}"
done
echo ""
##Prompt user about keeping single_video_file.mkv. Since the script skips creating this file if it already exists, keeping it, can help speed up the next run of the script.
echo -n "Would you like to keep 'single_video_file.mkv' (y/n)?:"
read answer
if [ "$answer" != "y" ] ;then
    rm single_video_file.mkv
else
    echo "Keeping: '${PWD}/single_video_file.mkv'"
fi

Advertisment

advertisement
Copyright © James Daniel Marrs Ritchey.

Siteviews