Skip to content

Instantly share code, notes, and snippets.

@pandanote-info
Created December 31, 2017 09:40
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 pandanote-info/4df60375bb7518228cd8572836c7be70 to your computer and use it in GitHub Desktop.
Save pandanote-info/4df60375bb7518228cd8572836c7be70 to your computer and use it in GitHub Desktop.
moviefilelist.pyを使って生成したJSONのスクリプトを読み込んで、ちょっとおしゃれなexoファイルを生成するためのPython3のプログラム。
#!/usr/bin/env python
import io
import os
import sys
import json
import subprocess
import codecs
import re
import math
import random
import argparse
def dumpexo():
global s
global fileid
global layer_count
global total_layer_count
global group_count
global outputPrefix
with open(outputPrefix+str(fileid)+'.exo','w',encoding='cp932') as f:
f.write('\r\n'.join(s))
s = []
s.append("[exedit]")
s.append("width={0:d}".format(width))
s.append("height={0:d}".format(height))
s.append("rate=30")
s.append("scale=1")
s.append("length=470")
s.append("audio_rate=44100")
s.append("audio_ch=2")
fileid += 1
layer_count = 0
group_count = 1
parser = argparse.ArgumentParser(description='Command line options of findmp4inuvdl.py')
parser.add_argument('-o','--output-file-prefix', type=str, default='output', help='Prefix of the output file.')
parser.add_argument('-c','--cmd-file', type=str, default='cmd.txt', help='Filename of the command to find a mp4 file.')
parser.add_argument('-u','--uploaded-json-file-list', type=str, default='UploadedVideoDataList.json', help='Filename of a file which stores the list of videos.')
parser.add_argument('-l','--length-in-frames', type=int, default=3600, help='Length in frames.')
args = parser.parse_args()
params = vars(args)
outputPrefix = params['output_file_prefix']
cmdFile = params['cmd_file']
uvdl = params['uploaded_json_file_list']
lengthInFrames = params['length_in_frames']
cmdText = 'where /r c:\\Users\\Administrator'
with open(uvdl) as infile:
text = infile.read()
uvdl = json.loads(text)
with open(cmdFile) as cmdinfile:
cmdText = cmdinfile.read()
sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf-8')
sys.stderr = io.TextIOWrapper(sys.stderr.buffer,encoding='utf-8')
maxViewCount = -1
# path 1
for uploadedVideoData in uvdl:
if (uploadedVideoData["filename"] != '' and uploadedVideoData["filename"] != 'livestream.str'):
filepath = ''
cmd = cmdText.format(uploadedVideoData["filename"])
#print(" cmd: {0:s}".format(cmd));
try:
filepath = subprocess.check_output(cmd.split())
#print(re.sub(r'[\r\n]',"",filepath.decode('utf-8')))
uploadedVideoData["filepath"] = re.sub(r'[\r\n]+.*$',"",filepath.decode('utf-8'))
except:
print(" Error in {0:s}:".format(uploadedVideoData["filename"]))
if (maxViewCount < 0 or maxViewCount < int(uploadedVideoData["viewCount"])):
maxViewCount = int(uploadedVideoData["viewCount"])
# path 2
fileid=0
s = []
width=1920
height=1080
s.append("[exedit]")
s.append("width={0:d}".format(width))
s.append("height={0:d}".format(height))
s.append("rate=30")
s.append("scale=1")
s.append("length=3900")
s.append("audio_rate=44100")
s.append("audio_ch=2")
total_layer_count = 0
layer_count = 0
group_count = 1
random.seed()
for uploadedVideoData in uvdl:
if 'filepath' in uploadedVideoData:
if layer_count > 98:
dumpexo()
s.append("[{0:d}]".format(layer_count))
offset = random.randint(0,lengthInFrames-100)
length = random.randint(100,400)
startpos = 1+offset
s.append("start={0:d}".format(startpos))
endpos = startpos+length
s.append("end={0:d}".format(endpos))
s.append("layer={0:d}".format(layer_count+1))
s.append("group={0:d}".format(group_count))
s.append("overlay=1")
s.append("camera=0")
s.append("[{0:d}.0]".format(layer_count))
s.append("_name=動画ファイル")
s.append("再生位置=1")
playspeed = random.randint(300,600)
s.append("再生速度={0:d}".format(playspeed))
s.append("ループ再生=1")
s.append("アルファチャンネルを読み込む=0")
s.append("file={0:s}".format(uploadedVideoData["filepath"]))
s.append("[{0:d}.1]".format(layer_count))
s.append("_name=標準描画")
ratio = 50.0*math.pow((float(uploadedVideoData["viewCount"]) if (int(uploadedVideoData["viewCount"])>1.0) else 1.0)/maxViewCount,0.2)
xlimit = -width*(1.0+ratio/100.0)/2
s.append("X={0:f},{1:f},1".format(-xlimit,xlimit))
#s.append("X=0.0,0.0,1")
ylimit = int(height*(1.0-ratio/100.0)/2.0)
y = random.randint(-ylimit,ylimit)
s.append("Y={0:d},{1:d},1".format(y,y))
#s.append("Y=0.0,0.0,1")
s.append("Z=0.0,0.0,1")
s.append("拡大率={0:f}".format(ratio))
#s.append("拡大率=100.0")
s.append("透明度=20.0")
s.append("回転=0.00")
s.append("blend=0")
layer_count += 1
total_layer_count += 1
s.append("[{0:d}]".format(layer_count))
s.append("start={0:d}".format(startpos))
s.append("end={0:d}".format(endpos))
s.append("layer={0:d}".format(layer_count+1))
s.append("group={0:d}".format(group_count))
s.append("overlay=1")
s.append("audio=1")
s.append("[{0:d}.0]".format(layer_count))
s.append("_name=音声ファイル")
s.append("再生位置=0.00")
s.append("再生速度={0:d}".format(playspeed))
s.append("ループ再生=1")
s.append("動画ファイルと連携=1")
s.append("file={0:s}".format(uploadedVideoData["filepath"]))
s.append("[{0:d}.1]".format(layer_count))
s.append("_name=標準再生")
s.append("音量=0.0")
s.append("左右=0.0")
layer_count += 1
total_layer_count += 1
group_count += 1
with open(outputPrefix+str(fileid)+'.exo','w',encoding='cp932') as f:
f.write(re.sub('\n$','\n','\n'.join(s)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment