如何使用 C#/.NET 的 FFmpeg 包装器从 .h264 转换为 .ts?

How to convert from .h264 to .ts using FFmpeg wrapper for C#/.NET?

上下文

我在我的 .NET Core API 项目中使用 FFMpegCore 接收 .h264 文件(以二进制格式发送,接收并转换为 byte array) 转换为 .ts.

我想使用 FFmpeg 将 .h264 流转换为 .ts 输出流。

当前方法

(...)

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() );

(...)

问题

我没有得到有效的 .ts 文件。我做错了什么?你能给我一些提示或帮助我吗?即使您有其他您认为更适合解决此问题的 FFmpeg 包装器。

备注:

缺少以下参数:.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() );

(...)