You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:如何将FFmpeg桌面RTSP推流命令转为.NET FFMpegWrapper参数?

问题解决:将FFmpeg桌面推流命令转换为.NET FFMpegConverter适配代码

问题背景

原本通过FFmpeg命令行可正常将桌面画面推流至RTSP服务器:

ffmpeg -f gdigrab -rtbufsize 100M -framerate 30 -probesize 10M -draw_mouse 1 -i desktop -c:v libx264 -r 30 -preset ultrafast -tune zerolatency -crf 25 -f rtsp -rtsp_transport tcp rtsp://1.1.1.1:8554/player/1ef8d9a5-b0b3-4dab-93a0-ac2bdef2f8aa/index.m3u8

但使用.NET的FFMpegConverter.ConvertLiveMedia方法时,因参数配置逻辑错误报错(提示输入需为流、desktop无效),需调整参数适配包装器的输入输出分离逻辑。

错误原因分析

原代码核心问题:

  • 将**所有命令行参数(含输入配置)**全部塞到CustomOutputArgs中,混淆了输入/输出参数的边界
  • 直接将inPath设为"desktop",但包装器无法自动识别这是gdigrab设备输入,需配合输入格式声明
  • 错误指定输出格式为Format.flv,实际应为RTSP格式

修正后的代码

Dim rtspUrl As String = "rtsp://1.1.1.1:8554/player/1ef8d9a5-b0b3-4dab-93a0-ac2bdef2f8aa/index.m3u8"
Dim videoConv = New FFMpegConverter()

' 配置转换参数
Dim convertSettings As New ConvertSettings() With {
    ' 对应命令行的输入参数部分:-rtbufsize 100M -framerate 30 -probesize 10M -draw_mouse 1
    .CustomInputArgs = "-rtbufsize 100M -framerate 30 -probesize 10M -draw_mouse 1",
    ' 对应命令行的输出编码及RTSP传输参数
    .CustomOutputArgs = "-c:v libx264 -r 30 -preset ultrafast -tune zerolatency -crf 25 -rtsp_transport tcp",
    .VideoFrameRate = 30,
    .MaxDuration = 5
}

' 调用ConvertLiveMedia:明确输入格式为gdigrab,输入源为desktop,输出格式为rtsp
Dim ffMpegTask = videoConv.ConvertLiveMedia(
    inputPath:="desktop",
    inputFormat:="gdigrab",
    outputPath:=rtspUrl,
    outputFormat:="rtsp",
    settings:=convertSettings
)

ffMpegTask.Start()

参数对应说明

原命令行参数包装器配置方式
-f gdigrab作为ConvertLiveMedia的inputFormat参数传入
-i desktop作为ConvertLiveMedia的inputPath参数传入
-rtbufsize 100M -framerate 30 -probesize 10M -draw_mouse 1放入CustomInputArgs
-c:v libx264 -r 30 -preset ultrafast -tune zerolatency -crf 25放入CustomOutputArgs
-f rtsp -rtsp_transport tcp-f rtsp作为outputFormat参数,-rtsp_transport tcp放入CustomOutputArgs

内容的提问来源于stack exchange,提问作者Luiz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 13:05:33