Jun-19-2017, 11:21 AM
Hello, I'm trying to use a code as below to create a .mp4 file (it's by someone else but I just wanted to try it out). It should create a mp4 file but after it creates a temp folder containing all the png frames and it gets deleted as expected after the process is finished - but it leaves no .mp4 file behind.
I also installed ffmpeg via pip install.
I wonder what I might be doing wrong?
Thanks!
I also installed ffmpeg via pip install.
I wonder what I might be doing wrong?
Thanks!
import scipy.misc import os cols, rows = 10, 4 nf = 24 # num frames per transitions ni = 4 # num transitions folder='temp' os.makedirs(folder) os.makedirs('%s/composite'%folder) print("generating frames for individual faces") for i in tqdm(range(cols)): for j in range(rows): idx = np.random.randint(n, size=ni) idx = np.append(idx, idx[0]) f = 1 for k in range(ni): xp1, xp2 = Xp[idx[k]], Xp[idx[k+1]] Z = [[(1.0-r)*i1 + r*i2 for i1, i2 in zip(xp1, xp2)] for r in np.linspace(0,1,nf)] Y = [ np.clip(pca.inverse_transform(z),0,255).reshape((w,h,3)) for z in Z ] for y in Y: scipy.misc.imsave('%s/face%02d_%02d_frame%04d.png'%(folder,i,j,f), y.astype('uint8')) f+=1 offset = np.random.randint(nf*(ni-1), size=cols*rows) print("compositing all the faces into one video") for f in tqdm(range(nf*ni)): img = Image.new('RGB',(w * cols, h * rows)) for i in range(cols): for j in range(rows): fidx = 1+(f + offset[i*rows+j])%(nf*ni) im = Image.open('%s/face%02d_%02d_frame%04d.png'%(folder,i,j,fidx)) img.paste(im, (i*w, j*h)) img = img.resize((int(1.2*img.size[0]), int(1.2*img.size[1]))) #upscale just a bit scipy.misc.imsave('temp/composite/frame%04d.png'%f, img) cmd = "ffmpeg -i %s/composite/frame%%04d.png -c:v libx264 -pix_fmt yuv420p composite.mp4"%folder print(cmd) os.system(cmd) os.system("rm -rf %s"%folder) print("done!")