(config: AudioEncoderConfig)
| 115 | } |
| 116 | |
| 117 | private static createCodecContext(config: AudioEncoderConfig) { |
| 118 | const inferred = inferCodecFromCodecString(config.codec); |
| 119 | if (!inferred) { |
| 120 | return null; |
| 121 | } |
| 122 | |
| 123 | const codec = Codec.findEncoder(inferred); |
| 124 | if (!codec) { |
| 125 | return null; |
| 126 | } |
| 127 | |
| 128 | let sampleFormat = AV_SAMPLE_FMT_FLTP; |
| 129 | if (codec.sampleFormats && !codec.sampleFormats.includes(AV_SAMPLE_FMT_FLTP)) { |
| 130 | sampleFormat = codec.sampleFormats[0]; |
| 131 | } |
| 132 | |
| 133 | const codecContext = new CodecContext(); |
| 134 | codecContext.allocContext3(codec); |
| 135 | |
| 136 | codecContext.sampleRate = config.sampleRate; |
| 137 | codecContext.channelLayout = getChannelLayout(config.numberOfChannels); |
| 138 | codecContext.codecType = AVMEDIA_TYPE_AUDIO; |
| 139 | codecContext.codecId = inferred; |
| 140 | codecContext.sampleFormat = sampleFormat; |
| 141 | codecContext.timeBase = new Rational(1, 1e6); |
| 142 | codecContext.bitRate = BigInt(config.bitrate ?? getDecentAudioBitrate(inferred)); |
| 143 | |
| 144 | if (config.bitrateMode === 'constant') { |
| 145 | codecContext.rcMinRate = codecContext.bitRate; |
| 146 | codecContext.rcMaxRate = codecContext.bitRate; |
| 147 | } |
| 148 | |
| 149 | return { codecContext, sampleFormat }; |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Checks if the encoder can support the given configuration. |
no test coverage detected