1
- import type { Codec , CodecOrUndefined } from '@remotion/renderer' ;
1
+ import type { Codec , CodecOrUndefined , FileExtension } from '@remotion/renderer' ;
2
2
import { RenderInternals } from '@remotion/renderer' ;
3
3
4
- const fileExtensions : Record < string , Codec [ ] > = {
5
- webm : [ 'vp8' , 'vp9' ] ,
6
- hevc : [ 'h265' ] ,
7
- mp3 : [ 'mp3' ] ,
8
- mov : [ 'prores' ] ,
9
- wav : [ 'wav' ] ,
10
- aac : [ 'aac' ] ,
11
- mkv : [ 'h264-mkv' ] ,
12
- gif : [ 'gif' ] ,
13
- mp4 : [ 'h264' ] ,
14
- m4a : [ 'aac' ] ,
15
- } ;
16
-
17
- const deriveExtensionFromFilename = ( extension : string | null ) => {
4
+ const deriveCodecsFromFilename = (
5
+ extension : string | null
6
+ ) : {
7
+ possible : Codec [ ] ;
8
+ default : Codec | null ;
9
+ } => {
18
10
if ( extension === null ) {
19
- return [ ] ;
11
+ return { possible : [ ] , default : null } ;
20
12
}
21
13
22
- return fileExtensions [ extension ] ?? [ ] ;
14
+ return {
15
+ default :
16
+ RenderInternals . defaultCodecsForFileExtension [
17
+ extension as FileExtension
18
+ ] ?? null ,
19
+ possible : RenderInternals . makeFileExtensionMap ( ) [ extension ] ?? [ ] ,
20
+ } ;
23
21
} ;
24
22
25
23
export const getFinalOutputCodec = ( {
@@ -37,15 +35,14 @@ export const getFinalOutputCodec = ({
37
35
RenderInternals . getExtensionOfFilename ( downloadName ) ;
38
36
const outNameExtension = RenderInternals . getExtensionOfFilename ( outName ) ;
39
37
40
- const derivedDownloadCodecs = deriveExtensionFromFilename (
41
- downloadNameExtension
42
- ) ;
43
- const derivedOutNameCodecs = deriveExtensionFromFilename ( outNameExtension ) ;
38
+ const derivedDownloadCodecs = deriveCodecsFromFilename ( downloadNameExtension ) ;
39
+ const derivedOutNameCodecs = deriveCodecsFromFilename ( outNameExtension ) ;
44
40
45
41
if (
46
- derivedDownloadCodecs . length > 0 &&
47
- derivedOutNameCodecs . length > 0 &&
48
- derivedDownloadCodecs . join ( '' ) !== derivedOutNameCodecs . join ( '' )
42
+ derivedDownloadCodecs . possible . length > 0 &&
43
+ derivedOutNameCodecs . possible . length > 0 &&
44
+ derivedDownloadCodecs . possible . join ( '' ) !==
45
+ derivedOutNameCodecs . possible . join ( '' )
49
46
) {
50
47
throw new TypeError (
51
48
`The download name is ${ downloadName } but the output name is ${ outName } . The file extensions must match`
@@ -54,22 +51,22 @@ export const getFinalOutputCodec = ({
54
51
55
52
if ( cliFlag ) {
56
53
if (
57
- derivedDownloadCodecs . length > 0 &&
58
- derivedDownloadCodecs . indexOf ( cliFlag ) === - 1
54
+ derivedDownloadCodecs . possible . length > 0 &&
55
+ derivedDownloadCodecs . possible . indexOf ( cliFlag ) === - 1
59
56
) {
60
57
throw new TypeError (
61
- `The download name is ${ downloadName } but --codec=${ cliFlag } was passed. The download name implies a codec of ${ derivedDownloadCodecs . join (
58
+ `The download name is ${ downloadName } but --codec=${ cliFlag } was passed. The download name implies a codec of ${ derivedDownloadCodecs . possible . join (
62
59
' or '
63
60
) } which does not align with the --codec flag.`
64
61
) ;
65
62
}
66
63
67
64
if (
68
- derivedOutNameCodecs . length > 0 &&
69
- derivedOutNameCodecs . indexOf ( cliFlag ) === - 1
65
+ derivedOutNameCodecs . possible . length > 0 &&
66
+ derivedOutNameCodecs . possible . indexOf ( cliFlag ) === - 1
70
67
) {
71
68
throw new TypeError (
72
- `The out name is ${ outName } but --codec=${ cliFlag } was passed. The out name implies a codec of ${ derivedOutNameCodecs . join (
69
+ `The out name is ${ outName } but --codec=${ cliFlag } was passed. The out name implies a codec of ${ derivedOutNameCodecs . possible . join (
73
70
' or '
74
71
) } which does not align with the --codec flag.`
75
72
) ;
@@ -78,16 +75,16 @@ export const getFinalOutputCodec = ({
78
75
return { codec : cliFlag , reason : 'from --codec flag' } ;
79
76
}
80
77
81
- if ( derivedDownloadCodecs . length > 0 ) {
78
+ if ( derivedDownloadCodecs . possible . length > 0 ) {
82
79
return {
83
- codec : derivedDownloadCodecs [ 0 ] ,
80
+ codec : derivedDownloadCodecs . default as Codec ,
84
81
reason : 'derived from download name' ,
85
82
} ;
86
83
}
87
84
88
- if ( derivedOutNameCodecs . length > 0 ) {
85
+ if ( derivedOutNameCodecs . possible . length > 0 ) {
89
86
return {
90
- codec : derivedOutNameCodecs [ 0 ] ,
87
+ codec : derivedOutNameCodecs . default as Codec ,
91
88
reason : 'derived from out name' ,
92
89
} ;
93
90
}
0 commit comments