Last active
December 22, 2021 21:32
-
-
Save jsta/64180683889f517c1d7cddf249062cc5 to your computer and use it in GitHub Desktop.
merge .webm (Audio) file and a .mp4 (Video) file
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
# https://stackoverflow.com/a/35939357/3362993 | |
import os | |
import glob | |
import subprocess | |
flist = sorted(glob.glob("*.webm") + glob.glob("*.mp4")) | |
pairs_index = [(x, x + 2) for x in range(0, len(flist), 2)] | |
flist_pairs = [flist[pairs_index[i][0]:pairs_index[i][1]] for i in range(0, int(len(flist)/2))] | |
def merge(audio, video): | |
stem = os.path.splitext(audio)[0] | |
outpath = stem + ".avi" | |
if not os.path.exists(outpath): | |
shell_cmd = "ffmpeg -i " + audio + " -i " + video + " -acodec copy -vcodec copy " + outpath | |
print(shell_cmd) | |
subprocess.call(shell_cmd, shell=True) | |
return None | |
for pair in flist_pairs: | |
merge(pair[1], pair[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment