mirror of
https://github.com/c0decracker/video-splitter.git
synced 2026-01-23 02:24:16 +00:00
fix: update for python3
This commit is contained in:
parent
14c9360d2b
commit
cfb62c5df8
1 changed files with 16 additions and 16 deletions
|
|
@ -23,7 +23,7 @@ def split_by_manifest(filename, manifest, vcodec="copy", acodec="copy",
|
|||
extra (str) - Extra options for ffmpeg.
|
||||
"""
|
||||
if not os.path.exists(manifest):
|
||||
print "File does not exist: %s" % manifest
|
||||
print("File does not exist: %s" % manifest)
|
||||
raise SystemExit
|
||||
|
||||
with open(manifest) as manifest_file:
|
||||
|
|
@ -33,7 +33,7 @@ def split_by_manifest(filename, manifest, vcodec="copy", acodec="copy",
|
|||
elif manifest_type == "csv":
|
||||
config = csv.DictReader(manifest_file)
|
||||
else:
|
||||
print "Format not supported. File must be a csv or json file"
|
||||
print("Format not supported. File must be a csv or json file")
|
||||
raise SystemExit
|
||||
|
||||
split_cmd = ["ffmpeg", "-i", filename, "-vcodec", vcodec,
|
||||
|
|
@ -56,27 +56,27 @@ def split_by_manifest(filename, manifest, vcodec="copy", acodec="copy",
|
|||
|
||||
split_args += ["-ss", str(split_start), "-t",
|
||||
str(split_length), filebase + "." + fileext]
|
||||
print "########################################################"
|
||||
print "About to run: "+" ".join(split_cmd+split_args)
|
||||
print "########################################################"
|
||||
print("########################################################")
|
||||
print("About to run: "+" ".join(split_cmd+split_args))
|
||||
print("########################################################")
|
||||
subprocess.check_output(split_cmd+split_args)
|
||||
except KeyError as e:
|
||||
print "############# Incorrect format ##############"
|
||||
print("############# Incorrect format ##############")
|
||||
if manifest_type == "json":
|
||||
print "The format of each json array should be:"
|
||||
print "{start_time: <int>, length: <int>, rename_to: <string>}"
|
||||
print("The format of each json array should be:")
|
||||
print("{start_time: <int>, length: <int>, rename_to: <string>}")
|
||||
elif manifest_type == "csv":
|
||||
print "start_time,length,rename_to should be the first line "
|
||||
print "in the csv file."
|
||||
print "#############################################"
|
||||
print e
|
||||
print("start_time,length,rename_to should be the first line ")
|
||||
print("in the csv file.")
|
||||
print("#############################################")
|
||||
print(e)
|
||||
raise SystemExit
|
||||
|
||||
def get_video_length(filename):
|
||||
|
||||
output = subprocess.check_output(("ffprobe", "-v", "error", "-show_entries", "format=duration", "-of", "default=noprint_wrappers=1:nokey=1", filename)).strip()
|
||||
video_length = int(float(output))
|
||||
print "Video length in seconds: "+str(video_length)
|
||||
print("Video length in seconds: "+str(video_length))
|
||||
|
||||
return video_length
|
||||
|
||||
|
|
@ -86,14 +86,14 @@ def ceildiv(a, b):
|
|||
def split_by_seconds(filename, split_length, vcodec="copy", acodec="copy",
|
||||
extra="", video_length=None, **kwargs):
|
||||
if split_length and split_length <= 0:
|
||||
print "Split length can't be 0"
|
||||
print("Split length can't be 0")
|
||||
raise SystemExit
|
||||
|
||||
if not video_length:
|
||||
video_length = get_video_length(filename)
|
||||
split_count = ceildiv(video_length, split_length)
|
||||
if(split_count == 1):
|
||||
print "Video length is less then the target split length."
|
||||
print("Video length is less then the target split length.")
|
||||
raise SystemExit
|
||||
|
||||
split_cmd = ["ffmpeg", "-i", filename, "-vcodec", vcodec, "-acodec", acodec] + shlex.split(extra)
|
||||
|
|
@ -112,7 +112,7 @@ def split_by_seconds(filename, split_length, vcodec="copy", acodec="copy",
|
|||
split_args += ["-ss", str(split_start), "-t", str(split_length),
|
||||
filebase + "-" + str(n+1) + "-of-" + \
|
||||
str(split_count) + "." + fileext]
|
||||
print "About to run: "+" ".join(split_cmd+split_args)
|
||||
print("About to run: "+" ".join(split_cmd+split_args))
|
||||
subprocess.check_output(split_cmd+split_args)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue