Created
April 18, 2018 22:38
-
-
Save kuguma/9e700261b0904b2679fed1b9b76b7075 to your computer and use it in GitHub Desktop.
ffmpegで1枚絵Twitter用音楽動画を書き出すやつ
This file contains hidden or 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 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