Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 .mp4 output via FFmpeg fails.
#1
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!


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!")
Quote
#2
Given than it prints the command it shouldn't be hard to try the command yourself and see if it produces a result? You can even comment out the os.system("rm -rf %s"%folder) line so that the PNGs remain in the temp folder for your tests.
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Quote
#3
Thanks for the reply, it actually works on simpler things which I do, I mean I can get .mp4 outputs. But no luck with this one.
I re-installed ffmpeg and x264 via pip again but no luck either.

I guess I'll have to compose a video from the still pngs by keeping the 'temp' and using a video software.

Best wishes.
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)