Modern Apps git

← Modern-Apps.git

fix: remove ffmpeg-kit.aar binary to unblock F-Droid

Commit
c15815961c7581d178f5cb7bef45b79ab2973892
Author
Vayun Mathur <[email protected]>
When
2026-07-23 16:50 UTC (4 months ago)
Parents
c148c5f
youpipe/ffmpeg/ffmpeg-kit.aar is a 33MB prebuilt binary with native
libffmpegkit.so libs. F-Droid rejects prebuilt binaries without source
build recipe.

Only usage was SabrFfmpegMuxer.mux() - simple stream-copy MP4 mux of
separate audio+video temp files (no transcoding). Replaced with
android.media.MediaMuxer + MediaExtractor which uses only AOSP APIs and
is fully FOSS-compliant.

Changes:
- Delete youpipe/ffmpeg module (aar + build.gradle.kts)
- Remove include(':youpipe:ffmpeg') from settings.gradle.kts
- Remove implementation(project(':youpipe:ffmpeg')) from youpipe/build.gradle.kts
- Update .github/workflows/android.yml excludes
- Rewrite SabrFfmpegMuxer.kt to use MediaMuxer:
  - setDataSource on both temp files (fMP4)
  - Add video/audio tracks via addTrack()
  - Interleave samples by PTS for streaming compatibility
  - Handle buffer growth >2MB

Verified: ./gradlew :youpipe:assembleDebug BUILD SUCCESSFUL

Diff

.github/workflows/android.yml
diff --git a/.github/workflows/android.yml b/.github/workflows/android.ymlindex 913f18ae9a..22415ed9d1 100644--- a/.github/workflows/android.yml+++ b/.github/workflows/android.yml@@ -78,7 +78,6 @@ jobs:             -not -path "./tools/*" \             -not -path "./whatsapp-signal/*" \             -not -path "./youpipe/extractor/*" \-            -not -path "./youpipe/ffmpeg/*" \             -not -path "./watch/*" \             -not -path "./build-logic/*" | while read -r file; do             if grep -q "common-conventions-app" "$file"; then@@ -110,7 +109,6 @@ jobs:             -not -path "./tools/*" \             -not -path "./whatsapp-signal/*" \             -not -path "./youpipe/extractor/*" \-            -not -path "./youpipe/ffmpeg/*" \             -not -path "./watch/*" \             -exec grep -l "common-conventions-app" {} \; | \             sed 's|^\./||; s|/build.gradle.kts$||' | sort -u)
settings.gradle.kts
diff --git a/settings.gradle.kts b/settings.gradle.ktsindex ce3eda4be6..902e235fdb 100644--- a/settings.gradle.kts+++ b/settings.gradle.kts@@ -47,7 +47,6 @@ include(":photos") include(":health") include(":youpipe") include(":youpipe:extractor")-include(":youpipe:ffmpeg") include(":findfamily") include(":maps") include(":games:chess")
youpipe/build.gradle.kts
diff --git a/youpipe/build.gradle.kts b/youpipe/build.gradle.ktsindex 36046f9d3f..5f310d8a00 100644--- a/youpipe/build.gradle.kts+++ b/youpipe/build.gradle.kts@@ -29,7 +29,6 @@ dependencies {     implementation(libs.quickjs.kt)     implementation(libs.newpipe.nanojson)     implementation(libs.androidx.webkit)-    implementation(project(":youpipe:ffmpeg"))      implementRoom(libs)     implementation(project(":library:room"))
youpipe/ffmpeg/build.gradle.kts
diff --git a/youpipe/ffmpeg/build.gradle.kts b/youpipe/ffmpeg/build.gradle.ktsdeleted file mode 100644index 5d358fee1b..0000000000--- a/youpipe/ffmpeg/build.gradle.kts+++ /dev/null@@ -1,3 +0,0 @@-configurations.maybeCreate("default")--artifacts.add("default", file("ffmpeg-kit.aar"))
youpipe/ffmpeg/ffmpeg-kit.aar
diff --git a/youpipe/ffmpeg/ffmpeg-kit.aar b/youpipe/ffmpeg/ffmpeg-kit.aardeleted file mode 100644index 64f4364779..0000000000Binary files a/youpipe/ffmpeg/ffmpeg-kit.aar and /dev/null differ
youpipe/src/main/java/com/vayunmathur/youpipe/util/sabr/SabrFfmpegMuxer.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/util/sabr/SabrFfmpegMuxer.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/util/sabr/SabrFfmpegMuxer.ktindex b3aa63dafe..c5cdd1a4f3 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/util/sabr/SabrFfmpegMuxer.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/util/sabr/SabrFfmpegMuxer.kt@@ -1,58 +1,205 @@ package com.vayunmathur.youpipe.util.sabr +import android.media.MediaCodec+import android.media.MediaExtractor+import android.media.MediaFormat+import android.media.MediaMuxer import android.util.Log-import com.arthenica.ffmpegkit.FFmpegKit-import com.arthenica.ffmpegkit.ReturnCode import java.io.File import java.io.IOException+import java.nio.ByteBuffer  /**  * Muxes the separately-downloaded SABR audio and video temporary files into a single mp4 using- * ffmpeg (stream copy, no re-encode). Adapted from PipePipe's SabrFfmpegMuxer, decoupled from the- * giga DownloadMission storage/state machine: it writes straight to [output].+ * Android's native [MediaMuxer] + [MediaExtractor] (stream copy, no re-encode).+ *+ * Previously this used ffmpeg-kit (ffmpeg-kit.aar), a prebuilt non-free binary that blocks+ * F-Droid publication. This implementation uses only AOSP framework APIs and is fully+ * FOSS-compliant.+ *+ * Input files are fMP4 containers (init + media segments) produced by [SabrSegmentWriter].+ * Each file contains a single track (video-only or audio-only).  */ internal object SabrFfmpegMuxer {     private const val TAG = "SabrFfmpegMuxer"+    private const val INITIAL_BUFFER_SIZE = 2 * 1024 * 1024 // 2 MB      @Throws(IOException::class)     fun mux(videoInput: File, audioInput: File, output: File) {-        val command = buildList {-            add("-hide_banner")-            add("-nostats")-            add("-loglevel")-            add("fatal")-            add("-y")-            add("-i")-            add(videoInput.absolutePath)-            add("-i")-            add(audioInput.absolutePath)-            add("-map")-            add("0:v?")-            add("-map")-            add("1:a?")-            add("-c")-            add("copy")-            if (supportsFastStart(output)) {-                add("-movflags")-                add("+faststart")-            }-            add(output.absolutePath)-        }         Log.d(TAG, "remux video=${videoInput.length()} audio=${audioInput.length()} -> ${output.name}")-        val session = FFmpegKit.executeWithArguments(command.toTypedArray())-        if (!ReturnCode.isSuccess(session.returnCode)) {++        if (!videoInput.exists() || videoInput.length() == 0L) {             throw SabrDownloadException(                 SabrDownloadException.Reason.MUXING,-                "SABR download failed: ffmpeg remux failed (${session.returnCode})"-                    + session.output.takeIf { it.isNotBlank() }?.let { ": $it" }.orEmpty(),+                "SABR download failed: video temp file missing or empty",             )         }-    }+        if (!audioInput.exists() || audioInput.length() == 0L) {+            throw SabrDownloadException(+                SabrDownloadException.Reason.MUXING,+                "SABR download failed: audio temp file missing or empty",+            )+        }++        output.parentFile?.mkdirs()+        if (output.exists() && !output.delete()) {+            throw SabrDownloadException(+                SabrDownloadException.Reason.STORAGE,+                "SABR download failed: could not delete existing output",+            )+        }++        var muxer: MediaMuxer? = null+        var videoExtractor: MediaExtractor? = null+        var audioExtractor: MediaExtractor? = null++        try {+            videoExtractor = MediaExtractor().apply { setDataSource(videoInput.absolutePath) }+            audioExtractor = MediaExtractor().apply { setDataSource(audioInput.absolutePath) }+            muxer = MediaMuxer(output.absolutePath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4)++            // Use non-null locals after creation to avoid !!.+            val vExtractor = videoExtractor+            val aExtractor = audioExtractor+            val mMuxer = muxer++            var videoExtractorTrackIndex = -1+            var videoMuxerTrackIndex = -1+            for (i in 0 until vExtractor.trackCount) {+                val format = vExtractor.getTrackFormat(i)+                val mime = format.getString(MediaFormat.KEY_MIME) ?: continue+                if (mime.startsWith("video/")) {+                    videoExtractorTrackIndex = i+                    videoMuxerTrackIndex = mMuxer.addTrack(format)+                    break+                }+            }++            var audioExtractorTrackIndex = -1+            var audioMuxerTrackIndex = -1+            for (i in 0 until aExtractor.trackCount) {+                val format = aExtractor.getTrackFormat(i)+                val mime = format.getString(MediaFormat.KEY_MIME) ?: continue+                if (mime.startsWith("audio/")) {+                    audioExtractorTrackIndex = i+                    audioMuxerTrackIndex = mMuxer.addTrack(format)+                    break+                }+            }++            if (videoMuxerTrackIndex == -1 && audioMuxerTrackIndex == -1) {+                throw SabrDownloadException(+                    SabrDownloadException.Reason.MUXING,+                    "SABR download failed: no video/audio tracks found in temp files",+                )+            }++            mMuxer.start()++            if (videoExtractorTrackIndex != -1) {+                vExtractor.selectTrack(videoExtractorTrackIndex)+            }+            if (audioExtractorTrackIndex != -1) {+                aExtractor.selectTrack(audioExtractorTrackIndex)+            }++            var videoBuffer = ByteBuffer.allocate(INITIAL_BUFFER_SIZE)+            var audioBuffer = ByteBuffer.allocate(INITIAL_BUFFER_SIZE)++            var videoDone = videoExtractorTrackIndex == -1+            var audioDone = audioExtractorTrackIndex == -1 -    private fun supportsFastStart(output: File): Boolean {-        return when (output.extension.lowercase()) {-            "m4a", "m4v", "mov", "mp4" -> true-            else -> false+            while (!videoDone || !audioDone) {+                val videoSampleTime = if (videoDone) {+                    Long.MAX_VALUE+                } else {+                    val t = vExtractor.sampleTime+                    if (t == -1L) {+                        videoDone = true+                        Long.MAX_VALUE+                    } else t+                }+                val audioSampleTime = if (audioDone) {+                    Long.MAX_VALUE+                } else {+                    val t = aExtractor.sampleTime+                    if (t == -1L) {+                        audioDone = true+                        Long.MAX_VALUE+                    } else t+                }++                if (videoDone && audioDone) break++                val useVideo = when {+                    videoDone -> false+                    audioDone -> true+                    else -> videoSampleTime <= audioSampleTime+                }++                if (useVideo) {+                    videoBuffer.clear()+                    var sampleSize = vExtractor.readSampleData(videoBuffer, 0)+                    if (sampleSize < 0) {+                        videoDone = true+                        continue+                    }+                    if (sampleSize > videoBuffer.capacity()) {+                        videoBuffer = ByteBuffer.allocate(sampleSize)+                        videoBuffer.clear()+                        sampleSize = vExtractor.readSampleData(videoBuffer, 0)+                        if (sampleSize < 0) {+                            videoDone = true+                            continue+                        }+                    }+                    val bufferInfo = MediaCodec.BufferInfo().apply {+                        set(0, sampleSize, vExtractor.sampleTime, vExtractor.sampleFlags)+                    }+                    mMuxer.writeSampleData(videoMuxerTrackIndex, videoBuffer, bufferInfo)+                    vExtractor.advance()+                } else {+                    audioBuffer.clear()+                    var sampleSize = aExtractor.readSampleData(audioBuffer, 0)+                    if (sampleSize < 0) {+                        audioDone = true+                        continue+                    }+                    if (sampleSize > audioBuffer.capacity()) {+                        audioBuffer = ByteBuffer.allocate(sampleSize)+                        audioBuffer.clear()+                        sampleSize = aExtractor.readSampleData(audioBuffer, 0)+                        if (sampleSize < 0) {+                            audioDone = true+                            continue+                        }+                    }+                    val bufferInfo = MediaCodec.BufferInfo().apply {+                        set(0, sampleSize, aExtractor.sampleTime, aExtractor.sampleFlags)+                    }+                    mMuxer.writeSampleData(audioMuxerTrackIndex, audioBuffer, bufferInfo)+                    aExtractor.advance()+                }+            }++            Log.d(TAG, "mux successful -> ${output.absolutePath} size=${output.length()}")+        } catch (e: SabrDownloadException) {+            runCatching { if (output.exists()) output.delete() }+            throw e+        } catch (e: Exception) {+            runCatching { if (output.exists()) output.delete() }+            throw SabrDownloadException(+                SabrDownloadException.Reason.MUXING,+                "SABR download failed: MediaMuxer remux failed: ${e.message ?: e.javaClass.simpleName}",+                e,+            )+        } finally {+            runCatching { videoExtractor?.release() }+            runCatching { audioExtractor?.release() }+            muxer?.let { m ->+                runCatching { m.stop() }+                runCatching { m.release() }+            }         }     } }