Created
May 26, 2023 10:34
-
-
Save ClimenteA/734c6da8bcf8baf6badcfcdf0439778e to your computer and use it in GitHub Desktop.
Use ffmpeg and python to increase volume of some videos and after that concat
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 | |
from datetime import datetime | |
# Assuming video files are recorted with OBS in this format: "2023-04-11 08-11-11.mp4" | |
def parse_date(filepath): | |
date_str = filepath[:19] | |
return datetime.strptime(date_str, "%Y-%m-%d %H-%M-%S") | |
filepaths = [f for f in os.listdir() if f.endswith(".mp4")] | |
for fname in filepaths: | |
cmd = f'ffmpeg -i "{fname}" -af "volume=20dB" -c:v copy "louder/{fname}"' | |
os.system(cmd) | |
# test and copy files from louder to current vids folder | |
# then run the concat cell | |
response = input("test and copy files from louder to current vids folder, Ready? y/n") | |
if response in ["y", "Y"]: | |
sorted_filepaths = sorted(filepaths, key=parse_date) | |
sorted_filepaths = [f.replace(" ", "\ ") for f in sorted_filepaths] | |
allvids = [f'file {os.path.abspath(f)}' for f in sorted_filepaths] | |
with open("vids.txt", "w") as f: | |
f.write("\n".join(allvids)) | |
# cat vids.txt | |
os.system("ffmpeg -f concat -safe 0 -i vids.txt -c copy allvids.mp4") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment