Skip to content

Commit

Permalink
Only splitting when final filesize exceeds limit, fixing output and r…
Browse files Browse the repository at this point in the history
…eading of input sizes, adding pip req file, bumping version
  • Loading branch information
sverrirs committed Feb 18, 2018
1 parent 0702d8d commit 61b2857
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
20 changes: 13 additions & 7 deletions src/combine.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python
# coding=utf-8
__version__ = "2.1.0"
__version__ = "2.2.0"
# When modifying remember to issue a new tag command in git before committing, then push the new tag
# git tag -a v2.1.0 -m "v2.1.0"
# git tag -a v2.2.0 -m "v2.2.0"
# git push origin --tags
"""
Python script that generates the necessary mp4box -cat commands to concatinate multiple video files
Expand All @@ -21,6 +21,8 @@
pip install colorama
pip install termcolor
pip install -r requirements.txt
See: https://github.com/sverrirs/mp4combine
Author: Sverrir Sigmundarson [email protected] https://www.sverrirs.com
"""
Expand Down Expand Up @@ -139,7 +141,7 @@ def createCombinedVideoFile(video_files, chapters, cumulative_dur, cumulative_si
saveChaptersFile(chapters, path_chapters_file)

# Re-encode and combine the video files first
print(Colors.toolpath("Combining and re-encoding video files (ffmpeg)"))
print(Colors.toolpath("Combining and re-encoding video files (ffmpeg), this will take a while..."))
reencodeAndCombineVideoFiles(ffmpegexec, video_files, path_out_file, args_videomaxsize)

# Now create the combined file and include the chapter marks
Expand All @@ -149,9 +151,13 @@ def createCombinedVideoFile(video_files, chapters, cumulative_dur, cumulative_si
# Delete the chapters file
os.remove(str(path_chapters_file))

# Read the created file to learn its final filesize
size_out_file_kb = os.path.getsize(str(path_out_file)) / 1024
print( Colors.toolpath("Final size of video file is: {0}".format(humanize.naturalsize(size_out_file_kb * 1024))))

# Now split the file if requested
if max_out_size_kb > 0:
print( Colors.toolpath("Splitting video file into requested max size of: {0}".format(humanize.naturalsize(max_out_size_kb * 1024))))
if max_out_size_kb > 0 and size_out_file_kb > max_out_size_kb :
print( Colors.toolpath("Size limit exceeded, splitting video into files of max size: {0}".format(humanize.naturalsize(max_out_size_kb * 1000))))
splitVideoFile(mp4exec, path_out_file, max_out_size_kb)

#
Expand Down Expand Up @@ -179,7 +185,7 @@ def determineMaximumOutputfileSizeInKb(absolute_size, disk_capacity):
unit_multiplier = ABSSIZES[unit]
total_size = size * unit_multiplier
#print( "Absolute total: {0}, mult: {1} ".format(total_size, unit_multiplier))
return total_size / 1024 # Return kilobytes
return total_size / 1000 # Return kilobytes but in the metric system sense not the "1024 byte sense"
else:
# If nothing is specified then the default return is to use unbounded
return -1
Expand Down Expand Up @@ -428,7 +434,7 @@ def _runSubProcess(prog_args, path_to_wait_on=None):
my_env['PYTHONIOENCODING'] = 'utf-8'

retcode = None

# Run the app and collect the output
ret = subprocess.Popen(prog_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, env=my_env)
try:
Expand Down
8 changes: 4 additions & 4 deletions src/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@

ABSSIZES={}
ABSSIZES['B'] = 1
ABSSIZES['KB'] = ABSSIZES['B'] * 1024
ABSSIZES['MB'] = ABSSIZES['KB'] * 1024
ABSSIZES['GB'] = ABSSIZES['MB'] * 1024
ABSSIZES['TB'] = ABSSIZES['GB'] * 1024
ABSSIZES['KB'] = ABSSIZES['B'] * 1000
ABSSIZES['MB'] = ABSSIZES['KB'] * 1000
ABSSIZES['GB'] = ABSSIZES['MB'] * 1000
ABSSIZES['TB'] = ABSSIZES['GB'] * 1000

class Colors(object):
# Lambdas as shorthands for printing various types of data
Expand Down
3 changes: 3 additions & 0 deletions src/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
humanize
colorama
termcolor

0 comments on commit 61b2857

Please sign in to comment.