zoukankan      html  css  js  c++  java
  • C#中读取流媒体视频文件转H.264具体实现方法

    现在有越来越多的人在使用C#语言做编程,但我发现好像用C#做音视频流媒体开发的比较少。我们的libEasyScreenLive目前支持Windows,Android平台,通过EasyScreenLive我们就可以避免接触到稍显复杂的音视频源采集,编码和流媒体推送以及RTSP/RTP/RTCP/RTMP服务流程。

    本文给大家介绍一下C#中读取流媒体视频文件转H.264具体实现方法。

    private void Test()
            {
                byte[] buffer;
                //c#文件流读文件 
                using (FileStream fsRead = new FileStream(videoName, FileMode.Open, FileAccess.Read))
                {
                    int fsLen = (int)fsRead.Length;
                    buffer = new byte[fsLen];
                    int r = fsRead.Read(buffer, 0, buffer.Length);
                } 
    
                PsToH264(buffer);
            }
    
    public void PsToH264(byte[] buffer)
            {
                _publicByte = copybyte(_publicByte, buffer);
                int i = 0;
                int BANum = 0;
                int startIndex = 0;
                if (buffer == null || buffer.Length < 5)
                {
                    return;
                }
                int bytes = _publicByte.Length - 4;
                while (i < bytes)
                {
                    if (_publicByte[i] == 0x00 && _publicByte[i + 1] == 0x00 && _publicByte[i + 2] == 0x01 && _publicByte[i + 3] == 0xBA)
                    {
                        BANum++;
                        if (BANum == 1)
                        {
                            startIndex = i;
                        }
                        if (BANum == 2)
                        {
                            break;
                        }
                    }
                    i++;
                }
    
                if (BANum == 2)
                {
                    int esNum = i - startIndex;
                    byte[] psByte = new byte[esNum];
                    Array.Copy(_publicByte, startIndex, psByte, 0, esNum);
    
                    try
                    {
                        //处理psByte
                        doPsByte(psByte);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("===============" + ex.Message + ex.StackTrace.ToString());
                    }
    
                    byte[] overByte = new byte[_publicByte.Length - i];
                    Array.Copy(_publicByte, i, overByte, 0, overByte.Length);
                    _publicByte = overByte;
                }
            }
  • 相关阅读:
    C 语言 静态库和动态库的创建和应用
    C++ 中英文术语对照
    下午
    [转]内核 do_fork 函数源代码浅析
    关于C#反射机制,自己写的
    获取字符串中数字
    关于C#反射机制,来源于网络
    关于 Nhinernate 的one to one(转载)
    鼠标坐标的记录
    关于C#中hibernate.cfg.xml动态加载问题
  • 原文地址:https://www.cnblogs.com/TSINGSEE/p/12848803.html
Copyright © 2011-2022 走看看