I'm using FFMpegCore in my .NET Core API project that receives a .h264
file (sent in a binary format that is received and converted into a byte array
) to be converted to a .ts
.
I want to convert a .h264
stream into a .ts
output stream using FFmpeg.
(...)
byte[] body;
using ( var ms = new MemoryStream() )
{
await request.Body.CopyToAsync( ms ); // read sent .h264 data
body = ms.ToArray();
}
var outputStream = new MemoryStream();
// FFMpegCore
await FFMpegArguments
.FromPipeInput( new StreamPipeSource( new MemoryStream( body ) ) )
.OutputToPipe( new StreamPipeSink( outputStream ), options => options
.ForceFormat( VideoType.MpegTs ) )
.ProcessAsynchronously();
// view converted ts file
await File.WriteAllBytesAsync( "output.ts", outputStream.ToArray() );
(...)
I'm not getting a working .ts
file. What I'm a doing wrong? Could you please give some hint or help me with this? Even if you have other FFmpeg wrappers that you consider more suitable for this problem.
.h264
to .ts
(using files): ffmpeg -i file.h264 -an -vcodec copy -f mpegts output.ts
Missing the following argument: .WithVideoCodec( "h264" )
on FFMpegArguments
.
(...)
byte[] body;
using ( var ms = new MemoryStream() )
{
await request.Body.CopyToAsync( ms ); // read sent .h264 data
body = ms.ToArray();
}
var outputStream = new MemoryStream();
// FFMpegCore
await FFMpegArguments
.FromPipeInput( new StreamPipeSource( new MemoryStream( body ) ) )
.OutputToPipe( new StreamPipeSink( outputStream ), options => options
.WithVideoCodec( "h264" ) // added this argument
.ForceFormat( "mpegts" ) ) // or VideoType.MpegTs
.ProcessAsynchronously();
// view converted ts file
await File.WriteAllBytesAsync( "output.ts", outputStream.ToArray() );
(...)