Skip to content

Instantly share code, notes, and snippets.

@kuguma
Created December 11, 2016 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuguma/d9b0e4ba3324958aa7909b600130ece1 to your computer and use it in GitHub Desktop.
Save kuguma/d9b0e4ba3324958aa7909b600130ece1 to your computer and use it in GitHub Desktop.
一枚絵からffmpegで動画を生成するバッチスクリプト
import os
import subprocess as sp
import sys
number = "07"
title = "月の息"
class Settings:
picture = "hogehoge"+number
music = "hogehoge"+number+" "+title
movie = "hogehoge"+number
ffmpeg = "C:/Programs/ffmpeg-20161122-d316b21-win64-static/bin/ffmpeg.exe"
def shell(str):
#sp.call(str,shell=True)
sp.check_output(str,shell=True,stderr=sp.STDOUT)
def getTrackList():
tracks = os.listdir(os.path.abspath(Settings.music))
tracks.sort()
for i in range(len(tracks)):
tracks[i] = tracks[i].split(".")[0]
#print(tracks)
return tracks
def exist_check(tracks):
print("file check")
flag = False
for t in tracks:
fpath = Settings.picture + "/" + t + " - 1920x1080.png"
if not os.path.exists(fpath):
print("{t} - No such file".format(t=t))
flag = True
else:
print("{t} - OK".format(t=t))
if flag:
sys.exit()
print("file check passed")
def main():
s = Settings()
tracks = getTrackList()
exist_check(tracks)
for t in tracks:
cmd = '''\
{s.ffmpeg} -loop 1 \
-i "{s.picture}/{t} - 1920x1080.png" \
-i "{s.music}/{t}.wav" \
-c:v libx264 \
-tune stillimage -preset medium -crf 18 -movflags +faststart \
-c:a aac -ab 384k -ar 48000 -ac 2 \
-r 30 -s 1920x1080 -aspect 16:9 \
-shortest "{s.movie}/{t}.mp4" \
-y -threads 2\
'''.format(**locals())
print(t + "...")
#print(cmd)
shell( cmd )
print(" : ENCODED")
print("All file encoded.")
#-b:v 30M
if __name__ == "__main__" :
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment