【问题标题】:Convert mp4 or Avi to m3u8 in pure node js在纯节点 js 中将 mp4 或 Avi 转换为 m3u8
【发布时间】:2020-07-21 07:44:02
【问题描述】:

我正在寻找一种在纯节点 js(firebase 云功能)中将 mp4 或 .avi 转换为 .m3u8 的方法。你有什么想法吗?

谢谢,但我试过了:

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); 

我有这个错误:

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

有什么想法吗?

提前致谢。

杰里米。

【问题讨论】:

  • 我不认为纯 nodejs 可以做到这一点...... FFmpeg 可以,但这可能不适用于 firebase 云功能......

标签: javascript node.js google-cloud-functions mp4 m3u8


【解决方案1】:

找到这个答案:https://stackoverflow.com/a/42777596/8006046。它展示了如何在 firebase 云中运行 FFmpeg。您可以将'path_or_readstream.mp4' 替换为您要转换的文件的路径,或者,在云函数中更可能的是,您可以将可读流与您要转换的文件一起传递。

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');

【讨论】:

  • @JérémyGachon 您使用的包与此答案使用的包不同。
  • 我只尝试了 fluent-ffmpeg 和 ffmpeg-static,但出现了这个错误。我在堆栈 oveflow 上搜索,有人说要添加 ffmpegInstaller 来设置 ffmpeg 路径。但总是有错误。
猜你喜欢
  • 1970-01-01
  • 2018-12-05
  • 2014-11-04
  • 2016-01-11
  • 2014-07-12
  • 1970-01-01
  • 2022-12-18
  • 2014-11-09
  • 2015-06-14
相关资源
最近更新 更多