Search code examples
pythonffmpeg

ffmpeg. I want to connect pictures in a video. Does not work


I use

ffmpeg -f -i -r 24 -vcodec mjpeg -y test.mov

It's in python code

cmd = 'ffmpeg -f image2 -i '
cmd += ' '.join([f'{i}' for i in jpg_list])
cmd += ' -r 24 -vcodec mjpeg'
cmd += f' -y {first_secv}.mkv'

I need codec mjpeg, 24 frames.


Solution

  • if you use the iteration of a list then you need to add -i before each file name. but in case of many items it might be limited.

    cmd = 'ffmpeg -f image2 '
    cmd += ' '.join([f'-i {i}' for i in jpg_list])
    cmd += ' -r 24 -vcodec mjpeg'
    cmd += f' -y {first_secv}.mkv'
    

    in case all files has same name with numeric postfix then you can use %d format.

    cmd = 'ffmpeg -framerate 24 -i '
    cmd += 'glass_crack_v001_%6d.jpg -c:v mjpeg'
    cmd += f' -y {first_secv}.mkv''
    

    Another option its to create a text file with the order of the images:

    the file (lets call it input.txt for the example) format should be as (2 lines for example):

    file sea_v001_14479.jpg
    file glass_crack_v001_000002
    file /home/user/Dev/TEST/to\ sort/exp_1_00001.jpg # incase of space (add \ before the space) and -safe 0 in the ffmpeg command
    

    and then the command would be :

    cmd = 'ffmpeg -framerate 24 -safe 0 -i input.txt -c:v mjpeg'
    cmd += f' -y {first_secv}.mkv'