Skip to content

Instantly share code, notes, and snippets.

@jasonraimondi
Created October 15, 2015 02:25
Show Gist options
  • Save jasonraimondi/935e1ecd139695d3277b to your computer and use it in GitHub Desktop.
Save jasonraimondi/935e1ecd139695d3277b to your computer and use it in GitHub Desktop.
#!/usr/bin/python
#
# Extract video files from source video based on array of timestamps
#
# times - array of times we are extracting, from times[x] to times[x + 1]
# src - src file
# dest - destination file
#
import os
from timecode import Timecode
timestamp = {
0 : '00:00:00:00',
1 : '00:24:11:18',
2 : '00:48:23:13',
3 : '01:12:36:65',
4 : '01:36:48:03',
5 : '02:01:01:48',
6 : '02:25:14:13',
7 : '02:49:26:45',
8 : '03:13:38:34',
9 : '03:37:50:65',
10 : '03:54:17:01'
}
src = '~/folder/source.mkv'
dest = '~/folder/destination-s01e'
for x in timestamp:
if x == 10:
break
start = Timecode('29.97', timestamp[x])
end = Timecode('29.97', timestamp[x + 1])
length = end - start
start = "%s.%s" % (str(start)[1:8],str(start)[10:12])
end = "%s.%s" % (str(end)[1:8],str(end)[10:12])
length = "%s.%s" % (str(length)[1:8],str(length)[10:12])
print 'start %s | end %s | exists %s' % (str(start), str(end), str(length))
print 'ffmpeg -i ' + src + ' -acodec copy -vcodec copy -ss ' + start + ' -to ' + end + ' ' + dest + str(x) + '.mkv'
os.system('ffmpeg -i ' + src + ' -acodec copy -vcodec copy -ss ' + start + ' -to ' + end + ' ' + dest + str(x) + '.mkv')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment