FFMpegCore icon indicating copy to clipboard operation
FFMpegCore copied to clipboard

Sample for Input/Output from Stream?

Open jjouppi opened this issue 6 years ago • 6 comments

Hey All!

Thanks for this awesome repository. I was messing around with having an input/output from stream and noticed the example in the ReadMe seems to be depreciated? That is, there is no instance of "StreamPipeDataWriter" or "StreamPipeDataReader" within FFMpegCore. Were those replaced with "StreamPipeSource" and "StreamPipeSink"? Does anyone have a sample on hand that demonstrates how reading from and writing to streams works now?

Here's what I have currently for reading from a stream and outputting to a stream:

            Stream inputFile = await file.OpenStreamForReadAsync();
            Stream outputFile = await saveLocation.OpenStreamForWriteAsync();


                FFMpegArguments
                    .FromPipe(new StreamPipeSource(inputFile))
                    .WithVideoCodec(VideoCodec.LibX264)
                    .ForcePixelFormat("yuv420p")
                    .WithAudioCodec(AudioCodec.Aac)
                    .Scale(VideoSize.Hd)
                    .OutputToPipe(new StreamPipeSink(outputFile))
                    .ProcessSynchronously();

Is this correct? Appreciate any help!

jjouppi avatar Aug 16 '20 16:08 jjouppi

Yes, you are right the readme is outdated, and indeed those classes have been renamed to avoid some confusion. It looks like what you have is correct. We do have a unit test that seems to do something very similar, so that might be a useable sample also. But if you are inputting a file, I'd recommend using .FromInputFiles instead of .FromPipe, since that avoids having to write everything through a named pipe, thus potentially performing a bit better.

rosenbjerg avatar Aug 17 '20 21:08 rosenbjerg

I have a similar scenario - I'd like to take a video byte stream (from the network, i.e. not a file), and then read the frames one by one and run some processing on them (i.e. no need to persist the stream). How can that be done?

tom-r-o avatar Aug 27 '20 12:08 tom-r-o

@max619 Seems like the reverse of your example. Have you tried something like this?

rosenbjerg avatar Aug 27 '20 14:08 rosenbjerg

Hi, i have not tried anything like this, but i think it is possible if you transcode video to raw_video and read input data directly to bitmaps. Take a look how bitmaps writing works and try to do it reverse

max619 avatar Aug 30 '20 15:08 max619

I have a similar scenario - I'd like to take a video byte stream (from the network, i.e. not a file), and then read the frames one by one and run some processing on them (i.e. no need to persist the stream). How can that be done?

Too much people need this. I guess the readme file should be updated asap

thatwickguy avatar Sep 03 '20 16:09 thatwickguy

Readme has been updated to version 3

rosenbjerg avatar Nov 09 '20 19:11 rosenbjerg