简体   繁体   English

在纯节点 js 中将 mp4 或 Avi 转换为 m3u8

[英]Convert mp4 or Avi to m3u8 in pure node js

I am searching a way to convert a mp4 or an.avi to.m3u8 in pure node js (firebase cloud function).我正在寻找一种在纯节点 js(firebase 云功能)中将 mp4 或 an.avi 转换为.m3u8 的方法。 Do you have ideas?你有想法吗?

Thank's, but I tried that:谢谢,但我试过了:

const ffmpegInstaller = require('@ffmpeg-installer/ffmpeg');
const ffmpeg = require('fluent-ffmpeg');
ffmpeg.setFfmpegPath(ffmpegInstaller.path);
const ffmpeg_static = require('ffmpeg-static');
var cmd = ffmpeg('./flir_20191202T174341.mp4')
    .setFfmpegPath(ffmpeg_static.path)
    .videoBitrate(1024)
    .videoCodec('divx')
    .format('m3u8')
    .on('end', () => {
        // ...
    })
    .on('error', err => {
        console.error(err);
    })
    .save('./file-out.m3u8');
console.log('Hello !');
console.log(cmd); 

And I have this error:我有这个错误:

Error: Cannot find ffmpeg
at /Users/jeremy/Dev/ssv-api/node_modules/fluent-ffmpeg/lib/processor.js:136:22
at FfmpegCommand.proto._getFfmpegPath (/Users/jeremy/Dev/ssv-api/node_modules/fluent-ffmpeg/lib/capabilities.js:90:14)
at FfmpegCommand.proto._spawnFfmpeg (/Users/jeremy/Dev/ssv-api/node_modules/fluent-ffmpeg/lib/processor.js:132:10)
at FfmpegCommand.proto.availableFormats.proto.getAvailableFormats (/Users/jeremy/Dev/ssv-api/node_modules/fluent-ffmpeg/lib/capabilities.js:517:10)
at /Users/jeremy/Dev/ssv-api/node_modules/fluent-ffmpeg/lib/capabilities.js:568:14
at nextTask (/Users/jeremy/Dev/ssv-api/node_modules/async/dist/async.js:4576:27)
at Object.waterfall (/Users/jeremy/Dev/ssv-api/node_modules/async/dist/async.js:4587:9)
at Object.awaitable [as waterfall] (/Users/jeremy/Dev/ssv-api/node_modules/async/dist/async.js:208:32)
at FfmpegCommand.proto._checkCapabilities (/Users/jeremy/Dev/ssv-api/node_modules/fluent-ffmpeg/lib/capabilities.js:565:11)
at /Users/jeremy/Dev/ssv-api/node_modules/fluent-ffmpeg/lib/processor.js:298:14

Any ideas?有任何想法吗?

Thanks in advance.提前致谢。

Jérémy.杰里米。

Found this answer: https://stackoverflow.com/a/42777596/8006046 .找到了这个答案: https://stackoverflow.com/a/42777596/8006046 It shows how you can run FFmpeg in the firebase cloud.它展示了如何在 firebase 云中运行 FFmpeg。 You can replace 'path_or_readstream.mp4' with either the path to the file you want to convert, or, which is more probable in a cloud function, you could pass the readable stream with the file you want to convert.您可以将'path_or_readstream.mp4'替换为要转换的文件的路径,或者,在云 function 中更可能的是,您可以将可读的 stream 与要转换的文件一起传递。

const ffmpeg = require('fluent-ffmpeg');
const ffmpeg_static = require('ffmpeg-static');

var cmd = ffmpeg('path_or_readstream.mp4')
  .setFfmpegPath(ffmpeg_static.path)
  .videoBitrate(1024)
  .videoCodec('divx')
  .format('m3u8')
  .on('end', () => {
    // ...
  })
  .on('error', err => {
    console.error(err);
  })
  .save('/tmp/file-out.m3u8');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM