LaPian (拉片)
A single-file Python tool for batch video transcoding with hardware-accelerated encoding support. Provides both a CLI and a graphical (tkinter) interface.
Installation
From PyPI (recommended)
pip install lapian
After installation, use the lapian command directly:
lapian -p android video.mp4
lapian --gui
From source
git clone https://github.com/cycleuser/LaPian.git
cd LaPian
pip install .
Or run the script directly without installing:
python lapian.py
Features
- 4 output presets: GIF, Android-compatible MP4, minimum-size MP4, audio-only extraction
- Hardware acceleration: Auto-detects NVENC, QSV, AMF, VAAPI, VideoToolbox encoders with software fallback
- Batch processing: Transcode multiple files or entire directories (recursive by default, preserves directory structure)
- Dual interface: Full-featured CLI and tkinter GUI
- Chinese support: Auto-detects system locale, GUI and CLI output in Chinese when appropriate
- Progress tracking: Real-time per-file and overall progress
- Dry-run mode: Preview FFmpeg commands without executing
- Cross-platform: Works on Linux, macOS, and Windows
Prerequisites
- Python 3.8+ with tkinter (included in most Python installations)
- FFmpeg (including ffprobe) installed and available in PATH
Installing FFmpeg
| OS | Command |
|---|---|
| Ubuntu/Debian | sudo apt install ffmpeg |
| Fedora | sudo dnf install ffmpeg |
| Arch Linux | sudo pacman -S ffmpeg |
| macOS (Homebrew) | brew install ffmpeg |
| Windows | Download from ffmpeg.org and add to PATH |
Installing tkinter (if not already available)
| OS | Command |
|---|---|
| Ubuntu/Debian | sudo apt install python3-tk |
| Fedora | sudo dnf install python3-tkinter |
| macOS (Homebrew) | brew install python-tk |
Quick Start
GUI Mode
Launch the graphical interface:
lapian --gui
Or run the script directly with no arguments:
python lapian.py
CLI Mode
lapian -p <preset> [options] <input_files_or_dirs...>
CLI Usage
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
input |
positional | (required) | Input video files or directories |
-p, --preset |
choice | (required) | Preset: gif, android, minsize, audio |
-o, --output |
path | ./transcoded |
Output directory |
-r, --recursive |
flag | true |
Recursively search directories (on by default) |
--no-recursive |
flag | false |
Disable recursive directory search |
--encoder |
string | (auto) | Force a specific encoder (e.g., h264_nvenc) |
--crf |
int | (preset default) | Override CRF quality value |
--fps |
int | 10 |
GIF framerate |
--width |
int | (original) | Max output width in pixels |
--resolution |
choice | (original) | Output resolution: 2160p, 1440p, 1080p, 720p, 480p, 360p, 240p |
--bitrate |
string | (CRF-based) | Video bitrate, e.g. 2M, 500k |
--video-fps |
choice | (original) | Output framerate: 60, 30, 25, 24, 15 |
--audio-format |
choice | mp3 |
Audio format: mp3 or aac |
--dry-run |
flag | false |
Print FFmpeg commands without executing |
--gui |
flag | false |
Launch GUI mode |
-v, --verbose |
flag | false |
Show detailed FFmpeg output |
--version |
flag | Show version and exit |
Examples
Convert a video to Android-compatible MP4:
lapian -p android video.mp4
Convert all videos in a directory to GIF (15fps, 320px wide):
lapian -p gif --fps 15 --width 320 /path/to/videos/
Create minimum-size MP4 from multiple files:
lapian -p minsize -o ./compressed video1.mp4 video2.mkv video3.avi
Extract audio as AAC:
lapian -p audio --audio-format aac movie.mkv
Preview commands without executing (dry run):
lapian -p android --dry-run video.mp4
Force a specific hardware encoder:
lapian -p android --encoder h264_nvenc video.mp4
Preset Details
gif - Animated GIF
Converts video to high-quality animated GIF using FFmpeg's two-pass palette optimization.
| Parameter | Default | Notes |
|---|---|---|
| FPS | 10 | Lower = smaller file, fewer frames |
| Width | 480 | Height auto-calculated to maintain aspect ratio |
- Uses
palettegen+paletteusefor optimal color quality - Bayer dithering for smooth gradients
- No audio (GIF format limitation)
android - Android-Compatible MP4
Produces H.264 Baseline profile video with AAC audio, guaranteed to play natively on all Android devices.
| Parameter | Default | Notes |
|---|---|---|
| CRF | 23 | Lower = better quality, larger file |
| Video codec | H.264 (Baseline) | Level 3.1, yuv420p pixel format |
| Audio codec | AAC | Stereo, 128 kbps |
- Hardware encoder auto-detected (NVENC > QSV > AMF > VAAPI > VideoToolbox > libx264)
- MP4 container with
faststartflag for streaming - Compatible with virtually all Android devices and web browsers
minsize - Minimum Size MP4
Aggressively compresses video for smallest possible file size while maintaining acceptable quality. Uses H.264 Baseline for maximum Android/device compatibility.
| Parameter | Default | Notes |
|---|---|---|
| CRF | 28 | Higher than android preset for more compression |
| Video codec | H.264 (Baseline) | Level 3.1, yuv420p pixel format |
| Audio codec | AAC | Mono, 64 kbps |
| Max height | 720p | Auto-downscales if source exceeds 720p |
- H.264 encoder chain: h264_nvenc > h264_qsv > h264_amf > h264_vaapi > h264_videotoolbox > libx264
- Mono audio at reduced bitrate for smaller output
- Ideal for archival, sharing on messaging apps, or limited storage
audio - Audio Extraction
Extracts the audio track from video files.
| Parameter | Default | Notes |
|---|---|---|
| Format | MP3 | Also supports AAC (use --audio-format aac) |
| Bitrate | 128 kbps | Good quality for speech and music |
- MP3 output uses libmp3lame encoder
- AAC output saved as
.m4acontainer
Hardware Acceleration
LaPian automatically detects available hardware encoders at startup and selects the best one. The detection order (highest priority first):
H.264 Encoder Chain
h264_nvenc(NVIDIA GPU)h264_qsv(Intel Quick Sync)h264_amf(AMD GPU)h264_vaapi(Linux VA-API)h264_videotoolbox(macOS)libx264(Software fallback)
Use --encoder <name> to force a specific encoder if auto-detection doesn't choose the one you want.
GUI Usage
- Launch:
lapian --gui(orpython lapian.pywith no arguments) - Click Add Files or Add Directory to queue videos
- Select a Preset from the dropdown
- Adjust options (CRF, FPS, width, etc.) as needed
- Set the Output Directory
- Click Start Transcoding
- Monitor progress in the progress bars and log area
- Click Cancel to stop the current batch
The GUI displays detected hardware encoders at startup and provides real-time logging of the transcoding process.
Supported Input Formats
MP4, MKV, AVI, MOV, WebM, FLV, WMV, TS, M4V, 3GP, MPG, MPEG, VOB, OGV, M2TS, MTS, F4V, RM, RMVB
Output Structure
Output files are placed in the output directory, preserving the original directory structure:
<output_dir>/<relative_subdir>/<original_name>_<preset>.<ext>
Examples:
transcoded/myvideo_android.mp4transcoded/subdir/clip_gif.giftranscoded/myvideo_minsize.mp4transcoded/myvideo_audio.mp3
Duplicate filenames are automatically resolved by appending _1, _2, etc.
Exit Codes (CLI)
| Code | Meaning |
|---|---|
| 0 | All jobs completed successfully |
| 1 | One or more jobs failed |
Python API
from lapian import transcode, batch_transcode, probe_video
# Probe video metadata
info = probe_video("input.mp4")
print(info.data) # duration, resolution, codecs, etc.
# Transcode a single file
result = transcode("input.mp4", preset="minsize")
print(result.data["output_path"])
# Batch transcode a directory
result = batch_transcode("./videos", preset="android")
print(result.metadata) # summary stats
Agent Integration (OpenAI Function Calling)
LaPian exposes OpenAI-compatible tools for LLM agents:
from lapian.tools import TOOLS, dispatch
# Pass TOOLS to the OpenAI chat completion API
response = client.chat.completions.create(
model="gpt-4o",
messages=messages,
tools=TOOLS,
)
# Dispatch the tool call
result = dispatch(
tool_call.function.name,
tool_call.function.arguments,
)
CLI Help
License
This project is licensed under GPL-3.0-or-later. See the LICENSE file for details.
Metadata
Release files for lapian 1.3.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| lapian-1.3.5.tar.gz | 52.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| lapian-1.3.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 99.3 kB
Release files / lapian-1.3.5.tar.gz
| Download URL | lapian-1.3.5.tar.gz |
|---|---|
| Size | 52.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
190edf65a9fcebf31a9e3dc278e60256eee25e544523055433916e81c3f25c5d
|
|
BLAKE2b-256 checksum How to use checksums |
ce54e7995126c4dc29a89395b9fb65ebf7bcac97a971c2ed09cf1188f599f6b6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Release files / lapian-1.3.5-py3-none-any.whl
| Download URL | lapian-1.3.5-py3-none-any.whl |
|---|---|
| Size | 46.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f48df67be7ece4006fe0786f964ccb36bdc3e06ae7d85b8e52a4c4f2f787fac3
|
|
BLAKE2b-256 checksum How to use checksums |
c22548b8a577bbbdafbebeb184d803358e706bf78e0e1d621fdc9bd63da9611e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Security for lapian 1.3.5
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.