• 大小: 29.9MB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2023-07-27
  • 语言: C#
  • 标签: rtsp  FFmpeg  

资源简介

C# 使用FFmpeg库保存rtsp视频流为本地文件,获取摄像头rtsp视频流地址可以参考我的另一个资源

资源截图

代码片段和文件信息

using System;
using System.IO;
using System.Runtime.InteropServices;

namespace OnvifVideoServer
{
    public class FFmpegBinariesHelper
    {
        private const string LD_LIBRARY_PATH = “LD_LIBRARY_PATH“;

        internal static void RegisterFFmpegBinaries()
        {
            switch (Environment.OSVersion.Platform)
            {
                case PlatformID.Win32NT:
                case PlatformID.Win32S:
                case PlatformID.Win32Windows:
                    var current = Environment.CurrentDirectory;
                    var probe = $“FFmpeg/bin/{(Environment.Is64BitProcess ? @“x64“ : @“x86“)}“;
                    while (current != null)
                    {
                        var ffmpegDirectory = Path.Combine(current probe);
                        if (Directory.Exists(ffmpegDirectory))
                        {
                            RegisterLibrariesSearchPath(ffmpegDirectory);
                            return;
                        }
                        current = Directory.GetParent(current)?.FullName;
                    }
                    break;
                case PlatformID.Unix:
                case PlatformID.MacOSX:
                    var libraryPath = Environment.GetEnvironmentVariable(LD_LIBRARY_PATH);
                    RegisterLibrariesSearchPath(libraryPath);
                    break;
            }
        }
        private static void RegisterLibrariesSearchPath(string path)
        {
            switch (Environment.OSVersion.Platform)
            {
                case PlatformID.Win32NT:
                case PlatformID.Win32S:
                case PlatformID.Win32Windows:
                    SetDllDirectory(path);
                    break;
                case PlatformID.Unix:
                case PlatformID.MacOSX:
                    string currentValue = Environment.GetEnvironmentVariable(LD_LIBRARY_PATH);
                    if (string.IsNullOrWhiteSpace(currentValue) == false && currentValue.Contains(path) == false)
                    {
                        string newValue = currentValue + Path.PathSeparator + path;
                        Environment.SetEnvironmentVariable(LD_LIBRARY_PATH newValue);
                    }
                    break;
            }
        }

        [DllImport(“kernel32“ SetLastError = true)]
        private static extern bool SetDllDirectory(string lpPathName);
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-11-14 17:22  OnvifVideoServer\
     目录           0  2018-11-14 17:01  OnvifVideoServer\.vs\
     目录           0  2018-11-14 17:03  OnvifVideoServer\.vs\OnvifVideoServer\
     目录           0  2018-11-14 17:17  OnvifVideoServer\.vs\OnvifVideoServer\v14\
     文件        6656  2018-11-14 17:48  OnvifVideoServer\.vs\OnvifVideoServer\v14\.suo
     目录           0  2018-11-14 17:17  OnvifVideoServer\.vs\OnvifVideoServer\v15\
     文件        3584  2018-11-14 17:17  OnvifVideoServer\.vs\OnvifVideoServer\v15\.suo
     文件         184  2018-11-07 11:56  OnvifVideoServer\App.config
     文件        2439  2018-11-14 17:22  OnvifVideoServer\FFmpegBinariesHelper.cs
     文件        2216  2018-11-14 17:03  OnvifVideoServer\Form1.Designer.cs
     文件        1980  2018-11-14 17:07  OnvifVideoServer\Form1.cs
     文件        6011  2018-11-14 17:03  OnvifVideoServer\Form1.resx
     文件        4642  2018-11-13 17:13  OnvifVideoServer\OnvifVideoServer.csproj
     文件         595  2018-11-14 17:02  OnvifVideoServer\Program.cs
     目录           0  2018-11-14 17:00  OnvifVideoServer\Properties\
     文件        1358  2018-11-07 11:56  OnvifVideoServer\Properties\AssemblyInfo.cs
     文件        2872  2018-11-07 11:56  OnvifVideoServer\Properties\Resources.Designer.cs
     文件        5612  2018-11-07 11:56  OnvifVideoServer\Properties\Resources.resx
     文件        1116  2018-11-07 11:56  OnvifVideoServer\Properties\Settings.Designer.cs
     文件         249  2018-11-07 11:56  OnvifVideoServer\Properties\Settings.settings
     文件        6658  2018-11-14 17:06  OnvifVideoServer\RTSPHelper.cs
     目录           0  2018-11-15 09:24  OnvifVideoServer\bin\
     目录           0  2018-11-14 17:13  OnvifVideoServer\bin\Debug\
     目录           0  2018-11-15 09:24  OnvifVideoServer\bin\Debug\ErrorLogs\
     文件      217088  2017-09-14 13:49  OnvifVideoServer\bin\Debug\FFmpeg.AutoGen.dll
     文件      176128  2013-05-18 11:15  OnvifVideoServer\bin\Debug\ICSharpCode.SharpZipLib.dll
     文件      229376  2013-08-28 18:47  OnvifVideoServer\bin\Debug\NVelocity.dll
     文件      373760  2013-08-28 18:47  OnvifVideoServer\bin\Debug\Newtonsoft.Json.dll
     文件       19968  2018-11-02 09:42  OnvifVideoServer\bin\Debug\Omu.ValueInjecter.dll
     文件        7778  2018-11-02 09:42  OnvifVideoServer\bin\Debug\Omu.ValueInjecter.xml
     文件       14336  2018-11-14 17:22  OnvifVideoServer\bin\Debug\OnvifVideoServer.exe
............此处省略169个文件信息

评论

共有 条评论