Created
February 6, 2024 00:56
-
-
Save lancepioch/28dad8d6a7e4ea92193750559efe0d8d to your computer and use it in GitHub Desktop.
This file contains 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
import os, subprocess, json | |
directory = "Z:\plex\movies" | |
if not directory: | |
directory = input("Enter directory: ") | |
for filename in os.listdir(directory): | |
path = os.path.join(directory, filename) | |
cmd = ['ffprobe', '-v', 'quiet', '-print_format', 'json', '-show_format', '-show_streams', path] | |
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) | |
data = proc.stdout.read() | |
data = json.loads(data) | |
if not 'streams' in data: | |
print("{} - Skipping non video file".format(filename)) | |
continue | |
streams = data['streams'] | |
for stream in streams: | |
if stream['codec_type'] != 'video': | |
print("{} #{} - Skipping non video stream: {}".format(filename, stream['index'], stream['codec_type'])) | |
continue | |
if stream['codec_name'] in ['hevc', 'h264', 'h265']: | |
print("{} #{} - Skipping video stream, already is: {}".format(filename, stream['index'], stream['codec_name'])) | |
continue | |
codec = 'h264' | |
print("{} #{} - Encoding video stream to {} from {}".format(filename, stream['index'], codec, stream['codec_name'])) | |
# encode to h264: ffmpeg -i abom.mkv -c:v h264 abom.mp4 | |
# remove extra video streams too https://stackoverflow.com/questions/19651272/multiple-video-streams-in-one-feed-ffmpeg | |
# print(streams) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment