[英]How to convert from .h264 to .ts using FFmpeg wrapper for C#/.NET?
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
.我在我的 .NET Core API 项目中使用FFMpegCore接收一个.h264
文件(以二进制格式发送,接收并转换为byte array
)转换为.ts
。
I want to convert a .h264
stream into a .ts
output stream using FFmpeg.我想使用 FFmpeg 将.h264
stream 转换为.ts
output stream。
(...)
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.我没有得到一个有效的.ts
文件。 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.即使您有其他 FFmpeg 包装器,您认为更适合解决此问题。
.h264
to .ts
(using files): ffmpeg -i file.h264 -an -vcodec copy -f mpegts output.ts
FFmpeg 命令用于测试从.h264
到.ts
的转换(使用文件): ffmpeg -i file.h264 -an -vcodec copy -f mpegts output.ts
Missing the following argument: .WithVideoCodec( "h264" )
on FFMpegArguments
.缺少以下参数:FFMpegArguments 上的FFMpegArguments
.WithVideoCodec( "h264" )
。
(...)
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() );
(...)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.