Skip to content

Instantly share code, notes, and snippets.

@alexeygrigorev
Last active February 14, 2021 11:49
Show Gist options
  • Save alexeygrigorev/b7123364689f4019662bba26537911dc to your computer and use it in GitHub Desktop.
Save alexeygrigorev/b7123364689f4019662bba26537911dc to your computer and use it in GitHub Desktop.
Cutting videos with FFMpeg

Cutting videos with FFMpeg without re-encoding

Here's how you use it:

./cut.sh conf2.mp4 out1.mp4 00:00:05 00:53:47
#!/usr/bin/env bash
IN_FILE=$1
OUT_FILE=$2
START=$3
END=$4
DURATION=$(python delta.py $START $END)
echo $DURATION
ffmpeg -ss $START -i ${IN_FILE} -to $DURATION -c copy ${OUT_FILE}
import sys
from datetime import datetime
from dateutil.relativedelta import relativedelta
s1 = sys.argv[1]
s2 = sys.argv[2]
FMT = '%H:%M:%S'
t1 = datetime.strptime(s2, FMT)
t2 = datetime.strptime(s1, FMT)
d = relativedelta(t1, t2)
res = '%02d:%02d:%02d' % (d.hours, d.minutes, d.seconds)
print(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment