Skip to content

OpenCV video decoding too slow for vidgear - ffmpeg might be better suited for decoding #148

Open
@golyalpha

Description

@golyalpha

Detailed Description

I've ran some encode and decode benchmarks, and it's becoming fairly obvious, that VidGear (CamGear API) is currently unable to decode 1080p60 video on computers where, given certain settings, ffmpeg can encode 1080p60 in real time or slightly faster without hardware acceleration.

Context

Currently, it's impossible to pass 1080p60 H264 (only tested codec) video through VidGear on computers that should be able to decode 1080p60 video just fine. The idea would be to replace the OpenCV VideoStream API with something more performant, like ffmpeg, since ffmpeg is capable of outputting raw video into stdout.

The CamGear API should not need to change from the developer's standpoint.

Your Environment

  • VidGear version: 0.1.8
  • Branch: PyPI
  • Python version: 3.8.2
  • pip version: 19.2.3
  • Operating System and version: Win10Pro 1909

Any Other Important Information

Encode/Decode benchmarks for VidGear (encode is compressed, so ffmpeg):

> poetry run sp-benchmark
Results:
        Encode:
                1080p: 71.34738617215714
                900p: 94.22808977047293
                720p: 137.51681644444432
                480p: 388.3952044196786
                360p: 506.7212349134308
                240p: 1020.0560010744543
                144p: 1860.4607896260777
        Decode:
                1080p: 36.054442749368185
                900p: 44.78923780306475
                720p: 55.349642074620796
                480p: 76.08067848749076
                360p: 81.93545752827764
                240p: 90.02970867849261
                144p: 99.95882945711747

ffmpeg decode benchmark (4k60):

> ffmpeg -i .\streampipe\benchmark\resources\bbb_sunflower_2160p_60fps_normal.mp4 -f null -
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '.\streampipe\benchmark\resources\bbb_sunflower_2160p_60fps_normal.mp4':
  Duration: 00:10:34.53, start: 0.000000, bitrate: 8487 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 3840x2160 [SAR 1:1 DAR 16:9], 8002 kb/s, 60 fps, 60 tbr, 60k tbn, 120 tbc (default)
    Stream #0:1(und): Audio: mp3 (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 160 kb/s (default)
    Stream #0:2(und): Audio: ac3 (ac-3 / 0x332D6361), 48000 Hz, 5.1(side), fltp, 320 kb/s (default)
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> wrapped_avframe (native))
  Stream #0:2 -> #0:1 (ac3 (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Output #0, null, to 'pipe:':
    Stream #0:0(und): Video: wrapped_avframe, yuv420p(progressive), 3840x2160 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 60 fps, 60 tbn, 60 tbc (default)
    Stream #0:1(und): Audio: pcm_s16le, 48000 Hz, 5.1(side), s16, 4608 kb/s (default)
frame=38072 fps=152 q=-0.0 Lsize=N/A time=00:10:34.56 bitrate=N/A speed=2.53x
video:19928kB audio:356706kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    In Progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions