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
--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.8.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.8.0
File Size Uploaded Provenance Actions
baycone-0.8.0.tar.gz 30.4 kB Without provenance Details for baycone-0.8.0.tar.gz

Built distribution (wheel)

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

Total release size: 61.6 kB

Release files / baycone-0.8.0.tar.gz

Download URL baycone-0.8.0.tar.gz
Size 30.4 kB
Tags Source
SHA-256 checksum
How to use checksums
ad9e73d3170a853fcc714475025e0eac660cc788717c4beea93828da7183d624
BLAKE2b-256 checksum
How to use checksums
931fa402f9d81c60ddbe8fd9bfc25a8123094fa51525da180e6bc26cf82c95c5
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.8.0-py3-none-any.whl

Download URL baycone-0.8.0-py3-none-any.whl
Size 31.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5a99e119948b6ad0b826ef530ee41eedf880802effa4b54e122a90282ad0235f
BLAKE2b-256 checksum
How to use checksums
6dbda0b5d5e2491cd9e8648b078022c866f4ba93bace7562b9deba7005d65f2b
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.8.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