Created
February 20, 2021 04:22
-
-
Save coding-youtuber/104896b498a7350ee67d138ac1ff2cc5 to your computer and use it in GitHub Desktop.
FFmpegを用いて動画にテロップをつける
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
import os | |
import subprocess | |
# Pythonからコマンド実行する例 | |
def add_telop(self, text, index, input_file_path): | |
file_name = os.path.basename(input_file_path) | |
output_video_path = os.path.join(self.telopped_working_dir, "{}.mp4".format(index)) | |
cmd = """ | |
ffmpeg -y -i {} \ | |
-filter_complex "drawtext=fontfile=/usr/share/fonts/truetype/freefont/FreeSerif.ttf: text='{}':\ | |
x=100: y=50: fontsize=35: fontcolor=yellow@0.9: box=1: boxcolor=red@0.9" {} | |
""".format(input_file_path, text, output_video_path) | |
# print(cmd) | |
subprocess.check_output(cmd, shell=True) |
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
# -i inputファイルパスを指定 | |
# -y 上書き保存 | |
# -filter_complex フィルターを指定 | |
# ffmpeg -y -i 元の動画ファイルパス \ | |
# -filter_complex "フィルターの内容を文字列で定義" \ | |
# 出力先の動画ファイルパス | |
# inputのファイルパス、出力先、フォントのファイルパスは環境に応じて書き換えてください | |
ffmpeg -y -i /Users/naoyashiga/youtube/hiroyuki/videos/source.mp4 \ | |
-filter_complex "drawtext=fontfile=/Users/naoyashiga/Library/Fonts/ラノベPOP.otf: text='こんにちは':\ | |
x=300: y=200: fontsize=100: fontcolor=blue@0.9: box=1: boxcolor=white@0.9" \ | |
/Users/naoyashiga/youtube/hiroyuki/videos/output.mp4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment