feat: pause and resume FFmpeg sessions - #12
Merged
Merged
Conversation
Adds pause(sessionId), resume(sessionId) and getSessionState(sessionId) (closes #11). FFmpeg has no pause of its own, so the fftools patch makes the threads that bring data into the pipeline wait while the running session is paused: demuxer threads before each read (shifting their -re/-readrate clocks by the time paused) and input-less filtergraphs before pulling frames. Downstream work drains and idles, output files stay open, and resuming continues from the exact packet reading stopped at: nothing is re-encoded or skipped, and the execute() promise settles once. Queued sessions can be paused and start paused; cancel() and cancelAll() work while paused. The core keys pauses on the numeric session id (new munim_ffmpeg_execute_session / munim_ffmpeg_probe_session entry points; the existing ones run with id 0) because the Android bridge makes a fresh JNI reference per run. getSessionState() reports queued, running, paused, completed, failed or cancelled; FFprobe sessions report state but cannot be paused. The example suite gains two device checks. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
… 33-check suite Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Member
Author
|
🎉 This PR is included in version 0.8.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #11.
What
pause(sessionId): boolean: pauses anexecute()session, whether running or queued.resume(sessionId): boolean: resumes a paused session.getSessionState(sessionId): returnsqueued,running,paused,completed,failed,cancelledorunknown.How
This does a real pause, rather than the cancel-and-restart-with-
-ssapproach suggested in the issue, which re-encodes around the seek point and can drift. FFmpeg 9's fftools runs demuxing, decoding, filtering, encoding and muxing on separate threads. The patch inscripts/ffmpeg/fftools-hooks.shmakes the threads that bring data into the pipeline wait while their session is paused:av_read_frame, and shift their-re/-readratewallclocks by the time spent paused so they don't burst afterwards.-filter_complex testsrcand similar) wait before pulling frames.Everything downstream drains and idles, so a paused session uses no CPU. Output stays open, and resuming continues from the exact packet where reading stopped. The
execute()promise settles once.cancel()/cancelAll()wake a paused session and cancel it as before, and a queued session can be paused so that it starts paused.The core keys pauses on the numeric session ID through the new
munim_ffmpeg_execute_session/munim_ffmpeg_probe_sessionentry points; the old entry points use ID 0. The Android bridge creates a new JNI global reference for every run, so the callback pointer can't identify a session. FFprobe sessions report their state but can't be paused.Verified so far
munim_ffmpeg_core.cagainst a fakeffmpeg_mainreader thread. It checks:tsc(package and example) and eslint pass.Still to do: run the device suite (two new checks) on the Galaxy A14 and the iPad Air M3 against binaries built by this PR's
build-binariesrun.🤖 Generated with Claude Code