Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

c# ffmpeg

作者:刃起风啸凌   发布日期:2026-04-21   浏览:118

using System;
using FFmpeg.AutoGen;

class Program
{
    static unsafe void Main(string[] args)
    {
        // 初始化FFmpeg库
        ffmpeg.avformat_network_init();

        // 打开输入文件或流
        AVFormatContext* formatContext = null;
        string inputFilePath = "input.mp4";
        if (ffmpeg.avformat_open_input(&formatContext, inputFilePath, null, null) != 0)
        {
            Console.WriteLine("无法打开输入文件");
            return;
        }

        // 读取文件信息
        if (ffmpeg.avformat_find_stream_info(formatContext, null) < 0)
        {
            Console.WriteLine("无法读取流信息");
            return;
        }

        // 输出文件信息
        ffmpeg.av_dump_format(formatContext, 0, inputFilePath, 0);

        // 关闭文件
        ffmpeg.avformat_close_input(&formatContext);
    }
}

解释说明:

  1. 初始化FFmpeg库ffmpeg.avformat_network_init() 用于初始化网络支持,这对于处理网络流是必需的。
  2. 打开输入文件或流ffmpeg.avformat_open_input 用于打开指定的输入文件或流。如果打开失败,则输出错误信息并返回。
  3. 读取文件信息ffmpeg.avformat_find_stream_info 用于读取文件中的流信息(如视频、音频轨道等)。如果读取失败,则输出错误信息并返回。
  4. 输出文件信息ffmpeg.av_dump_format 用于将文件信息打印到控制台,方便调试和查看。
  5. 关闭文件ffmpeg.avformat_close_input 用于关闭打开的文件或流,释放资源。

如果你需要更复杂的操作(如转码、截图等),可以在此基础上进一步扩展代码。

上一篇:c# %

下一篇:c#基础

大家都在看

c# 二进制

c# 创建目录

c# socket服务端连接多个客户端

c# datatable group by

c# tcp client

c# type.gettype

c# sqlconnection

c# string.format 小数位数

c# invoke方法

.net和c#

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站