繁体   English   中英

将视频 stream 转换为音频 stream 无效

[英]converting a video stream to an audio stream not working

我正在使用ffmeg-fluent库从视频中提取音频

实际上,当我将音频保存在本地时,它就可以工作了。 我得到一个带有数据的音频文件。

ffmpeg(recordedVideoStrm)
  .outputOptions([
    "-vn", // Discard the video
    "-acodec pcm_s16le", // Set the audio codec
    "-ar 44100", // Set the audio sample rate
    "-ac 2", // Set the number of audio channels
  ])
  .output("mp3")
  .on("error", function (err) {
    console.log("An error occurred: " + err.message);
  })
  .on("end", function () {
    console.log("Audio extraction completed");
  })
  .save("output.wav");

但是当我尝试将视频 stream 转换为音频 stream 以便将文件保存在我的 azure blob 存储中时,我得到一个八位字节大小为 0 的空文件。

const audioStream = ffmpeg(recordedVideoStrm)
  .outputOptions([
    "-vn", // Discard the video
    "-acodec pcm_s16le", // Set the audio codec
    "-ar 44100", // Set the audio sample rate
    "-ac 2", // Set the number of audio channels
  ])
  .on("error", function (err) {
    console.log("An error occurred: " + err.message);
  })
  .on("end", function () {
    console.log("Audio extraction completed");
  })
  .pipe(); 

const stream = await blobClient.uploadStream(audioStream);
  • 这里我有一个变通办法,不是使用fluent-ffmpeg来 pipe stream 中的数据,我们可以将音频存储到一个文件中并读取文件 stream 然后上传它。

  • 在这里,我将音频数据写入novideo.mp3文件,然后将文件上传为 stream。

代码:

var  writeStream = Stream.Writable();
ffmpeg({source:'newtest.mp4'})
    .noVideo()
    .saveToFile("novideo.mp4");
writeStream = fs.createReadStream('novideo.mp4');
await  blockblobclient.uploadStream(writeStream);

output:在此处输入图像描述

  • 此外,如果您想使用pipe() function,那么我认为您必须将可写的 stream 连同选项一起传递给 function。 请参考这些NPM-DOCS

暂无
暂无

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

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