Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

636
Visualizações
ffmpeg in python script

I would like to run the following command in a python script, I also want to make it loop over several videos in a folder. This is the command I want to run.

ffmpeg -i mymovie.avi -f image2 -vf fps=fps=1 output%d.png

I want to fit it in something like this:

import ffmpy
import os

path = './Videos/MyVideos/'
for filename in os.listdir(path):
    name = filename.replace('.avi','')
    os.mkdir(os.path.join(path,name))
    *ffmpeg command here*

I found a wrapper for ffmpeg called ffmpy, could this be a solution?

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

From a brief look at FFMPY, you could do this using ffmpy.FFmpeg, as that allows any and all FFMPEG command line options, including -f. -- Click the link for documentation.

You could do the FFMPEG command with os.system. You'll need to import OS anyway to iterate through the files.

You would need to iterate through all the files in a directory though. This would be the more challenging bit, it's quite easy with a for loop though.

for filename in os.listdir(path):
    if (filename.endswith(".mp4")): #or .avi, .mpeg, whatever.
        os.system("ffmpeg -i {0} -f image2 -vf fps=fps=1 output%d.png".format(filename))
    else:
        continue

The above code iterates through the directory at path, and uses command prompt to execute your given FFMPEG command, using the filename (if it's a video file) in place of mymovie.avi

over 4 years ago · Santiago Trujillo Relatório

0

Dont have reputation to comment, hence adding another response.

Another version of ocelot's answer with the more readable f-string syntax of python -

for filename in os.listdir(path):
    if (filename.endswith(".mp4")): #or .avi, .mpeg, whatever.
        os.system(f'ffmpeg -i {filename} -f image2 -vf fps=fps=1 output%d.png')
    else:
        continue
over 4 years ago · Santiago Trujillo Relatório

0

Try pydemux in https://github.com/Tee0125/pydemux. Pydemux module can extract video frames as in Pillow Image format

from PyDemux import Video

v = Video.open('video.mov')

i = 0
while True:
    im = v.get_frame()

    if im is None:
        break

    im.save('output%d.png'%i)
    i = i + 1
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda