#πŸ”’ Convert images (frames) to a video with ffmpeg or cv2

83 messages Β· Page 1 of 1 (latest)

neon lagoon
#

hello!
i am trying to make a super generic lightweight screen recorder with python
i have managed to make the frame saving part, now comes the part where i shove all of them together into a video

i've tried cv2 (!pypi opencv-python) but the resulting video plays faster (more than 2x) than i wanted it to

i'm open to also using any other library that can do this for me

i split the project into two files
recorder: https://paste.pythondiscord.com/BH6Q
constructor: https://paste.pythondiscord.com/U6SA

white charmBOT
#

@neon lagoon

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

sour pollen
neon lagoon
sour pollen
#

ok, then

import os
os.system('ffmpeg -framerate 15 -pattern_type glob "<images_folder>/*" -c:v <video codec> out.mp4')
neon lagoon
#

ok -_-

sour pollen
#

Other than that, i think OpenCV videowriter has a FPS argument

neon lagoon
#

what is the video codec

neon lagoon
sour pollen
neon lagoon
sour pollen
#

did you double check in vlc that it shows a different frame rate?

neon lagoon
#

i dont have or know vlc

sour pollen
#

What does that say for yours?

neon lagoon
sour pollen
#

πŸ€¦β€β™‚οΈ

#

then don't tell me "you tried opencv but the video was too fast"

neon lagoon
#

i tried it

#

and i deleted it

sour pollen
#

try again

neon lagoon
#

and im gonna get it fropm the trahs

sour pollen
#

i mean how long did it take to make?

neon lagoon
#

no time

#

anyway i have trhe file

#

it says 15.00000000000000 FPS

sour pollen
#

πŸ€·β€β™‚οΈ looks like it worked then

neon lagoon
#

it still fast

sour pollen
#

Says it's only 2 seconds. Did it use all the files?

#

that would be 30 frames yeah?

neon lagoon
#

definitely

#

it was like

#

more than that

#

i have 2700+ frames rn saved that we can test

fast barn
#

2700/15 = 180

sour pollen
#

Maybe try the ffmpeg command just to see if it works

#

see if it produces what you want

neon lagoon
#
import os
os.system(f"ffmpeg -framerate {FPS} -pattern_type glob {path} -c:v mp4v out.mp4")
#

AVFormatContext @ 0000019ad749b240] Unable to choose an output format for 'C:\Users\Uzivatel\Videos\diepio_recording_001'; use a standard extension for the filename or specify the format manually.
[out#0 @ 0000019ad749af00] Error initializing the muxer for C:\Users\Uzivatel\Videos\diepio_recording_001: Invalid argument
Error opening output file C:\Users\Uzivatel\Videos\diepio_recording_001.
Error opening output files: Invalid argument

#

lemem delete this rq

#

ok i ran its kinda stuck

#

OK OK

#

it made a video

#

it did it

#

but its faster than its supposed to be

#

big success

#

the 2m video is 125mbs πŸ’€ its because of the quality i think

#

i hope i can degrade it after

#

@sour pollen

#

pls ;-;

sour pollen
neon lagoon
#

and how do i degrade the quality

sour pollen
neon lagoon
sour pollen
neon lagoon
#

the sample video i made plays for 2:24

#

with 2,726 frames

#

at 15fps

#

(1900 x 1080 quality)

sour pollen
neon lagoon
sour pollen
#

You can also try -vcodec libx264 -vf format=yuv420p before out.mp4 to drop down to 420p

neon lagoon
#

im still using cv2

sour pollen
neon lagoon
#

ok i will

#

guide me but i have to go to sleep in 3mins because tomorrow im having my PET exam

#

drop all the explanations here ill look at them tomorrow

sour pollen
#

sigh

neon lagoon
#

ITS NOT MY PROBLEM I DONT HAVE TIME

sour pollen
#
import os
os.system(f"ffmpeg -framerate {FPS} -pattern_type glob {path} -r 15 -c:v mp4v -vcodec libx264 -vf format=yuv420p out.mp4")
sour pollen
mighty fog
#

just.come back tomorrow?

neon lagoon
fast barn
stuck kiln
#

geomy das

white charmBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.