0

I am working on a simple video using matplotlib.animation. I couldn't help noticing that each time I run my project it took a rather long time to save the video. I am using a graphic card with the model of 3080Ti and when the code is running, CPU is under great pressure but my graphic card is not being used at all.

This is my code of output the video file:

ani.save('particle_box.mp4', fps=60, extra_args=['-vcodec', 'libx264'])

I tried to look up the official reference of the FFMpegWriter but I could not find something useful. Maybe someone could help me to deal with this problem?

yangyang
  • 125
  • 1
  • 6
  • Does this answer help [FFMPEG Hardware Encoding H264](https://stackoverflow.com/a/56049614/14277722)? It's from 2019 so it might not be accurate anymore. – Michael Szczesny Jan 18 '22 at 13:16
  • @MichaelSzczesny I've read this answer but I am not sure how to apply it into my case. It mentioned thhat libx264 is not the correct option. I've tried to remove it from my code but it comes with error. – yangyang Jan 18 '22 at 23:16
  • If you are still after this, have you tried `extra_args=['-vcodec', 'h264_nvenc']`? This being said, you generally get inferior video with HW encoding than SW encoding. Last, here is the reference directly from nVidia [Using FFmpeg with NVIDIA GPU](https://docs.nvidia.com/video-technologies/video-codec-sdk/ffmpeg-with-nvidia-gpu/#basic-testing) – kesh Jan 29 '22 at 22:12
  • @kesh hi, thanks for your help. I've tried your method and indeed your code imporved my code. To be more specific, your code takes 89.79 seconds and my code takes 104.35. This is almost 14% improvement. Thanks again. – yangyang Feb 01 '22 at 11:29

0 Answers0