Skip to content

Conversation

@jonoomph
Copy link
Member

@jonoomph jonoomph commented Jun 6, 2025

Related to OpenShot/libopenshot-audio#165

Large performance improvements for FFmpegReader (decoding up to 300% faster). This was mostly due to fixing unaligned memory allocations. Improved performance of FFmpegWriter by 9% (utilizing a single SwsContext and reusing it). Improving VideoCacheThread so it can be used to further speed up FFmpegWriter (upwards of 30% faster when everything is working together).

  • Threading & caching

    • Split FF_NUM_PROCESSORSVIDEO/AUDIO; cap threads (video = 16, audio = 2)
    • Re-add VIDEO_CACHE_MAX_FRAMES; DRY up capacity logic
    • Expose VideoCacheThread via SWIG (Python/Ruby/Java)
    • Wire VideoCacheThread & FFmpegWriter into openshot-example for export caching & Valgrind tests
  • Performance

    • Switch to single persistent SwsContext + frames (+8–9% H.264 @720p)
    • Align FFmpegReader buffers to 32-byte (AVX2) via cross-platform malloc/free (×3 speed)
    • Minor cache/SWS reuse tweaks (~1.5% CPU)
    • Unify Settings (no header/Instance duplication; auto-detect CPU threads)
  • Mac & CI fixes

    • Revert experimental Mac build changes; restore & fix macOS unit tests in CI
    • Replace _MSC_VER_WIN32; use aligned free for QImage/frame buffers on Win32

jonoomph added 19 commits June 4, 2025 17:18
…jects. About 1.5% less CPU calls, and more even memory allocations (less spikey).
…2. This increases performance by a factor of 3X.
…e not found" errors when running unit tests.
…t for video scaling. Total improvement of 8-9% when testing h.264 encoding @ 720p.
… thread to a hard #. Also, minor refactor to reduce duplication of capacity.
…nce() method. Also changing FF_THREADS and OMP_THREADS to use # of processors on device.
…iting VIDEO encoders to 16 threads and audio encoders to 2 threads.
…xperiment with caching during export. It works great!
…. This will be called from openshot-qt in Python, to speed up exports.
@jonoomph
Copy link
Member Author

jonoomph commented Jun 6, 2025

@jonoomph jonoomph changed the title Ffmpeg performance FFmpeg Performance - Let's GO! Jun 6, 2025
@codecov
Copy link

codecov bot commented Jun 6, 2025

Codecov Report

Attention: Patch coverage is 72.78912% with 40 lines in your changes missing coverage. Please review.

Project coverage is 57.32%. Comparing base (9a4dcf2) to head (099fe59).
Report is 21 commits behind head on develop.

Files with missing lines Patch % Lines
src/Qt/VideoCacheThread.cpp 0.00% 25 Missing ⚠️
src/FFmpegWriter.cpp 83.56% 12 Missing ⚠️
src/FFmpegReader.cpp 93.75% 2 Missing ⚠️
src/FFmpegUtilities.h 80.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1014      +/-   ##
===========================================
+ Coverage    57.29%   57.32%   +0.03%     
===========================================
  Files          198      198              
  Lines        18148    18168      +20     
===========================================
+ Hits         10397    10415      +18     
- Misses        7751     7753       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jonoomph jonoomph merged commit cdaccf2 into develop Jun 7, 2025
13 checks passed
@jonoomph jonoomph deleted the ffmpeg-performance branch June 7, 2025 04:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants