Skip to main content

Baycone

Tests PyPI Python License

Transcode videos into streaming-friendly MP4 with ffmpeg — as a Python library or a command.

Baycone turns a video file into an MP4 that plays everywhere and starts instantly: h264 or hevc video, AAC audio and the moov atom up front. It only re-encodes what needs it, picks the audio tracks you want and never leaves a half-written file behind.

This package is the pipeline behind the Baycone Docker image, which watches media libraries and processes new files automatically.

Features

  • Two-pass libx264 / libx265 encode to a target bitrate, never above the source's
  • Copies streams that are already within limits; a container mismatch alone is fixed by a remux
  • Scales down to fit 1920×1080 (configurable), crops black bars and tone maps HDR10 / HLG to SDR
  • Keeps the original audio language plus your preferred ones, one track per language at the preferred channel count
  • Extracts text subtitles to UTF-8 .srt files
  • Detects copies that were cut off, kills a hung ffmpeg, and resumes an interrupted encode from its second pass
  • Writes the output in one step after it is safely on disk; the input file is never modified

Requirements

  • Python 3.14
  • ffmpeg and ffprobe on PATH, built with libx264, libx265 and libzimg (most distribution builds are)

Installation

pip install baycone
# or, for the command only
uv tool install baycone

Command line

baycone-cli movie.mkv                          # result in _baycone_processed/movie.mp4 next to the input
baycone-cli movie.mkv --output /media/out.mp4
baycone-cli movie.mkv -l cze -l eng -v 1800    # audio languages in order, video bitrate in kbps
baycone-cli movie.mkv --codec hevc
baycone-cli movie.mkv --remux-only             # never encode, only remux into MP4
baycone-cli trailer.mp4 --start 0:07 --end 2:21.5 --force-video-encode  # frame-accurate cut
baycone-cli movie.mkv --info                   # print the analysis as JSON and exit
Flag Default Description
--output _baycone_processed/ Output file
--work-dir .baycone/cli/ Temporary files; the default one is removed afterwards
-l, --language original eng cze Audio language to keep, repeatable, in order
-v, --video-bitrate 2250 Target video bitrate in kbps
-a, --audio-bitrate 64 Target audio bitrate per channel in kbps
--codec h264 Target video codec, h264 or hevc
--subtitles none Subtitle language to extract to .srt, repeatable
--undefined-language keep und Audio language assumed for tracks without one
--undefined-subtitle-language keep und Subtitle language assumed for streams without one
--start, --end none Cut from / at a position, [[HH:]MM:]SS[.fff]
--force-video-encode off Encode the video even within every limit
--remux-only off Copy every stream, only remux into the target container
--info off Print the analysis as JSON and exit
--ffmpeg, --ffprobe ffmpeg, ffprobe Binaries to use

A cut is exact only when the video is encoded: a copied video starts at the keyframe before --start, so add --force-video-encode for a source that is already within limits.

Exit codes: 0 success, 1 the file could not be processed, 2 invalid arguments, 130 stopped by Ctrl+C.

Library

from pathlib import Path

from baycone import BayconeError, Encoder, EncodingSettings, Job

settings = EncodingSettings(target_video_bitrate=1800, target_audio_languages=["original", "eng"])
job = Job(input_file=Path("movie.mkv"), output_file=Path("out/movie.mp4"), work_dir=Path("work"))

try:
    Encoder(settings, on_progress=lambda step, percent: print(step, percent)).process(job)
except BayconeError as e:
    ...  # the input is untouched and no output is left behind
  • EncodingSettings holds every encoding setting: allowed codecs and containers, targets and limits.
  • Encoder.process() returns the output path or raises a BayconeError: InsufficientSpaceError before anything is written, InvalidFileError for an unreadable or truncated file, EncodingError when ffmpeg fails, and SourceChangedError when the input changed while it was processed.
  • Keep work_dir on the same filesystem as output_file, otherwise publishing has to copy the file.
  • Job(..., start=7.0, end=141.5) cuts the video to that range of the source, in seconds; an out-of-range cut raises InvalidCutError before anything is written. The cut is frame-accurate when the video is encoded; a copied video starts at the keyframe before start, so set force_video_encode=True for a source within limits.
  • Analyzer(settings).analyze(path) returns the analysis alone, without encoding anything.
  • The library logs through logging under baycone.* and configures no handlers. It is fully typed.

Released under the MIT License.

Metadata

Release files for baycone 0.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for baycone 0.9.0
File Size Uploaded Provenance Actions
baycone-0.9.0.tar.gz 31.1 kB Without provenance Details for baycone-0.9.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for baycone 0.9.0
File Interpreter ABI Platform Actions
baycone-0.9.0-py3-none-any.whl Python 3 none any Details for baycone-0.9.0-py3-none-any.whl

Total release size: 63.1 kB

Release files / baycone-0.9.0.tar.gz

Download URL baycone-0.9.0.tar.gz
Size 31.1 kB
Tags Source
SHA-256 checksum
How to use checksums
27cce0547cccb8b97aac140b64fccc1d64af033b94bc14de63cb9416cd4307b3
BLAKE2b-256 checksum
How to use checksums
ff44d3aabac4d2bd9929a8b97a791d883bad76d3cc842ad4003ac433fad97e77
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Omarchy","version":"4.5.0","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / baycone-0.9.0-py3-none-any.whl

Download URL baycone-0.9.0-py3-none-any.whl
Size 32.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
953e4d99fd44ab295c41f00a4b8dec74dfdfe95b66945a76023c7560b9f3425d
BLAKE2b-256 checksum
How to use checksums
fac5d3c102f14a11aea97b70e41ffd6dcaf3139b2eddbea00330516eb6524536
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Omarchy","version":"4.5.0","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for baycone 0.9.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page