VLCでもちゃんとチャプター名が表示されるように、エンコーディングはUTF-8を指定しています。
#!python3
# -*- coding: utf-8 -*-
# vim:fenc=utf-8 ff=unix ft=python ts=4 sw=4 sts=4 si et fdm fdl=99:
# vim:cinw=if,elif,else,for,while,try,except,finally,def,class:
#
# makechap.py:
# カレントディレクトリからすべての.keyframeファイルを検索し
# 順次aviutl(muxer.exe, remuxer.exe)が取り込める形式の
# チャプターマークに変換する。
# ファイルが引数として指定された場合は、そのファイルだけを処理する。
#
# TMPGEnc MPEG Smart Rendereの.keyframe 出力形式
# [chap1]
# Name=[チャプター名1]
# [chap2]
# Name=[チャプター名2]
# ただし[chapx]はフレーム番号
# チャプター名が明示的に指定されたときはName=の部分が使用される。
#
# muxer / remuxer のチャプター形式
# CHAPTER01=00:03:00.000
# CHAPTER01NAME=チャプター名1
# CHAPTER02=00:06:30.000
# CHAPTER02NAME=チャプター名2
import sys
from glob import glob
from os.path import join, splitext
from dateutil.relativedelta import relativedelta
if sys.version_info[0] != 3:
print('This script requires Python 3')
exit()
path = '.'
debug = 1
files = []
i = 0
print(sys.argv)
if len(sys.argv) > 1:
files = sys.argv
del files[0]
print(files[0])
else:
files = glob(join(path, '*.keyframe'))
if debug:
print('files:', files)
for kffile in files:
base = splitext(kffile)[0]
f = open(kffile, 'r', encoding='utf-8')
outfile = open(base+'.chapter.txt', 'w', encoding='utf-8')
lines = f.readlines()
i = 0 # line number
j = 1 # chapter number
while i < len(lines):
chap = ''
s = lines[i].rstrip()
if s == '': # skip blank line
i = i + 1
continue
if s.isdecimal(): # if line is frame number
rd = relativedelta(seconds=round(int(s)*0.0333667))
chap = "{:02}".format(j)
if (i+1) < len(lines):
if lines[i+1][0] == '#': # if next line is chapter name
chap = lines[i+1].lstrip('#Name=').rstrip()
i = i + 1
time = "{0.hours:02}:{0.minutes:02}:{0.seconds:02}.000".format(rd)
outfile.write(f'CHAPTER{j:02}={time}\n')
outfile.write(f'CHAPTER{j:02}NAME={chap}\n')
i = i + 1
j = j + 1
f.close()
outfile.close()
そしてこれを、MP4ファイルにあとからチャプターを打つ。でやったようにバッチファイルに仕込めばOKです。
0 件のコメント:
コメントを投稿