使用 FFmpeg 将 ManicTime 的截图转成视频

使用 FFmpeg,将 Manictime 生成的图片转为视频

最近用上了 ManicTime,其截图占用空间实在是太大,所以准备归档一下。

写了个小脚本,功能非常简单,把 ManicTime 的截图通过 FFmpeg 转成视频。代码大致是这样子:

# -*- coding: UTF-8 -*-

import os
import subprocess
from glob import glob

if __name__ == '__main__':
    path = input("path: ")
    num = input("num per second: ")
    file_list = glob(path + "\\*.jpg")
    video_name = input("video name: ")
    encode_type = int(input("encode type (1 - nvidia, 2 - intel): "))
    with open(path + "\\input.txt", "w") as f:
        for i in file_list:
            file_name = i.split('\\')[-1]
            if file_name.__contains__("thumbnail"):
                continue
            f.write("file " + file_name + "\n")
            f.write("duration {}\n".format(1 / int(num)))
    command = '''ffmpeg -f concat -i {}\input.txt -c:v {} -r 25 -vf "scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2" -loglevel error -y {}\{}.mp4'''.format(
        path, "h264_qsv" if 2 == encode_type else "h264_nvenc", path, video_name)
    print("executing command: " + command)
    code = subprocess.call(command, shell=True)
    print("subprocess exit code: {}".format(code))
    del_pic = int(input("delete pics? 1 or 0: "))
    if (del_pic):
        print("deleting...")
        for i in file_list:
            os.remove(i)
        print("delete finished")

图片转视频的 FFmpeg 调用大致是这样:

ffmpeg -f concat -i {{input.txt}} -c:v h264_qsv -r 25 -vf "scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2" -loglevel error -y {{target}}

算是自己第一次的 FFmpeg 实践吧,这玩意真是个好东西🤣

加载评论