Skip to content

Instantly share code, notes, and snippets.

@LucaTNT
Created August 1, 2014 11:04
Show Gist options
  • Save LucaTNT/7e00824ad8e860d378c6 to your computer and use it in GitHub Desktop.
Save LucaTNT/7e00824ad8e860d378c6 to your computer and use it in GitHub Desktop.
Convert IP camera recordings to lower quality for archiving
#!/bin/bash
# convertVideo.sh
# ---------------
# This script converts the original, high quality recording to a much smaller
# and lower quality file for archiving purposes.
# ---------------
# Author: @LucaTNT
# License: BSD
# Define some paths
BASEpath='/path/to/surveillance/folder'
ARCHIVEpath=$BASEpath'/archive'
RECpath=$BASEpath'/video'
# Video conversion parameters
# Experiment freely with them
framerate='5'
bitrate='100k'
# Check that the file actually exists
if [[ ! -f $1 ]]
then
echo 'File not found'
exit 0;
fi
# Get the file's name
FILEname="`basename $1`"
FILEpath=$(cd $(dirname $1); pwd);
# The camera's name is the last 5 characters of the path, as each folder is called camXX where XX is the cam number
CAM=${FILEpath: -5}
# These variables will be used to create the destination path, feel free to edit them as needed
YEAR_MONTH=${FILEname:0:7}
DAY=${FILEname:8:2}
DESTINATIONpath=$ARCHIVEpath'/'$CAM'/'$YEAR_MONTH'/'$DAY;
# If the destination folder does not exist (i.e. new day/month), create it
if [[ ! -d $DESTINATIONpath ]]
then
echo 'Destination folder not found, creating it'
mkdir -p $DESTINATIONpath
fi
# Convert the video
ffmpeg -i $1 -r 5 -preset ultrafast -b:v 100k $DESTINATIONpath'/'$FILEname
# Delete the original file
rm $1
@non7top
Copy link

non7top commented Apr 24, 2016

framerate='5'
bitrate='100k'
these are not used later in the script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment