Skip to content

feat: pause and resume FFmpeg sessions - #12

Merged
sheehanmunim merged 2 commits into
mainfrom
feat/pause-resume
Sep 19, 2026
Merged

sheehanmunim merged 2 commits into
mainfrom
feat/pause-resume

Conversation

@sheehanmunim

Copy link
Copy Markdown
Member

Closes #11.

What

  • pause(sessionId): boolean: pauses an execute() session, whether running or queued.
  • resume(sessionId): boolean: resumes a paused session.
  • getSessionState(sessionId): returns queued, running, paused, completed, failed, cancelled or unknown.

How

This does a real pause, rather than the cancel-and-restart-with--ss approach 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 in scripts/ffmpeg/fftools-hooks.sh makes the threads that bring data into the pipeline wait while their session is paused:

  • Demuxer threads wait before each av_read_frame, and shift their -re/-readrate wallclocks by the time spent paused so they don't burst afterwards.
  • Filtergraphs with no inputs (-filter_complex testsrc and 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_session entry 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

  • A native harness links the real munim_ffmpeg_core.c against a fake ffmpeg_main reader thread. It checks:
    • no progress while paused;
    • the run completes after resume, and the hook reports the time spent paused;
    • cancel while paused returns 255;
    • a queued session starts paused and completes after resume;
    • unknown and zero IDs do nothing.
  • The fftools patch applies cleanly to FFmpeg 9.0.2, and fails on anchor drift.
  • 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-binaries run.

🤖 Generated with Claude Code

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>
Copilot AI lite review requested due to automatic review settings September 19, 2026 20:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

… 33-check suite

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@sheehanmunim
sheehanmunim merged commit 46852ea into main Sep 19, 2026
8 checks passed
sheehanmunim pushed a commit that referenced this pull request Sep 19, 2026
## [0.8.0](v0.7.1...v0.8.0) (2026-09-19)

### ✨ Features

* pause and resume FFmpeg sessions ([#12](#12)) ([46852ea](46852ea))

### 🛠️ Other changes

* sync package-lock with the release ([47fae81](47fae81))
@sheehanmunim

Copy link
Copy Markdown
Member Author

🎉 This PR is included in version 0.8.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@sheehanmunim
sheehanmunim deleted the feat/pause-resume branch September 19, 2026 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add pause and resume support for FFmpeg sessions

2 participants