Skip to content

feat(ffmpeg): migrate from CLI bridge to libav*-based Kotlin API with CLI fallback #31

Merged
StageGuard merged 25 commits into
open-ani:mainfrom
GeneralK1ng:libav-patch
May 6, 2026
Merged

feat(ffmpeg): migrate from CLI bridge to libav*-based Kotlin API with CLI fallback #31
StageGuard merged 25 commits into
open-ani:mainfrom
GeneralK1ng:libav-patch

Conversation

@GeneralK1ng
Copy link
Copy Markdown
Member

Summary

This PR migrates mediamp-ffmpeg from a pure CLI bridge (FFmpegKit.execute(args) calling main()) to a thin Kotlin Multiplatform wrapper around libavformat / libavcodec, while preserving the CLI bridge as a fallback for unmapped operations.

Key Changes

New Kotlin API

  • MediaTranscoder + MediaOperation for high-level operations:
    • MediaOperation.Remux — stream copy with automatic time_base rescaling, per-stream BSF, and muxer options.
    • MediaOperation.Probe — read stream info.
  • Low-level wrappers: InputContainer, OutputContainer, Stream, AVPacket, BitstreamFilter, MuxerOptions.
  • Unified native types via internal expect/actual typealiases, enabling shared logic in commonMain.

CLI Bridge Preservation

FFmpegKit.execute(args) remains available as a fallback:

  • Recognized operations (Remux, Probe) are routed through the new Kotlin API.
  • Unrecognized / complex operations fall back to the extracted ffmpeg binary (Android/Desktop) or throw UnsupportedOperationException (iOS).

Android Native Library Consolidation

  • Switched androidMain dependency to libs.ffmpeg (pure Java API) to prevent JavaCPP prebuilt libav*.so from entering the AAR.
  • Added ExtractJavaCppJniTask to extract JavaCPP JNI bridge libjni*.so from classifier jars.
  • AAR now contains exactly one set of self-built libav*.so + libjni*.so, resolving mergeNativeLibs conflicts.

Breaking Changes

  • Removed legacy CLI wrapper C files (ffmpegkit_jni.c, MediampFFmpegKit.h) and fftools linkage.
  • Flattened package directory structure.

GeneralK1ng added 23 commits May 1, 2026 02:50
…areFfmpegAndroidJniLibsTask for Gradle configuration cache compatibility
… so from JavaCPP jars and switching to pure Java API dependency
@Him188 Him188 requested a review from StageGuard May 3, 2026 07:13
Copy link
Copy Markdown
Member

@StageGuard StageGuard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found two blocking regressions in the optimized FFmpegKit path.

Comment thread mediamp-ffmpeg/src/commonMain/kotlin/ArgsParser.kt
Comment thread mediamp-ffmpeg/src/iosMain/kotlin/FFmpegKit.ios.kt
@GeneralK1ng GeneralK1ng requested a review from StageGuard May 4, 2026 14:00
@StageGuard StageGuard merged commit a454f85 into open-ani:main May 6, 2026
4 checks passed
StageGuard added a commit that referenced this pull request May 10, 2026
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.

3 participants