Created
January 7, 2018 05:36
-
-
Save snt/38b18fff862f5932f9818429499d40bf to your computer and use it in GitHub Desktop.
split movies longer than 180 seconds for flickr upload.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env python3 | |
# run like this: `find ~/Desktop/exporting/*.{mp4,mov} | python3 ~/bin/splitmovies.py` | |
import fileinput | |
import subprocess | |
import math | |
SPLIT_SECONDS = 180 | |
def movie_length(filename: str) -> float: | |
p = subprocess.run(["ffprobe", "-v", "error", "-show_entries", "format=duration", "-of", "default=noprint_wrappers=1:nokey=1", filename], stdout=subprocess.PIPE) | |
print (p) | |
out = p.stdout | |
s = out.decode('utf-8').strip() | |
return float(s) | |
movies = [f.strip() for f in fileinput.input()] | |
print (movies) | |
large_movies = [m for m in movies if movie_length(m) > SPLIT_SECONDS ] | |
print (large_movies) | |
for f in large_movies: | |
print(f) | |
fsp = f.split('.') | |
ext = fsp[-1] | |
fnbody = '.'.join(fsp[:-1]) | |
subprocess.run(["ffmpeg","-i", f, "-c", "copy", "-map", "0", "-segment_time", "180", "-f", "segment", "-reset_timestamps", "1", "%s.%%03d.%s" % (fnbody, ext)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment