Created
July 28, 2023 07:46
-
-
Save ammar-faifi/c1fd8a1ababedb6c0673b57389eef6e4 to your computer and use it in GitHub Desktop.
Using `ffmpeg` to reduce quality video and convert it to `mp4`
This file contains hidden or 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 subprocess | |
def reduce_video_quality( | |
input_file, | |
output_file, | |
target_resolution=(640, 360), | |
target_fps=30, | |
target_bitrate="1500k", | |
): | |
try: | |
command = [ | |
"ffmpeg", | |
"-i", | |
input_file, | |
"-s", | |
f"{target_resolution[0]}x{target_resolution[1]}", | |
"-r", | |
str(target_fps), | |
"-b:v", | |
target_bitrate, | |
"-c:a", | |
"copy", # Keep the audio unchanged | |
output_file, | |
] | |
subprocess.run(command, check=True) | |
print("Video quality reduced successfully.") | |
except subprocess.CalledProcessError as e: | |
print(f"Error occurred: {e}") | |
# Example usage | |
input_video = input("input path>") or "video.mov" | |
output_video = "output_video_reduced.mp4" | |
reduce_video_quality(input_video, output_video, (1280, 720)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment