简体   繁体   English

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

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

I'm extracting audio from a video using ffmeg-fluent library我正在使用ffmeg-fluent库从视频中提取音频

Actually when I save the audio in local it works.实际上,当我将音频保存在本地时,它就可以工作了。 I get an audio file with data.我得到一个带有数据的音频文件。

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

But when I try to convert the video stream to audio stream in order to save the file in my azure blob storage I get an empty file with 0 octet size.但是当我尝试将视频 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);
  • Here I have a work around were, instead of using the fluent-ffmpeg to pipe the data in the stream, we can store the audio to a file and read the file as stream and then upload it.这里我有一个变通办法,不是使用fluent-ffmpeg来 pipe stream 中的数据,我们可以将音频存储到一个文件中并读取文件 stream 然后上传它。

  • here, I am writing the audio data to a novideo.mp3 file and then uploading the file as a stream.在这里,我将音频数据写入novideo.mp3文件,然后将文件上传为 stream。

code:代码:

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

output: output:在此处输入图像描述

  • Also, if you want to use the pipe() function then I think you have to pass a writable stream to the function along with option.此外,如果您想使用pipe() function,那么我认为您必须将可写的 stream 连同选项一起传递给 function。 refer these NPM- DOCS for it请参考这些NPM-DOCS

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

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