Skip to content

Instantly share code, notes, and snippets.

@modbender
Created September 29, 2021 20:26
Show Gist options
  • Save modbender/812dc432669ca932c644218e27c8f27a to your computer and use it in GitHub Desktop.
Save modbender/812dc432669ca932c644218e27c8f27a to your computer and use it in GitHub Desktop.
Extract only video stream from all mkv in current folder and subdirectories into a mp4 file.
import os
import glob
import shutil
import pathlib
import ffmpeg
current_path = pathlib.Path(__file__).parent.resolve()
videos = glob.glob(os.path.join(current_path, '**', '*.mkv'), recursive=True)
rdname = 'vraw'
if os.path.exists(rdname):
shutil.rmtree(rdname)
os.makedirs(rdname)
rdpath = os.path.join(current_path, rdname)
fargs = {
'c': 'copy',
}
for vfile in videos:
fname = os.path.basename(vfile)
new_fname = fname.replace('.mkv', '.mp4')
new_vfile = os.path.join(rdpath, new_fname)
stream = ffmpeg.input(vfile)
stream = ffmpeg.output(
stream.video, new_vfile, **fargs,
)
stream = ffmpeg.overwrite_output(stream)
ffmpeg.get_args(stream)
ffmpeg.run(stream)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment