C#程序调用ffmpeg

using System;
using System.Diagnostics;

namespace sendffmpeg
{
class Program
{
static void Main(string[] args)
{
int returnValue;
try
{
args = Environment.GetCommandLineArgs();
String ip = args[1];
String streamName = args[2];
//Console.ReadKey();

//string strExePath = "E:/工具/ffmpeg/ffmpeg.exe";
string strExePath = "ffmpeg.exe";
//string param = "-re -f gdigrab -i desktop -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -f flv -pix_fmt yuv420p rtmp://192.168.1.100:1935/live/desktop";
string param = "-re -f gdigrab -i desktop -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -f flv -pix_fmt yuv420p rtmp://" + ip + ":1935/live/" + streamName;

//ProcessStartInfo info = new ProcessStartInfo(strExePath);
ProcessStartInfo info = new ProcessStartInfo(strExePath,param);
info.UseShellExecute = false;

info.WindowStyle = ProcessWindowStyle.Hidden; //隐藏exe窗口状态

//info.CreateNoWindow = true; //隐藏本exe的窗口

Process proBach = Process.Start(info); //运行exe
// 取得EXE运行后的返回值,返回值只能是整型
//returnValue = proBach.ExitCode;
//Console.WriteLine("returnValue:" + returnValue);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
Console.WriteLine("");
}

}
}
}

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在C#中使用ffmpeg库,你需要使用FFmpeg.AutoGen库。以下是一个简单的示例代码: ```csharp using FFmpeg.AutoGen; unsafe static void Main(string[] args) { av_register_all(); avformat_network_init(); AVFormatContext* pFormatContext = null; AVCodecContext* pCodecContext = null; AVCodec* pCodec = null; AVFrame* pFrame = null; AVPacket* pPacket = null; // 打开视频文件 avformat_open_input(&pFormatContext, "input.mp4", null, null); // 查找视频流 avformat_find_stream_info(pFormatContext, null); // 获取视频流索引 int videoStreamIndex = -1; for (int i = 0; i < pFormatContext->nb_streams; i++) { if (pFormatContext->streams[i]->codecpar->codec_type == AVMediaType.AVMEDIA_TYPE_VIDEO) { videoStreamIndex = i; break; } } // 获取视频流解码器 pCodec = avcodec_find_decoder(pFormatContext->streams[videoStreamIndex]->codecpar->codec_id); pCodecContext = avcodec_alloc_context3(pCodec); avcodec_parameters_to_context(pCodecContext, pFormatContext->streams[videoStreamIndex]->codecpar); avcodec_open2(pCodecContext, pCodec, null); pFrame = av_frame_alloc(); pPacket = av_packet_alloc(); // 解码视频帧 while (av_read_frame(pFormatContext, pPacket) >= 0) { if (pPacket->stream_index == videoStreamIndex) { avcodec_send_packet(pCodecContext, pPacket); while (avcodec_receive_frame(pCodecContext, pFrame) == 0) { // 处理视频帧 } } av_packet_unref(pPacket); } avformat_close_input(&pFormatContext); avformat_network_deinit(); } ``` 在这个示例代码中,我们首先调用av_register_all和avformat_network_init函数初始化FFmpeg库。然后我们使用avformat_open_input函数打开视频文件,使用avformat_find_stream_info函数查找视频流,然后使用avcodec_find_decoder函数查找视频流解码器,最后使用avcodec_send_packet和avcodec_receive_frame函数解码视频帧。 请注意,这只是一个简单的示例代码,并且FFmpeg库的使用可能因版本而异。你需要根据自己的需要调整代码,以满足你的需求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值