mwydmuch / ZoomVideoComposer

Pyhton script for generating zoom in/out videos from a set of images
MIT License
108 stars 20 forks source link

ffmpeg using hwaccel dramatically decreases scaling and encoding time #4

Open optisynapsis opened 1 year ago

optisynapsis commented 1 year ago

Not a python master so not sure how easy this would be to achieve, I presume this could be installed as a dependency through pip?

Obviously, it's possible to just save the frames and not encode the video, and do this manually. The scaling algorithm might be a little better with the original script truth be told, although frame generation time will be pretty high in comparison.

But here's an example of ffmpeg using cuda for anybody who's interested in doing it that way :

ffmpeg -hwaccel cuvid -framerate 30 -i %06d.png -i 'optionalaudio.wav' -vf "hwupload_cuda,scale_cuda=1280:720" -c:v h264_nvenc -c:a aac -b:a 320k output720.mp4

mwydmuch commented 1 year ago

Should be quite easy to support it, thanks for suggestion!

optisynapsis commented 1 year ago

No problem :)

Done some more experimenting. Here's my newest command line (which allows for lanczos scaling and doesn't seem much slower. Quality is noticeably improved.)

ffmpeg -hwaccel cuvid -framerate 30 -i %06d.png -i 'optionalmusic.wav' -vf "scale=1920:1080:flags=lanczos,format=yuv420p" -c:v h264_nvenc -profile:v main -preset slow -cq:v 21 -c:a aac -b:a 320k -movflags +faststart output1080.mp4

Obviously there's a little more to experiment with here. At the moment I'm trying to encode in a manner that's compatible with facebook at 2160p, as it's defaulting to 720p no matter what I upload.