-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathffmpeg-vf-dev
executable file
·49 lines (43 loc) · 1.91 KB
/
ffmpeg-vf-dev
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python3
#
# Play a video and its FFmpeg -vf filtered version side-by-side without creating a video file as intermediary step.
#
# Usage example:
# ffmpeg-vf-dev video.mp4 "boxblur=10"
# ffmpeg-vf-dev video.mp4 "boxblur=10" --savePath output.mp4
#
# Docs for writing filters: <https://ffmpeg.org/ffmpeg-filters.html>
import shutil
import subprocess
def main(args):
if not shutil.which("ffmpeg"):
print("Could not find `ffmpeg`.")
return
if not shutil.which(args.videoPlayer) and not args.savePath:
print(f"Could not find `{args.videoPlayer}`. You can alternatively use --savePath.")
return
ss = f"-ss {args.t0}" if args.t0 else ""
if not args.savePath or args.saveSideBySide:
# Side-by-side. Left original, right filtered.
vf = "-vf \"[0:v]split[half1][half2];[half2]{}[out];[half1][out]hstack\"".format(args.vf)
else:
vf = "-vf \"{}\"".format(args.vf)
if args.savePath:
out = args.savePath
else:
out = f"-f matroska - | {args.videoPlayer} -"
cmd = f"ffmpeg -i {args.videoPath} {ss} {vf} {out}"
print(cmd)
# Display the FFmpeg stderr because it may contain the "File already exists. Overwrite? [y/N]" prompt.
subprocess.run(cmd, shell=True)
if __name__ == "__main__":
import argparse
p = argparse.ArgumentParser(__doc__)
p.add_argument("videoPath", help="Path to the video to use.")
p.add_argument("vf", help="FFmpeg `-vf` argument value.")
p.add_argument("--savePath", help="Save to file instead of playing back live.")
p.add_argument("--saveSideBySide", action="store_true", help="With --savePath, concatenate the original and filtered videos.")
p.add_argument("--videoPlayer", default="mpv", help="Installed video player that supports playback from stdin.")
p.add_argument("--t0", type=float, help="Skip this many seconds from the beginning.")
args = p.parse_args()
main(args)