• 大小: 658KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-11-27
  • 语言: Html/CSS
  • 标签: html5  websocket  解码  

资源简介

通过websocket传输裸H264到网页通过html5 video标签解码 参考博客https://blog.csdn.net/g0415shenw/article/details/80372580

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

/// 
/// 作者:笨鸟先飞g0415shenw
/// 音视频交流qq群:759117824
/// 博客:https://blog.csdn.net/g0415shenw
/// 欢迎大家留言入群交流
/// 

namespace H5WebSocket
{
    class Program
    {
        static List m_BufH264 = new List();
        static FileStream m_fs = new FileStream(“bigbuckbunny_480x272.h264“ FileMode.Open);
        static int m_iHaveRead = 0;
        static int m_iReadLenth = 1024;
        static byte[] m_H264frame;
        static void Main(string[] args)
        {

            StartWebSocket();
            Console.ReadKey();

        }
        async static void StartWebSocket()
        {
            var listener = new HttpListener();
            listener.Prefixes.Add(“http://127.0.0.1:8080/“);
            listener.Start();
            while(true)
            {
                var context = listener.GetContext();
                var wsContext = await context.AcceptWebSocketAsync(null);
                var ws = wsContext.WebSocket;
                Console.WriteLine(“WebSocket connect“);

                //create H264 send thread
                await Task.Run(() =>
                 {
                     while(true)
                     {
                         if(ReadOneframeFromFile())
                         {
                             ws.SendAsync(new ArraySegment(m_H264frame) System.Net.WebSockets.WebSocketMessageType.Binary true new System.Threading.CancellationToken());
                             Thread.Sleep(25);
                         }
                         else
                         {
                             ws.Dispose();
                             return;
                         }
                     }
                 });
            }
           
        }
        static bool ReadOneframeFromFile()
        {
            while(!GetOneframe())
            {
                if ((m_iHaveRead + m_iReadLenth) < m_fs.Length)
                {
                    byte[] bRead = new byte[m_iReadLenth];
                    m_fs.Read(bRead 0 m_iReadLenth);
                    m_BufH264.AddRange(bRead);
                }
                else
                {
                    return false;
                }
            }
            return true;
        }
        static bool GetOneframe()
        {
            if(m_BufH264.Count<=8)
            {
                return false;
            }
            int iCount = 0;
            for (int i = 4;i            {
                if(m_BufH264[i]==0 && m_BufH264[i+1] == 0&& m_BufH264[i+2] == 0&& m_BufH264[i+3] == 1)
                {
                    iCount = i;
                    break;
                }
            }
            if(iCount>0)
         

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        658  2018-05-19 11:02  H5WebSocket\.gitignore

     文件        187  2018-05-19 07:21  H5WebSocket\App.config

     文件        678  2018-05-19 10:50  H5WebSocket\bin\Debug\.gitignore

     文件     626669  2015-07-15 16:19  H5WebSocket\bin\Debug\bigbuckbunny_480x272.h264

     文件       8192  2018-05-19 12:51  H5WebSocket\bin\Debug\H5WebSocket.exe

     文件        187  2018-05-19 07:21  H5WebSocket\bin\Debug\H5WebSocket.exe.config

     文件      15872  2018-05-19 12:51  H5WebSocket\bin\Debug\H5WebSocket.pdb

     文件        721  2018-05-19 09:47  H5WebSocket\demo\index.html

     文件     143263  2018-05-19 09:47  H5WebSocket\demo\wfs.js

     文件       2258  2018-05-19 07:21  H5WebSocket\H5WebSocket.csproj

     文件         42  2018-05-19 10:50  H5WebSocket\obj\Debug\H5WebSocket.csproj.CoreCompileInputs.cache

     文件        669  2018-05-19 11:01  H5WebSocket\obj\Debug\H5WebSocket.csproj.FileListAbsolute.txt

     文件       8059  2018-05-19 10:50  H5WebSocket\obj\Debug\H5WebSocket.csprojAssemblyReference.cache

     文件       8192  2018-05-19 12:51  H5WebSocket\obj\Debug\H5WebSocket.exe

     文件      15872  2018-05-19 12:51  H5WebSocket\obj\Debug\H5WebSocket.pdb

     文件          0  2018-05-19 10:50  H5WebSocket\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs

     文件          0  2018-05-19 10:50  H5WebSocket\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs

     文件          0  2018-05-19 10:50  H5WebSocket\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs

     文件       3370  2018-05-19 11:05  H5WebSocket\Program.cs

     文件       1320  2018-05-19 07:21  H5WebSocket\Properties\AssemblyInfo.cs

     目录          0  2018-05-19 10:50  H5WebSocket\obj\Debug\TempPE

     目录          0  2018-05-19 10:50  H5WebSocket\bin\Debug

     目录          0  2018-05-19 11:01  H5WebSocket\obj\Debug

     目录          0  2018-05-19 07:21  H5WebSocket\bin

     目录          0  2018-05-19 09:47  H5WebSocket\demo

     目录          0  2018-05-19 10:50  H5WebSocket\obj

     目录          0  2018-05-19 07:21  H5WebSocket\Properties

     目录          0  2018-05-19 11:05  H5WebSocket

----------- ---------  ---------- -----  ----

               836209                    28

............此处省略1个文件信息

评论

共有 条评论