差分

移動: 案内検索
ページの作成:「したかったので、pythonスクリプトで実現した。ガバガバ。 自分用なので忘備録くらいの感覚。 == スクリプト == 以下を encode.p...」
したかったので、pythonスクリプトで実現した。ガバガバ。

自分用なので忘備録くらいの感覚。

== スクリプト ==
以下を encode.py みたいなファイルで置いて実行。

<pre>import re
import os
from subprocess import Popen

for folder in os.listdir("./"):
if os.path.isfile(folder):
continue
try:
for file in os.listdir(folder):
if os.path.isdir(file):
continue

if ".ts" in file:
path = os.getcwd()
output = re.sub(r'\.ts$','.mp4',file)
print('IN:' + path + '\\' + folder + '\\' + file + ' OUT:' + path + '\\' + folder + '\\' + output)
c = 'ffmpeg -y -analyzeduration 10M -probesize 32M -hwaccel cuvid -deint adaptive -drop_second_field 1 -c:v mpeg2_cuvid -i "' + path + '\\' + folder + '\\' + file +'" -sn -threads 0 -f mp4 -c:a aac -ar 48000 -b:a 192k -ac 2 -c:v h264_nvenc -profile high -b:v 0 -cq 33.5 -maxrate:v 4000k -rc-lookahead 60 -temporal-aq 1 -weighted_pred 0 -flags +loop-global_header -top 1 -b_ref_mode middle "' + path + '\\' + folder + '\\' + output + '"'
popen = Popen( c,shell=True )
popen.wait()
except:
print("Error... Next Folder")
</pre>
パス連結とかいいメソッドアリそうだけど調べるのすらめんどくさい、やりたいことができりゃいい、それがおじさん。

== 想定フォルダ構成 ==
以下みたいな感じのとき効力を発揮する。出力ファイルは同じフォルダにmp4形式。

<pre>
なんかフォルダ
 ├ encode.py
 ├ あにめ!
 │ ├ あにめ!1話.ts
 │ └ あにめ!2話.ts
 ├ あにめ2!
 │ ├ あにめ2!1話.ts
 │ └ あにめ2!2話.ts
 ・・・
</pre>

== 想定環境 ==
* OSはWindows想定
* NVENCが使えるGeForceのってるマシン用(新世代NVENCだと好ましい)<br>GPUでのデコード/エンコードしたいので
* ffmpegのパスが通ってる必要あり

エンコード速度はGTX1650Ti使用時で16x(1話2分弱で完了)出る。はやい。
651
回編集