0

I am trying to join a sequence of images (*.png) using ffmpeg. The filenames of the images are in the following format: recon_0001.png, recon_0002.png, ... , recon_0100.png. I would like to join the images sequentially (i.e. recon_0001.png being the first frame, recon_0002.png the second frame and so on.)

After looking at the following link: Python: Make a video using several .png images , I tried to implement my task using the following code:

from __future__ import division
import cv2
import os
import matplotlib.pyplot as plt
from pylab import pcolor, show, colorbar, xticks, yticks
import numpy as np

if(1):
    ffmpeg -f image2 -r 1/5 -i /Users/Username/Folder/recon_%04d.png -vcodec mpeg4 -y movie.mp4

But, I get the following error:

ffmpeg -f image2 -r 1/5 -i /Users/Username/Folder/recon_%04d.png -vcodec mpeg4 -y movie.mp4
               ^
SyntaxError: invalid syntax

What am I missing here? I am new to the use of ffmpeg and I will really appreciate any help.

Commoner
  • 1,678
  • 3
  • 19
  • 34
  • The `ffmpeg` command is valid and should execute just fine in a command-line interface, but you don't need `-f image2` and `-r` should be `-framerate`. The log/console output from the command will be informative if an output file is not created. – llogan Apr 24 '18 at 19:04
  • @LordNeckbeard: Thanks for the reply. But, I still get the same error after implementing your suggestion (Error: `SyntaxError: invalid syntax`) – Commoner Apr 24 '18 at 19:09
  • That's not a message from `ffmpeg`, so I'm guessing it's a python issue. You should show your actual code. – llogan Apr 24 '18 at 19:53
  • @LordNeckbeard : I added my code now. Is there something that I am missing in my code? – Commoner Apr 24 '18 at 20:44
  • I'm not sure. I'm not a python user, but I thought it would be useful for others who do know python to see your script. – llogan Apr 24 '18 at 20:50

1 Answers1

0

you need to import the "os" module and put the ffmpeg command in "os.system("ffmpeg command")" python doesnt automatically run terminal commands so you have to specify that with os.system

xyper
  • 1
  • 2