11import { BuildExtension } from "@trigger.dev/core/v3/build" ;
22
33export type FfmpegOptions = {
4+ /**
5+ * The version of ffmpeg to install. If not provided, the latest version from apt will be installed.
6+ * If set to '7' or starts with '7.', a static build of ffmpeg 7.x from johnvansickle.com will be used instead of apt.
7+ * @example
8+ * ffmpeg() // Installs latest ffmpeg from apt
9+ * ffmpeg({ version: '7' }) // Installs static build of ffmpeg 7.x
10+ * ffmpeg({ version: '7.0.1' }) // Installs static build of ffmpeg 7.x
11+ * ffmpeg({ version: '6' }) // Version ignored, installs latest ffmpeg from apt
12+ * ffmpeg({ version: '8' }) // Version ignored, installs latest ffmpeg from apt
13+ */
414 version ?: string ;
515} ;
616
717/**
818 * Add ffmpeg to the build, and automatically set the FFMPEG_PATH and FFPROBE_PATH environment variables.
9- * @param options.version The version of ffmpeg to install. If not provided, the latest version will be installed.
19+ * @param options.version The version of ffmpeg to install. If not provided, the latest version from apt will be installed.
20+ * If set to '7' or starts with '7.', a static build of ffmpeg 7.x from johnvansickle.com will be used instead of apt.
1021 *
1122 * @returns The build extension.
1223 */
@@ -22,10 +33,36 @@ export function ffmpeg(options: FfmpegOptions = {}): BuildExtension {
2233 options,
2334 } ) ;
2435
36+ // Use static build for version 7 or 7.x
37+ if ( options . version === "7" || options . version ?. startsWith ( "7." ) ) {
38+ context . addLayer ( {
39+ id : "ffmpeg7" ,
40+ image : {
41+ instructions : [
42+ "RUN apt-get update && apt-get install -y --no-install-recommends wget xz-utils && apt-get clean && rm -rf /var/lib/apt/lists/*" ,
43+ "RUN wget https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz -O ffmpeg.tar.xz && tar xvf ffmpeg.tar.xz -C /usr/bin --strip-components=1 --no-anchored 'ffmpeg' 'ffprobe' && rm ffmpeg.tar.xz" ,
44+ ] ,
45+ } ,
46+ deploy : {
47+ env : {
48+ FFMPEG_PATH : "/usr/bin/ffmpeg" ,
49+ FFPROBE_PATH : "/usr/bin/ffprobe" ,
50+ } ,
51+ override : true ,
52+ } ,
53+ } ) ;
54+ return ;
55+ } else if ( options . version ) {
56+ context . logger . warn ( "Custom ffmpeg version not supported, ignoring" , {
57+ version : options . version ,
58+ } ) ;
59+ }
60+
61+ // Default: use apt
2562 context . addLayer ( {
2663 id : "ffmpeg" ,
2764 image : {
28- pkgs : options . version ? [ `ffmpeg= ${ options . version } ` ] : [ "ffmpeg" ] ,
65+ pkgs : [ "ffmpeg" ] ,
2966 } ,
3067 deploy : {
3168 env : {
0 commit comments