新增编码器选择

This commit is contained in:
CN-JS-HuiBai
2026-04-02 17:40:06 +08:00
parent 47de5ac65b
commit eb6068cbb8
4 changed files with 55 additions and 7 deletions

View File

@@ -65,14 +65,20 @@ app.get('/api/videos', async (req, res) => {
// Endpoint to transcode S3 video streaming to HLS
app.post('/api/transcode', async (req, res) => {
const { key, codec } = req.body;
const { key, codec, encoder } = req.body;
if (!key) {
return res.status(400).json({ error: 'Video key is required' });
}
const safeCodec = codec === 'h265' ? 'h265' : 'h264';
const videoCodec = safeCodec === 'h265' ? 'libx265' : 'libx264';
const safeEncoder = ['nvidia', 'intel'].includes(encoder) ? encoder : 'software';
const codecMap = {
software: { h264: 'libx264', h265: 'libx265' },
nvidia: { h264: 'h264_nvenc', h265: 'hevc_nvenc' },
intel: { h264: 'h264_qsv', h265: 'hevc_qsv' }
};
const videoCodec = codecMap[safeEncoder][safeCodec];
try {
const safeKeySegments = key.split('/').map(segment => segment.replace(/[^a-zA-Z0-9_\-]/g, '_'));