GreycLab / CImg

The CImg Library is a small and open-source C++ toolkit for image processing
http://cimg.eu
Other
1.48k stars 282 forks source link

save_ffmpeg_external doesn't pass fps parameter properly to ffmpeg #368

Open yanongena opened 1 year ago

yanongena commented 1 year ago

I'm new to cImg so maybe it's me, not using the library properly but I noticed that when I have a CImgList and use save_ffmpeg_external to save the video, no matter what value I provide for fps, the video is always saved with 25fps.

When I looked through the code, I noticed that the function does not send the -framerate parameter to ffmpeg, only the -r parameter but that doesn't seem sufficient.

I updated the code that calls the ffmpeg:

cimg_snprintf(command,command._width,
                    "\"%s\" -framerate %u -v -8 -y -i \"%s_%%6d.ppm\" -pix_fmt yuv420p -vcodec %s -b %uk -r %u \"%s\"",
                    cimg::ffmpeg_path(),
                    fps,
                    CImg<charT>::string(filename_tmp)._system_strescape().data(),
                    _codec,bitrate,fps,
                    CImg<charT>::string(filename)._system_strescape().data())

This adds the -framerate parameter and when I use that, it does work and I get the correct FPS in the video.

So, is this a bug or is it me, not using the library correctly?

I tried this on both Windows 10 and 11 with ffmpeg 5.1.2 and cImg 320

dtschump commented 1 year ago

Thanks for the feedback. Function save_ffmpeg_external() is quite old, and it may happen that I've used an older version of ffmpeg with different options ? Anyway, thanks for your suggestion, I've pushed it as commit https://github.com/GreycLab/CImg/commit/f2dc3ef7b28228a3242f052829d7c49b7e6e8dbd