training_extensions icon indicating copy to clipboard operation
training_extensions copied to clipboard

Implement video upload endpoints

Open leoll2 opened this issue 10 months ago • 2 comments

Add support for video files in the media upload endpoints and implement the related logic to store them.

leoll2 avatar Jan 22 '26 08:01 leoll2

I've made some simple benchmarks of video processing using opencv and ffmpeg, two operations were checked:

  • get video metadata
  • extract video frame (39 seconds of 40, closer to the end of file)

Here are results:

Linux (WSL):

------------------------------------------------------------------------------------------------------ benchmark: 4 tests -----------------------------------------------------------------------------------------------------
Name (time in ms)                                              Min                 Max                Mean             StdDev              Median                IQR            Outliers      OPS            Rounds  Iterations
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_opencv_get_video_metadata_benchmark[CAP_FFMPEG]       24.1895 (1.0)       36.0511 (1.0)       29.5671 (1.0)       2.4462 (5.77)      29.3376 (1.0)       3.1083 (5.12)         35;1  33.8214 (1.0)         100           1
test_opencv_extract_video_frame_benchmark[CAP_FFMPEG]     101.3824 (4.19)     274.9190 (7.63)     114.6148 (3.88)     17.5268 (41.31)    112.3035 (3.83)      6.5550 (10.80)         3;7   8.7249 (0.26)        100           1
test_ffmpeg_get_video_metadata_benchmark                  114.9186 (4.75)     117.0041 (3.25)     116.0836 (3.93)      0.4243 (1.0)      116.1059 (3.96)      0.6071 (1.0)          30;0   8.6145 (0.25)        100           1
test_ffmpeg_extract_video_frame_benchmark                 174.3797 (7.21)     254.3791 (7.06)     198.5445 (6.72)     13.9698 (32.92)    196.5437 (6.70)     18.8180 (31.00)        28;1   5.0367 (0.15)        100           1
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Windows 11:

------------------------------------------------------------------------------------------------------ benchmark: 4 tests -----------------------------------------------------------------------------------------------------
Name (time in ms)                                              Min                 Max                Mean             StdDev              Median                IQR            Outliers      OPS            Rounds  Iterations
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_opencv_get_video_metadata_benchmark[CAP_FFMPEG]       19.6138 (1.0)       26.0333 (1.0)       22.4357 (1.0)       1.4013 (1.0)       22.2936 (1.0)       1.8332 (1.0)          30;0  44.5719 (1.0)         100           1
test_opencv_extract_video_frame_benchmark[CAP_FFMPEG]      91.2012 (4.65)     155.2391 (5.96)     106.4484 (4.74)     11.6513 (8.31)     103.0697 (4.62)     15.5076 (8.46)         22;2   9.3942 (0.21)        100           1
test_ffmpeg_get_video_metadata_benchmark                  198.6664 (10.13)    276.5289 (10.62)    224.1802 (9.99)     16.4288 (11.72)    222.5005 (9.98)     16.7351 (9.13)         28;7   4.4607 (0.10)        100           1
test_ffmpeg_extract_video_frame_benchmark                 288.4696 (14.71)    451.7002 (17.35)    326.5355 (14.55)    35.7551 (25.52)    312.4367 (14.01)    37.3885 (20.40)        17;8   3.0625 (0.07)        100           1
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Even though opencv uses ffmpeg backend under the hood it shows significantly lower latency in both OS for both operations.

Another advantage of opencv is that it doesn't require additional components to be bundled with the application, only python library is needed. No memory issues were detected during running the tests

warrkan avatar Feb 02 '26 14:02 warrkan

Even though opencv uses ffmpeg backend under the hood it shows significantly lower latency in both OS for both operations.

How do you explain this effect? Is it because ffmpeg runs in a subprocess (-> overhead to spawn the process) while OpenCV can directly call libavformat/libavcodec in the same process context?

Anyway, thank you very much for sharing these results, I suggest to move forward with OpenCV.

leoll2 avatar Feb 02 '26 16:02 leoll2