Clapshot supports customizable transcoding and thumbnailing through external scripts. This allows for hardware acceleration, custom encoders, and specialized processing workflows.
Clapshot includes default scripts for media processing that can be customized or replaced:
- clapshot-transcode-decision: Determines whether a media file needs transcoding
- clapshot-transcode: Converts media files to web-compatible formats
- clapshot-thumbnail: Generates poster thumbnails and thumbnail sheets
These scripts are invoked by the Clapshot Server during media ingestion and can be customized for specific hardware or encoding requirements.
The transcoding decision script evaluates whether a media file needs transcoding before the actual transcoding process begins. This allows you to:
- Customize which codecs and containers are considered web-compatible
- Implement site-specific policies for bitrate and quality requirements
- Skip transcoding for already-compatible formats to save processing time
The script receives media information via environment variables (media type, codec, container, bitrate) and outputs a JSON decision indicating whether transcoding is needed and at what bitrate.
By default, the script skips transcoding for browser-compatible formats (H.264, HEVC, VP8, VP9, AV1 in MP4/MKV/WebM containers) when the bitrate is acceptable.
The default transcoding script handles three media types:
- Video: Converts to H.264 MP4 with configurable bitrate, max 1080p resolution
- Audio: Generates waveform visualization videos for audio-only files
- Image: Creates short video loops from still images
The script automatically selects appropriate encoding parameters based on the media type and target bitrate specified by the server.
The thumbnailing script creates:
- Poster thumbnails: Single frame thumbnails
- Thumbnail sheets: Grid of frames distributed throughout the video for scrub preview
Thumbnails are generated only for appropriate media types (no thumbnails for audio files).
On low level, the custom scripts are set via command-line arguments to Clapshot Server:
clapshot-server --transcode-decision-script /path/to/custom-decision \
--transcode-script /path/to/custom-transcode \
--thumbnail-script /path/to/custom-thumbnailHowever,
- on Debian deployments, you'll want to edit
/etc/clapshot-server.confinstead, and - on Docker ones, use the
CLAPSHOT_SERVER__environment variables to set the corresponding variables.
These will both set those command line options under the hood. See Sysadmin Guide guide for more details.
The default transcoding script supports hardware FFMPEG acceleration. You can enable one through a configuration file:
# Edit /etc/clapshot-transcode.conf
VIDEO_CODEC=h264_nvenc # NVIDIA GPU encoding
HWACCEL=nvenc
VIDEO_FILTER_SCALE=scale_cudaSupported acceleration options:
- Intel Quick Sync Video (QSV):
h264_qsv - NVIDIA NVENC:
h264_nvenc - VA-API (Intel/AMD):
h264_vaapi - Apple VideoToolbox:
h264_videotoolbox
All scripts receive input from Server through environment variables:
CLAPSHOT_MEDIA_TYPE: Media type (video,audio, orimage)CLAPSHOT_ORIG_CODEC: Original codec (e.g.,h264,vp9)CLAPSHOT_CONTAINER: Container extension (e.g.,mp4,mkv)CLAPSHOT_BITRATE: Original bitrate in bits per secondCLAPSHOT_TARGET_BITRATE: Server's target max bitrateCLAPSHOT_DURATION: Duration in secondsCLAPSHOT_INPUT_FILE: Path to source fileCLAPSHOT_METADATA_JSON: Full mediainfo JSON output (for advanced decisions)
The decision script must output JSON to stdout:
{"transcode": true, "reason": "codec not supported", "bitrate": 2500000}
{"transcode": false}CLAPSHOT_INPUT_FILE: Path to source media fileCLAPSHOT_OUTPUT_DIR: Directory for output filesCLAPSHOT_MEDIA_TYPE: Media type (video,audio, orimage)CLAPSHOT_USER_ID: User identifier for loggingCLAPSHOT_MEDIA_ID: Media file identifierCLAPSHOT_DURATION: Media duration in seconds
CLAPSHOT_OUTPUT_PREFIX: Filename prefix for outputCLAPSHOT_TARGET_BITRATE: Target bitrate in bits per secondCLAPSHOT_PROGRESS_PIPE: Named pipe for progress reporting (optional)
CLAPSHOT_THUMB_SIZE: Thumbnail dimensions (e.g.,160x90)CLAPSHOT_SHEET_DIMS: Sheet grid dimensions (e.g.,10x10)
See the default scripts on how these are used with FFMPEG.
Transcoding scripts can (should) report progress by writing to CLAPSHOT_PROGRESS_PIPE:
# FFmpeg-style progress format
frame=584
fps=52.40
speed=2.1x
progress=continue
# Final completion
progress=endThis will cause Client to show a progress bar to the user.
Scripts should exit with status 0 for success, non-zero for failure. The server captures stdout/stderr for logging and troubleshooting.
Script execution outputs are written to dedicated log files:
- Transcoding logs:
<media-dir>/<media-id>/transcode.log - Thumbnailing logs:
<media-dir>/<media-id>/thumbs/thumbnail.log - Server logs: Check for log file locations when processing fails
- Use
--log-level debugfor detailed execution information - Test scripts manually with environment variables set
Log files contain timestamps, command details, exit status, and complete stdout/stderr output from the scripts.
- Architecture Overview: Overall system design
- Sysadmin Guide: Server configuration and deployment
- Development Setup: Building and testing custom scripts