Skip to content

Instantly share code, notes, and snippets.

@kuguma
Created April 18, 2018 22: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/9e700261b0904b2679fed1b9b76b7075 to your computer and use it in GitHub Desktop.
Save kuguma/9e700261b0904b2679fed1b9b76b7075 to your computer and use it in GitHub Desktop.
ffmpegで1枚絵Twitter用音楽動画を書き出すやつ
import os
import subprocess as sp
import sys
'''
requirements:
- python3
- ffmpeg
・正方形の絵とwavファイルを用意する。
・二分間の動画ができる。
'''
class Settings:
ffmpeg = "<.../ffmpeg.exe>"
music = "<.../music.wav>"
picture = "<.../square_pict.jpg>"
name = "<movie_name>"
output_path = "<...>"
def shell(cmd):
sp.call(cmd,shell=True)
#sp.check_output(cmd,shell=True,stderr=sp.STDOUT)
def ffmpeg():
print(" : START")
s = Settings()
cmd = '''\
{s.ffmpeg} -loop 1 \
-i "{s.picture}" \
-i "{s.music}" \
-c:v libx264 \
-pix_fmt yuv420p \
-t 00:02:00 \
-tune stillimage -preset medium -crf 18 -movflags +faststart \
-c:a aac -ab 384k -ar 48000 -ac 2 \
-r 30 -s 640x640 -aspect 1:1 \
-shortest "{s.output_path}/{s.name}.mp4" \
-y -threads 8\
'''.format(**locals())
shell( cmd )
print(" : ENCODED")
def main():
ffmpeg()
if __name__ == "__main__" :
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment