rosenbjerg / FFMpegCore

A .NET FFMpeg/FFProbe wrapper for easily integrating media analysis and conversion into your C# applications
MIT License
1.61k stars 289 forks source link

Audio conversion fails when writing to output pipe #318

Closed josago97 closed 2 years ago

josago97 commented 2 years ago

Hello,

I am trying to change the format of an audio that is obtained from a url to a Stream object. However, when executing the ffmpeg command it fails with the following error: "Error writing trailer of \.\pipe\FFMpegCore_d411987f-0e0a-4f82-b2de-2228f3b6a8de: Invalid argument".

The code I use is the following:


MemoryStream stream = new MemoryStream();

FFMpegArguments.FromUrlInput(new Uri("https://cadena100-cope.flumotion.com/playlist.m3u8"))
  .OutputToPipe(new StreamPipeSink(stream), options =>
  {
      options.WithAudioSamplingRate(48000)
      .WithCustomArgument("-loglevel debug -ac 2 -f wav");
  })
  .NotifyOnOutput((e, r) => Console.WriteLine($">>>>>> {e}"))
  .ProcessAsynchronously();
rosenbjerg commented 2 years ago

Please confirm that ffmpeg actually supports transcoding from a m3u8 source to a wav target. It is not possible to output to a stream if the transcoding requires seeking, since streams does not support that. Consider outputting to a file instead if that is the case.

Reopen this issue if you find that ffmpeg should support this use-case

josago97 commented 2 years ago

If instead of calling ffmpeg from the library I do it by creating a process, with the same arguments, it works.


string path = "https://cadena100-cope.flumotion.com/playlist.m3u8";

Process.Start(new ProcessStartInfo
  {
      FileName = "ffmpeg",
      Arguments = $"-i \"{path}\" -ac 2 -f wav -ar 48000 pipe:1",
      UseShellExecute = false,
      RedirectStandardOutput = true,
  });
rosenbjerg commented 2 years ago

To replicate that cli command with this wrapper library, you shouldn't use OutputToPipe(..), but instead OutputToUrl("pipe:1"). But that would make it quite hard to access the resulting data in this case.. Not sure what the best approach is for this

josago97 commented 2 years ago

Ok, so I think it's best to call ffmpeg directly through Process, thank you very much.