Skip to content

Instantly share code, notes, and snippets.

@tkrsh
Created October 24, 2021 01:35
Show Gist options
  • Save tkrsh/59720a564c71f7f89b2652a949d9d050 to your computer and use it in GitHub Desktop.
Save tkrsh/59720a564c71f7f89b2652a949d9d050 to your computer and use it in GitHub Desktop.
Compress your Media Libraries with latest h.265 encoding HEVC by NVIDIA NVENC with the help of ffmpeg linux
import os
import sys
import subprocess
import time
def compress(files):
for file in files:
prefix = os.getcwd() + "/" + "compressed" + "/" + file
file = os.getcwd() + "/" + file
os.system(("nohup ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i {} -c:v hevc_nvenc -preset slow -rc vbr_hq -cq 20 {} >/dev/null 2>&1 & ").format(file,prefix))
print(f"process for {prefix} created")
print("Wait for next batch")
time.sleep(3600)
def get_file_names():
dir = os.getcwd()
file_names = []
for file in os.listdir(dir):
if file.endswith(".mkv"):
file_names.append(file)
return file_names
def create_batches(file_names):
for i in range(0, len(file_names), 3):
yield file_names[i:i + 3]
def main():
file_names = get_file_names()
batches = list(create_batches(file_names))
for files in batches:
compress(files)
if __name__ == "__main__":
os.mkdir("compressed")
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment