Skip to content

Commit

Permalink
update v2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillermo-Hidalgo-Gadea committed Jul 2, 2022
1 parent 51f2c22 commit 4821140
Show file tree
Hide file tree
Showing 14 changed files with 222 additions and 323 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
*.exe
*.DS_store
*.spec
*.rc
*.ico
.gitignore
.gitattributes
build
dist
__pycache__
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Guillermo-Hidalgo-Gadea
Copyright (c) 2022 Guillermo-Hidalgo-Gadea

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# VideoPyToolbox [<img src="https://github.com/Guillermo-Hidalgo-Gadea/personal-academic-website/blob/master/assets/images/icon.png" alt="logo" align="right" width="100"/>](https://guillermohidalgogadea.com/)

Play, compress, trim and concatenate videos in python using FFmpeg

Play, compress, trim and concatenate videos using ffmpeg

## What it is
This Toolbox is a python wrapper for a bunch of useful ffmpeg commands to play, compress and edit videos using ffmpeg.
Expand All @@ -11,15 +10,12 @@ When it comes to video compression, FFmpeg can be challenging to use over comman
<img src="screen.PNG" alt="logo" width="900"/>

## How to use it
The Toolbox is built as an interactive terminal prompt to guide you step by step through the process of concatenating, compressing, spliting and playing videos. You can either use the `VideoPyToolbox.py` script in your IDE, or run it from the terminal. You can find a compiled version of VideoPyToolbox [here](https://gitlab.ruhr-uni-bochum.de/ikn/syncflir/-/blob/master/PostProcessing/VideoPyToolbox.exe).
The Toolbox is built as an interactive terminal prompt to guide you step by step through the process of concatenating, compressing, spliting and playing videos. You can either use the `VideoPyToolbox.py` script in your IDE, or run it from the terminal. You can find a compiled version of VideoPyToolbox [here](https://gitlab.ruhr-uni-bochum.de/ikn/syncflir/-/blob/master/PostProcessing/VideoPyToolbox.exe). Compiled in Windows with pyinstaller v5.1 using `pyinstaller --add-binary ffmpeg.exe;. --add-binary ffplay.exe;. --onefile --icon=logo.ico VideoPyToolbox.py`.

## Features
The video player allows to stream up to 9 files at the same time, for example to check for synchronizity. Video compression is set to `hevc/h.265`, but could be expanded in future releases. GPU mode uses hardware acceleration for encoding with `hevc_nvenc`. The trim/split function to extract video snippets between timestamps needs to re-encode the video with `h.265 cfr 0` or `hevc_nvenc cq 0` respectively, to achieve "frame-accurate" splits. Lossless splits are not accurate enough if the chosen timestamp does not happen to contain a keyframe, which can result in timeshifts of up to several seconds (depending on framerate).

## Next release
* enhanced batch processing for split from multiple directories
* choice between losless and re-encoded trim/split
* choose from wider variety of compression codecs
* play audio from video with waveform and timestamp
* create mosaic video
* scrap all files in directory and subdirectory
* tbd
87 changes: 53 additions & 34 deletions VideoPyToolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
to play a video recording, compress it using h265 codec, or to concatenate and trim clips from
timestamps. Use the custom pipeline to compress and concat at once.
'conda install ffmpeg' if not already installed
MIT License Copyright (c) 2021 GuillermoHidalgoGadea.com
MIT License Copyright (c) 2022 GuillermoHidalgoGadea.com
Sourcecode: https://github.com/Guillermo-Hidalgo-Gadea/VideoPyToolbox
====================================================================================================
Expand All @@ -22,11 +20,11 @@

# import functions
from toolbox.function_ffplay import ffplay
from toolbox.function_compress import compress_h265, compress_hevc_nvenc
from toolbox.function_compress import compress_h265, compress_h264, compress_hevc_nvenc
from toolbox.function_concatenate import concat_videos
from toolbox.function_custom import the_usual_h265, the_usual_hevc_nvenc
from toolbox.function_rename import batch_rename
from toolbox.function_custom import the_usual_h265
from toolbox.function_split import trim_split_h265, trim_split_hevc_nvenc
from toolbox.function_mosaic import mosaic_video
from toolbox.logo import ascii_logo, width, height

# Helper functions
Expand Down Expand Up @@ -58,6 +56,7 @@ def check_gpu():
# Terminal print colors
RESET = "\033[0;0m"
MATRIX = "\033[0;32m"
YELLOW = "\033[0;33m"
CYAN = "\033[0;36m"
RED = "\033[0;31m"

Expand All @@ -73,11 +72,11 @@ def check_gpu():

# header
print("#"*width + "\n")
print("MIT License Copyright (c) 2021 GuillermoHidalgoGadea.com\n".center(width))
print("MIT License Copyright (c) 2022 GuillermoHidalgoGadea.com\n".center(width))
print("#"*width)

#logo in ascii here
sys.stdout.write(MATRIX)
sys.stdout.write(YELLOW)
print(ascii_logo.center(width))
sys.stdout.write(RESET)
instructions = "VideoPy is a FFMPEG wrapper to play videos, to compress and change codecs, as well as to append and split raw videos."
Expand All @@ -86,11 +85,11 @@ def check_gpu():
# function help format
help = '''
'p' Play audio or video file
'c' Compress video to h.265/h.264
'c' Compress video with h265/h264
'a' Append or Concatenate multiple files
's' Split or Trim files by timestamp
'r' Rename files in batches
'u' Custom pipeline to compress and concatenate
'm' Create multi-view mosaic video
'gpu' Check for hardware acceleration
'q' Quit
'''
Expand All @@ -104,7 +103,7 @@ def check_gpu():

# header
print("#"*width + "\n")
print("MIT License Copyright (c) 2021 GuillermoHidalgoGadea.com\n".center(width))
print("MIT License Copyright (c) 2022 GuillermoHidalgoGadea.com\n".center(width))
print("#"*width)

#logo in ascii here
Expand All @@ -117,11 +116,11 @@ def check_gpu():
# function help format
help = '''
'p' Play audio or video file
'c' Compress video to h.265/h.264
'c' Compress video with h265/h264
'a' Append or Concatenate multiple files
's' Split or Trim files by timestamp
'r' Rename files in batches
'u' Custom pipeline to compress and concatenate
'm' Create multi-view mosaic video
'gpu' Check for hardware acceleration
'q' Quit
'''
Expand Down Expand Up @@ -150,10 +149,17 @@ def check_gpu():
# start compression
print("\nStart compression with ffmpeg... \n")
if "y" not in gpu_use:
compress_h265()
input("\nCompressing ended!\n")
# reset while loop
choice = 'main'
encoder = input("\n(CPU mode) Choose video encoder [h264/h265]: ")
if "4" in encoder:
compress_h264()
input("\nCompressing ended!\n")
# reset while loop
choice = 'main'
elif "5" in encoder:
compress_h265()
input("\nCompressing ended!\n")
# reset while loop
choice = 'main'
else:
compress_hevc_nvenc()
input("\nCompressing ended!\n")
Expand All @@ -173,15 +179,25 @@ def check_gpu():
elif choice.startswith("s"):
print("\nStart trimming videos in ffmpeg... \n")
if "y" not in gpu_use:
trim_split_h265()
input("\nTrimming ended!\n")
# reset while loop
choice = 'main'
try:
trim_split_h265()
input("\nTrimming ended!\n")
# reset while loop
choice = 'main'
except:
input("\nTrimming ended!\n")
# reset while loop
choice = 'main'
else:
trim_split_hevc_nvenc()
input("\nTrimming ended!\n")
# reset while loop
choice = 'acc_main'
try:
trim_split_hevc_nvenc()
input("\nTrimming ended!\n")
# reset while loop
choice = 'acc_main'
except:
input("\nTrimming ended!\n")
# reset while loop
choice = 'acc_main'

elif choice.startswith("u"):
print("\nAh, the usual. Comming right up... \n")
Expand All @@ -191,20 +207,23 @@ def check_gpu():
# reset while loop
choice = 'main'
else:
the_usual_hevc_nvenc()
the_usual_h265()
input("\nPipeline ended!\n")
# reset while loop
choice = 'acc_main'

elif choice.startswith("r"):
print("\nStart renaming files... \n")
batch_rename()
input("\nRenaming ended!\n")
# reset while loop
if "y" in gpu_use:
choice = 'acc_main'
else:
elif choice.startswith("m"):
print("\nStart creating mosaic video... \n")
if "y" not in gpu_use:
mosaic_video()
input("\nMosaic video created!\n")
# reset while loop
choice = 'main'
else:
mosaic_video()
input("\nMosaic video created!\n")
# reset while loop
choice = 'acc_main'

elif choice.startswith("q"):
break
Expand Down
75 changes: 38 additions & 37 deletions VideoPyToolbox.spec
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,42 @@
block_cipher = None


a = Analysis(['VideoPyToolbox.py'],
pathex=[],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
a = Analysis(
['VideoPyToolbox.py'],
pathex=[],
binaries=[('ffmpeg.exe', '.'), ('ffplay.exe', '.')],
datas=[],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)

exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='VideoPyToolbox',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=False,
disable_windowed_traceback=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None , icon='logo.ico')
app = BUNDLE(exe,
name='VideoPyToolbox.app',
icon='logo.ico',
bundle_identifier=None)
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='VideoPyToolbox',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
icon='logo.ico', version='version.rc',
)
Binary file modified logo.ico
Binary file not shown.
Binary file modified screen.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 4821140

Please sign in to comment.