FFMpegCore: (StreamPipeSink) Pipe is broken
Hello,
I am experiencing an issue where I cannot get the StreamPipeSink to work.
Stream input = File.OpenRead("video.ts"); // Will get it from an online source
StreamPipeSource pipeSource = new StreamPipeSource(input);
var output = new MemoryStream();
StreamPipeSink pipeSink = new StreamPipeSink(output);
//Exctract audio to a MemoryStream --> byte[ ]
FFMpegArguments
.FromPipeInput(pipeSource)
.OutputToPipe(pipeSink, options => options.WithCustomArgument("-acodec pcm_s16le -osr 16000 -ocl mono"))
.ProcessSynchronously();
This results in an error:
Pipe is broken.
at FFMpegCore.Arguments.InputPipeArgument.ProcessDataAsync(CancellationToken token) in C:\dev\FFMpegCore\FFMpegCore\FFMpeg\Arguments\InputPipeArgument.cs:line 27
at FFMpegCore.Arguments.PipeArgument.During(CancellationToken cancellationToken) in C:\dev\FFMpegCore\FFMpegCore\FFMpeg\Arguments\PipeArgument.cs:line 41
at FFMpegCore.FFMpegArguments.During(CancellationToken cancellationToken) in C:\dev\FFMpegCore\FFMpegCore\FFMpeg\FFMpegArguments.cs:line 73
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.WaitAllCore(Task[] tasks, Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.WaitAll(Task[] tasks)
at FFMpegCore.FFMpegArgumentProcessor.ProcessSynchronously(Boolean throwOnError) in C:\dev\FFMpegCore\FFMpegCore\FFMpeg\FFMpegArgumentProcessor.cs:line 64
--- End of inner exception stack trace ---
at FFMpegCore.FFMpegArgumentProcessor.HandleException(Boolean throwOnError, Exception e, IReadOnlyList`1 errorData) in C:\dev\FFMpegCore\FFMpegCore\FFMpeg\FFMpegArgumentProcessor.cs:line 150
at FFMpegCore.FFMpegArgumentProcessor.ProcessSynchronously(Boolean throwOnError) in C:\dev\FFMpegCore\FFMpegCore\FFMpeg\FFMpegArgumentProcessor.cs:line 73
My own throughts:
I have been digging around a bit.
The FFMpegArgumentProcessor.ProcessSynchronously(...) calls the cancellationTokenSource.Cancel() before the OutputPipeArgument.ProcessDataAsync(...) is finished, means no data have been read.
try
{
_ffMpegArguments.Pre();
await Task.WhenAll(instance.FinishedRunning().ContinueWith(t =>
{
errorCode = t.Result;
cancellationTokenSource.Cancel();
_ffMpegArguments.Post();
}), _ffMpegArguments.During(cancellationTokenSource.Token)).ConfigureAwait(false);
}
And it the PipeArgument.Post() is called before the OutputPipeArgument.ProcessDataAsync(...) is finished too (due to the async nature of async). Even through cancellationTokenSource.Cancel(); have been called
Due to PipeArgument.Post() does:
public void Post()
{
Pipe?.Dispose();
Pipe = null!;
}
Means the pipe is null.
The last thing PipeArgument.During(...) does is calling:
Pipe.Disconnect();
But at this point the pipe is already null, hence the error.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 28 (11 by maintainers)
To fix this error, you need to add .ForceFormat(“wav”), which gives ffmpeg
-f wav. ffmpeg normally uses the extension of the output file path to determine the format. When outputting to a stream, that is not possible and that will almost always require it to be specified.FFMpegCore does not use StandardInput.BaseStream to “pass along” the input stream. Instead it uses NamedPipeServerStream, which btw uses unix sockets on non-Windows machines
@renanrcp could you try using version 3.2.2 or newer?
@renanrcp I was able to fix PipeBroken1Async and PipeBroken2Async just by adding .ForceFormat(“opus”) and .ForceForce(“mp3”). I’m looking into PipeBroken3Async since that one gives a null ref exception after adding ForceFormat(“raw”) to input and ForceFormat(“opus”) to output
A temporary solution is use -f instead -acoded
Example:
to
I do this repo with 3 broken pipes example and one working (just decoding, if you try encoding will broke)