Skip to content

Instantly share code, notes, and snippets.

@ClimenteA
Created May 26, 2023 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ClimenteA/734c6da8bcf8baf6badcfcdf0439778e to your computer and use it in GitHub Desktop.
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
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