Skip to content

[cli] Add --stdin to read the input video from a pipe - #598

Open
EnesSoydan wants to merge 1 commit into
Breakthrough:mainfrom
EnesSoydan:fix/434-stdin-input
Open

EnesSoydan wants to merge 1 commit into
Breakthrough:mainfrom
EnesSoydan:fix/434-stdin-input

Conversation

@EnesSoydan

Copy link
Copy Markdown

Closes #434
Closes #189

Adds a --stdin flag, so a video can be piped in:

ffmpeg -i input.mp4 -c copy -f matroska - | scenedetect --stdin detect-content list-scenes

This went through the task list in #189:

  • Backend: it uses VideoStreamAv, since PyAV already takes a file-like object. --stdin with another backend is an error, and so is combining it with -i.
  • Seeking: it isn't possible, so these commands now fail with a clear error before anything is processed: split-video, save-images, load-scenes, and time -s. save-html leaves out images.
  • Source path: save-fcp and save-otio are rejected as well, because they write a reference to a source file that doesn't exist here.
  • $VIDEO_NAME: it is set to stdin, so output files get names like stdin-Scenes.csv.

I left split-video from a stream out of this PR.

Two things I ran into while testing:

  • On Windows, sys.stdin.buffer.seekable() returns True for a pipe, and PyAV then fails with OSError: [Errno 22] when it tries to seek. _PipeReader is a small wrapper that reports the stream as non-seekable.
  • An MP4 with its index at the end of the file opens from a pipe but decodes no frames, without raising an error. The CLI now logs a critical message with a remux hint and exits with 1, so a pipeline doesn't treat it as success. __main__.py lets SystemExit through so this isn't logged as an unhandled exception. The existing OpenCV "no frames" path still exits with 0; I didn't change that here.

The new tests in tests/test_cli.py write to the CLI through a real pipe. They include a check that the scenes match the same video opened with -i.

I edited docs/cli.rst by hand instead of committing the output of generate_cli_docs.py, because the generator also changed some unrelated lines.

Tested on Windows with Python 3.10 and PyAV 17. I haven't run it on Linux or macOS, or with a real ffmpeg pipe, since ffmpeg isn't installed on my machine. The tests pipe the file's bytes directly.

@Breakthrough

Breakthrough commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner

Also FYI I'm trying to get v0.7.3. out right now so I'd like to hold this until after the release just to avoid bringing in any last minute changes. Feel free to continue working on this in the meantime though, I'll make sure we get this landed in the version that we ship just after v0.7.3.

Can you also post a quick comment in each of the linked bugs in the PR description so I can assign those issues to you (so folks know it's taken)? Just something like "I'd like to take this on, staged #598 for this" is sufficient. Thanks.

This branch has not been deployed

No deployments
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.

Support of input type "std input" [Feature Request] Support input via pipe

2 participants