Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot extract proper audio from video using pipes #507

Open
ruliworst opened this issue Mar 12, 2024 · 0 comments
Open

Cannot extract proper audio from video using pipes #507

ruliworst opened this issue Mar 12, 2024 · 0 comments

Comments

@ruliworst
Copy link

ruliworst commented Mar 12, 2024

Hi everyone!

I am trying to extract audio from video using pipes unsuccessfully. Here is the code:

... ExtractAudioFromVideoUsingPipes(byte[] video)
{
  MemoryStream videoStream = new MemoryStream(video);
  MemoryStream audioStream = new MemoryStream();
  
  StreamPipeSource input = new StreamPipeSource(videoStream);
  StreamPipeSink output = new StreamPipeSink(audioStream);
  
  FFMpegArguments
    .FromPipeInput(input)
    .OutputToPipe(output, options =>
    {
       options.DisableChannel(Channel.Video).ForceFormat("mp3");
    })
    .ProcessSynchronously();
  
    byte[] outputByteArray = new byte[audioStream.Length];
  
    audioStream.Position = 0;
    audioStream.Read(outputByteArray, 0, outputByteArray.Length);
  
  ...
}

That code produces a result but it is wrong. The resulting outputByteArray should have a length of approximately 223000, but a length of 148 is provided instead. However, if I use the original method, everything is fine:

public static bool ExtractAudio(string input, string output)
{
     FFMpegHelper.ExtensionExceptionCheck(output, FileExtension.Mp3);

      return FFMpegArguments
                .FromFileInput(input)
                .OutputToFile(output, true, options => options
                    .DisableChannel(Channel.Video))
                .ProcessSynchronously();
}

FFMpeg version used: 2022-10-24-git-d79c240196-full_build-www.gyan.dev.

Processing video and audio in memory is a requirement so, I cannot use file system. Has anyone had to deal with this before?

Any help is really appreciated. Thanks in advance.

@ruliworst ruliworst changed the title Cannot extract audio from video using pipes Cannot extract proper audio from video using pipes Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant