Closed CodingOX closed 4 years ago
你好,我试了你给的这个网址,没能重现问题。你能把裁剪结果贴上来?
你好,我试了你给的这个网址,没能重现问题。你能把裁剪结果贴上来?
如下是内容:
安装命令ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"移除命令ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
增加对 nginx 的扩展;也就是从github上下载,home-brew对ngixnx的扩展
brew tap homebrew/nginx
brew install nginx-full --with-rtmp-module
brew info nginx-full
nginx的安装位置
/usr/local/Cellar/nginx-full/1.10.1/bin/nginxnginx配置文件所在位置/usr/local/etc/nginx/nginx.confnginx服务器根目录所在位置 /usr/local/var/www
使用命令开启nginx:
nginx
在浏览器地址栏输入:http://localhost:8080 (直接点击)
图1.jpg
open /usr/local/etc/nginx
打开niginx的文件夹,找到nginx.conf文件,用xcode打开。添加下面配置
#在http节点下面(也就是文件的尾部)加上rtmp配置:rtmp {#协议名称 server {#说明内部中是服务器相关配置 listen 12345;#监听的端口号, rtmp协议的默认端口号是1935 application zbcs {#访问的应用路径是 zbcs live on; #开启实时 record off;#不记录数据 } }}
图2.jpg
重要操作!一定要重启nginx
nginx -s reload
brew install ffmpeg
ffmpeg -re -i /Users/mazaiting/Downloads/台球.mp4 -vcodec copy -f flv rtmp://localhost:12345/zbcs/room
其中abcs是配置文件中的应用名,12345是配置文件中的端口,room可以随便写,"/Users/mazaiting/Downloads/台球.mp4"是推流的视频。
使用软件VLC MediaPlayer打开网络串流,Open Media...->Network,输入rtmp://localhost:12345/zbcs/room
,点击Open进行观看。
图3.jpg
你好,我试了你给的这个网址,没能重现问题。你能把裁剪结果贴上来?
比如当前是: 原本是:
@CodingOx
我猜测你的 markdown 查看软件,无法正确识别换行符 \n
。下面是我裁剪这个网页后,把文件读出来。你可以看到文本 "安装命令" 的后面是有个换行符 \n
的。
不知道你是不是在 windows 下,windows 的默认文本打开软件「记事本」,无法正确显示换行符 \n
。
"# MAC使用Nginx搭建RTMP服务器\n\n#### 1、先安装homeView\n\n```plain\n安装命令\nruby -e \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)\"\n\n移除命令\nruby -e \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)\"\n```\n\n#### 2、安装Nginx服务器\n\n增加对 nginx 的扩展;也就是从github上下载,home-brew对ngixnx的扩展\n\n```plain\nbrew tap homebrew/nginx\n```\n\n#### 3、安装Nginx服务器和rtmp模块,安装过程有点久。稍等。\n\n```plain\nbrew install nginx-full --with-rtmp-module\n```\n\n#### 4、查看nginx的信息\n\n```plain\nbrew info nginx-full\n```\n\nnginx的安装位置\n\n```plain\n/usr/local/Cellar/nginx-full/1.10.1/bin/nginx\nnginx配置文件所在位置\n/usr/local/etc/nginx/nginx.conf\nnginx服务器根目录所在位置 \n /usr/local/var/www\n```\n\n使用命令开启nginx:\n\n```plain\nnginx\n```\n\n在浏览器地址栏输入:[http://localhost:8080](https://link.jianshu.com/?t=http://localhost:8080/) (直接点击)\n\n![](invalid-url.png)\n\n图1.jpg\n\n#### 5、配置rtmp\n\n```plain\nopen /usr/local/etc/nginx\n```\n\n打开niginx的文件夹,找到nginx.conf文件,用xcode打开。添加下面配置\n\n```plain\n#在http节点下面(也就是文件的尾部)加上rtmp配置:\nrtmp {#协议名称\n server {#说明内部中是服务器相关配置\n listen 12345;#监听的端口号, rtmp协议的默认端口号是1935\n application zbcs {#访问的应用路径是 zbcs\n live on; #开启实时\n record off;#不记录数据\n }\n }\n}\n```\n\n![](invalid-url.png)\n\n图2.jpg\n\n#### 6、 保存文件后,重新加载nginx的配置文件。\n\n重要操作!一定要重启nginx\n\n```plain\nnginx -s reload\n```\n\n#### 7、 安装ffmepg工具\n\n```plain\nbrew install ffmpeg\n```\n\n#### 8、推流\n\n```plain\nffmpeg -re -i /Users/mazaiting/Downloads/台球.mp4 -vcodec copy -f flv rtmp://localhost:12345/zbcs/room\n```\n\n其中abcs是配置文件中的应用名,12345是配置文件中的端口,room可以随便写,\"/Users/mazaiting/Downloads/台球.mp4\"是推流的视频。\n\n#### 9、观看\n\n使用软件[VLC MediaPlayer](http://www.videolan.org/vlc/)打开网络串流,Open Media...->Network,输入`rtmp://localhost:12345/zbcs/room`,点击Open进行观看。 \n\n![](invalid-url.png)\n\n图3.jpg
啊,我知道了,我和你的运行环境不一样,我没有启用脚本,所以我裁剪出来的代码都是 plain,而你的和我不一样。(可是这个网站一启用脚本就白屏)。
我实在打不开这个网页。里面的 JS 似乎有问题,也有可能是墙在搞鬼。你能把网页用 html 的格式裁剪下来,然后发到这里吗?
我实在打不开这个网页。里面的 JS 似乎有问题,也有可能是墙在搞鬼。你能把网页用 html 的格式裁剪下来,然后发到这里吗?
下面是用插件,剪裁下来的 html 的代码
<!DOCTYPE html>
<html id="" class="cm-retina">
<!-- OriginalSrc: https://www.jianshu.com/p/5ec142a5fd8c -->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>MAC使用Nginx搭建RTMP服务器 - 简书</title>
<link rel="stylesheet" href="assets/1585384411-a163dd27aceef87938caba87283f7ee8.css" referrerpolicy="no-referrer">
<link rel="stylesheet" href="assets/1585384411-47b864473137965bed1f03ba57113429.css" referrerpolicy="no-referrer">
<link rel="stylesheet" type="text/css" href="assets/1585384411-b8703ee03d9ae4a892fed93b0ce964ab.css" referrerpolicy="no-referrer">
<link rel="stylesheet" type="text/css" href="assets/1585384411-19946a1e2cc23252d34cb7ce75ed7fc5.css" referrerpolicy="no-referrer">
<link rel="stylesheet" type="text/css" href="assets/1585384411-c0658ff162731971280527d7a832c5f7.css" referrerpolicy="no-referrer">
<style type="text/css">#rwl-iqxin{position:fixed;transform:translate(-95px,0);width:85px;height:25px;font-size:12px;font-weight: 500;font-family:Verdana, Arial, '宋体';color:#fff;background:#333;z-index:2147483647;margin: 0;opacity:0.05;transition:0.3s;overflow:hidden;user-select:none;text-align:center;white-space:nowrap;line-height:25px;padding:0 16px;border:1px solid #ccc;border-width:1px 1px 1px 0;border-bottom-right-radius:5px;box-sizing: content-box;}#rwl-iqxin input{margin: 0;padding: 0;vertical-align:middle;-webkit-appearance:checkbox;-moz-appearance:checkbox;position: static;clip: auto;opacity: 1;cursor: pointer;}#rwl-iqxin.rwl-active-iqxin{left: 0px;transform:translate(0,0);opacity: 0.9;height: 32px;line-height: 32px}#rwl-iqxin label{margin:0;padding:0;font-weight:500;}#rwl-iqxin #rwl-setbtn{margin: 0 4px 0 0;padding: 0 0 0 4px;border: none;border-radius: 2px;cursor: pointer;background: #fff;color: #000;} </style>
<style class="mx-wc-style">
body {padding-top: 20px;}
.mx-wc-main img {max-width: 100%;}
.mx-wc-main{
box-sizing: content-box;
background-color: rgb(249, 249, 249) !important;
margin: 0 auto;
max-width: 700px;
}
@media (min-width: 768px) {
.mx-wc-main { padding: 15px 15px 80px 15px }
}
@media (max-width: 767px) {
.mx-wc-main { padding: 15px 3px 80px 3px }
}
</style>
</head>
<body style="background-color: #464646 !important; min-height: 100%; height: auto; position: static !important; overflow: auto !important; padding-bottom: 0px !important;" id="" class="">
<div class="mx-wc-main">
<DIV id="__next" style="display: block !important;float: none !important;position: relative !important;top: 0 !important;left: 0 !important;border: 0px !important;width: 100% !important;min-width: 100% !important;max-width: 100% !important;height: auto !important;min-height: auto !important;max-height: 100% !important;margin: 0px !important;padding: 0px !important;"><DIV class="_21bLU4 _3kbg6I" style="display: block !important;float: none !important;position: relative !important;top: 0 !important;left: 0 !important;border: 0px !important;width: 100% !important;min-width: 100% !important;max-width: 100% !important;height: auto !important;min-height: auto !important;max-height: 100% !important;margin: 0px !important;padding: 0px !important;"><DIV class="_3VRLsv" role="main" style="display: block !important;float: none !important;position: relative !important;top: 0 !important;left: 0 !important;border: 0px !important;width: 100% !important;min-width: 100% !important;max-width: 100% !important;height: auto !important;min-height: auto !important;max-height: 100% !important;margin: 0px !important;padding: 0px !important;"><DIV class="_gp-ck" style="display: block !important;float: none !important;position: relative !important;top: 0 !important;left: 0 !important;border: 0px !important;width: 100% !important;min-width: 100% !important;max-width: 100% !important;height: auto !important;min-height: auto !important;max-height: 100% !important;margin: 0px !important;padding: 0px !important;"><SECTION class="ouvJEz" style="display: block !important;float: none !important;position: relative !important;top: 0 !important;left: 0 !important;border: 0px !important;width: 100% !important;min-width: 100% !important;max-width: 100% !important;height: auto !important;min-height: auto !important;max-height: 100% !important;margin: 0px !important;padding: 0px !important;"><article class="_2rhmJa mx-wc-selected-elem" style="display: block; float: none !important; position: relative !important; top: 0px !important; left: 0px !important; margin: 0px !important; flex: unset !important; width: 100% !important; max-width: 100% !important;"><h4>1、先安装homeView</h4>
<div class="_2Uzcx_"><pre class="line-numbers language-bash"><code class=" language-bash">安装命令
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
移除命令
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span></span></code></pre></div>
<h4>2、安装Nginx服务器</h4>
<p>增加对 nginx 的扩展;也就是从github上下载,home-brew对ngixnx的扩展</p>
<div class="_2Uzcx_"><pre class="line-numbers language-undefined"><code class=" language-undefined">brew tap homebrew/nginx
<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre></div>
<h4>3、安装Nginx服务器和rtmp模块,安装过程有点久。稍等。</h4>
<div class="_2Uzcx_"><pre class="line-numbers language-jsx"><code class=" language-jsx">brew install nginx<span class="token operator">-</span>full <span class="token operator">--</span><span class="token keyword">with</span><span class="token operator">-</span>rtmp<span class="token operator">-</span>module
<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre></div>
<h4>4、查看nginx的信息</h4>
<div class="_2Uzcx_"><pre class="line-numbers language-undefined"><code class=" language-undefined">brew info nginx-full
<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre></div>
<p>nginx的安装位置</p>
<div class="_2Uzcx_"><pre class="line-numbers language-bash"><code class=" language-bash">/usr/local/Cellar/nginx-full/1.10.1/bin/nginx
nginx配置文件所在位置
/usr/local/etc/nginx/nginx.conf
nginx服务器根目录所在位置
/usr/local/var/www
<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span></span></code></pre></div>
<p>使用命令开启nginx:</p>
<div class="_2Uzcx_"><pre class="line-numbers language-undefined"><code class=" language-undefined">nginx
<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre></div>
<p>在浏览器地址栏输入:<a href="https://link.jianshu.com/?t=http://localhost:8080/" target="_blank" referrerpolicy="no-referrer" rel="noopener noreferrer">http://localhost:8080</a> (直接点击)</p>
<div class="image-package">
<div class="image-container" style="max-width: 700px; max-height: 346px; background-color: transparent;">
<div class="image-container-fill" style="padding-bottom: 36.08%;"></div>
<div class="image-view" data-width="959" data-height="346"><img data-original-src="//upload-images.jianshu.io/upload_images/3110861-720ee0515c3ef025.jpg" data-original-width="959" data-original-height="346" data-original-format="" data-original-filesize="58150" data-image-index="0" style="cursor: zoom-in;" class="" src="assets/1585384411-fa2ba2dfa4b02dca9d73c310ac325f8d.jpg"></div>
</div>
<div class="image-caption">图1.jpg</div>
</div>
<h4>5、配置rtmp</h4>
<div class="_2Uzcx_"><pre class="line-numbers language-bash"><code class=" language-bash">open /usr/local/etc/nginx
<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre></div>
<p>打开niginx的文件夹,找到nginx.conf文件,用xcode打开。添加下面配置</p>
<div class="_2Uzcx_"><pre class="line-numbers language-csharp"><code class=" language-csharp"><span class="token preprocessor property">#在http节点下面(也就是文件的尾部)加上rtmp配置:</span>
rtmp <span class="token punctuation">{</span>#协议名称
server <span class="token punctuation">{</span>#说明内部中是服务器相关配置
listen <span class="token number">12345</span><span class="token punctuation">;</span>#监听的端口号<span class="token punctuation">,</span> rtmp协议的默认端口号是<span class="token number">1935</span>
application zbcs <span class="token punctuation">{</span>#访问的应用路径是 zbcs
live on<span class="token punctuation">;</span> #开启实时
record off<span class="token punctuation">;</span>#不记录数据
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></div>
<div class="image-package">
<div class="image-container" style="max-width: 700px; max-height: 672px;">
<div class="image-container-fill" style="padding-bottom: 96.13000000000001%;"></div>
<div class="image-view" data-width="800" data-height="769"><img data-original-src="//upload-images.jianshu.io/upload_images/3110861-887e6236e8b243ed.jpg" data-original-width="800" data-original-height="769" data-original-format="" data-original-filesize="134940" data-image-index="1" style="cursor: zoom-in;" class="image-loading" data-mx-warn="Empty URL" data-mx-original-src="" src="invalid-url.png"></div>
</div>
<div class="image-caption">图2.jpg</div>
</div>
<h4>6、 保存文件后,重新加载nginx的配置文件。</h4>
<p>重要操作!一定要重启nginx</p>
<div class="_2Uzcx_"><pre class="line-numbers language-undefined"><code class=" language-undefined">nginx -s reload
<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre></div>
<h4>7、 安装ffmepg工具</h4>
<div class="_2Uzcx_"><pre class="line-numbers language-undefined"><code class=" language-undefined">brew install ffmpeg
<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre></div>
<h4>8、推流</h4>
<div class="_2Uzcx_"><pre class="line-numbers language-go"><code class=" language-go">ffmpeg <span class="token operator">-</span>re <span class="token operator">-</span>i <span class="token operator">/</span>Users<span class="token operator">/</span>mazaiting<span class="token operator">/</span>Downloads<span class="token operator">/</span>台球<span class="token punctuation">.</span>mp4 <span class="token operator">-</span>vcodec <span class="token builtin">copy</span> <span class="token operator">-</span>f flv rtmp<span class="token punctuation">:</span><span class="token operator">/</span><span class="token operator">/</span>localhost<span class="token punctuation">:</span><span class="token number">12345</span><span class="token operator">/</span>zbcs<span class="token operator">/</span>room
<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre></div>
<p>其中abcs是配置文件中的应用名,12345是配置文件中的端口,room可以随便写,"/Users/mazaiting/Downloads/台球.mp4"是推流的视频。</p>
<h4>9、观看</h4>
<p>使用软件<a href="http://www.videolan.org/vlc/" target="_blank" rel="noopener noreferrer" referrerpolicy="no-referrer">VLC MediaPlayer</a>打开网络串流,Open Media...->Network,输入<code>rtmp://localhost:12345/zbcs/room</code>,点击Open进行观看。<br>
</p><div class="image-package">
<div class="image-container" style="max-width: 700px; max-height: 403px;">
<div class="image-container-fill" style="padding-bottom: 46.86%;"></div>
<div class="image-view" data-width="860" data-height="403"><img data-original-src="//upload-images.jianshu.io/upload_images/3110861-46e55c012d37dcfc.jpg" data-original-width="860" data-original-height="403" data-original-format="" data-original-filesize="62696" data-image-index="2" style="cursor: zoom-in;" class="image-loading" data-mx-warn="Empty URL" data-mx-original-src="" src="invalid-url.png"></div>
</div>
<div class="image-caption">图3.jpg</div>
</div><p></p>
</article></SECTION></DIV></DIV></DIV></DIV>
</div>
</body>
</html>
这样貌似是没有问题的!
@CodingOX 你在 WizNotePlus 文档页面,打开右键菜单,选择 “打开临时文件夹位置” ,然后在浏览器里查看 index.html。看看是不是 WizNotePlus 渲染问题?
我实在打不开这个网页。里面的 JS 似乎有问题,也有可能是墙在搞鬼。你能把网页用 html 的格式裁剪下来,然后发到这里吗?
我在提供一个发现问题的页面,CSDN 的:https://blog.csdn.net/vanjoge/article/details/79657874
剪裁下来也是出现该问题!
@CodingOX 你在 WizNotePlus 文档页面,打开右键菜单,选择 “打开临时文件夹位置” ,然后在浏览器里查看 index.html。看看是不是 WizNotePlus 渲染问题?
Mac 下,我没有发现这个怎么操作,抱歉! 不过我发现剪裁下面的 MarkDown 原始的文件,也是出现该问题的。
@CodingOX 你在 WizNotePlus 文档页面,打开右键菜单,选择 “打开临时文件夹位置” ,然后在浏览器里查看 index.html。看看是不是 WizNotePlus 渲染问题?
如图所示,问题依旧:
@mika-cn @altairwei 我提供一下剪裁后的结果: bug-resource.zip
我使用 “浏览器” 来下载剪裁页面,能够复现这个问题 https://www.jianshu.com/p/5ec142a5fd8c
@CodingOX
幫忙把這個網頁(https://blog.csdn.net/vanjoge/article/details/79657874)也用 html 格式裁剪下來,粘貼上來。
我嘗試把這兩個問題都修了。
@CodingOX
幫忙把這個網頁(https://blog.csdn.net/vanjoge/article/details/79657874)也用 html 格式裁剪下來,粘貼上來。
我嘗試把這兩個問題都修了。
以下是html 文件 source2.zip
以下是 html 的代码
<!DOCTYPE html>
<html id="" class="cm-retina">
<!-- OriginalSrc: https://blog.csdn.net/vanjoge/article/details/79657874 -->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>C#开发FFMPEG例子(API方式) FFmpeg拉取RTMP流并播放_C#_vanjoge的博客-CSDN博客</title>
<link rel="stylesheet" href="assets/1585390350-e98db96b744b629cab9eef4e306b209d.css" referrerpolicy="no-referrer">
<link rel="stylesheet" href="assets/1585390350-4eb27f14c92dd9348d1cdf8636d7a92e.css" referrerpolicy="no-referrer">
<link rel="stylesheet" href="assets/1585390350-3ee558b18d32cf19bc5f15c8f3dc942f.css" referrerpolicy="no-referrer">
<link rel="stylesheet" type="text/css" href="assets/1585390350-ce2a7a7a13b3b2aae540a44424b01c4b.css" referrerpolicy="no-referrer">
<link rel="stylesheet" type="text/css" href="assets/1585390350-78080f772924c0d07b282be0e2e3078e.css" referrerpolicy="no-referrer">
<link rel="stylesheet" type="text/css" href="assets/1585390350-a6c3000d53b6a1600bb40d9e36063f0f.css" referrerpolicy="no-referrer">
<link rel="stylesheet" type="text/css" href="assets/1585390350-240753ccfa3afa1ce9400c95d3af703f.css" referrerpolicy="no-referrer">
<link rel="stylesheet" href="assets/1585390350-8afce11d00f7bc88a8191ad66e945525.css" referrerpolicy="no-referrer">
<link rel="stylesheet" href="assets/1585390350-d59c8fbcb4e99f490e1b848904625eb0.css" referrerpolicy="no-referrer">
<link rel="stylesheet" href="assets/1585390350-e60b8afa93239c562b4a10fa023d71c6.css" referrerpolicy="no-referrer">
<link rel="stylesheet" href="assets/1585390350-186b0d2f06ccc88e64f41fdb5cf32ed8.css" referrerpolicy="no-referrer">
<link rel="stylesheet" href="assets/1585390350-27408d75f6de622064bb82366bd31c72.css" referrerpolicy="no-referrer">
<link rel="stylesheet" href="assets/1585390350-27408d75f6de622064bb82366bd31c72.css" referrerpolicy="no-referrer">
<link rel="stylesheet" href="assets/1585390350-913d01a6af20594d2652620992e4dc4b.css" referrerpolicy="no-referrer">
<link rel="stylesheet" href="assets/1585390350-776fd6508449d6399c7cbc31bc1307f0.css" referrerpolicy="no-referrer">
<style>.login-box{position: fixed;display: none;left: 50%;top: 50%;z-index: 10000;-webkit-transform: translate(-50%, -50%);-ms-transform: translate(-50%, -50%);-o-transform: translate(-50%, -50%);-moz-transform: translate(-50%, -50%);transform: translate(-50%, -50%);background-color: #fff;}.login-mark{position: fixed;top: 0;left: 0;z-index: 9999;background-color: rgba(0, 0, 0, 0.5);width: 100%;height: 100%;display: none;}</style>
<style>
.MathJax, .MathJax_Message, .MathJax_Preview{
display: none
}
</style>
<style type="text/css">pre{position: relative}pre:hover .hljs-button{display: block}.hljs-button{display: none;position: absolute;right: 4px;top: 4px;font-size: 12px;color: #4d4d4d;background-color: white;padding: 2px 8px;margin: 8px;border-radius: 4px;cursor: pointer; box-shadow: 0 2px 4px rgba(0,0,0,0.05), 0 2px 4px rgba(0,0,0,0.05);}.hljs-button:after{content: attr(data-title)}code .hljs-button{margin: 2px 8px;}</style>
<style type="text/css">.hljs-ln{border-collapse:collapse} .hljs-ln td{padding:0} .hljs-ln-n{text-align: right;padding-right: 8px;} .hljs-ln-n:before{content:attr(data-line-number)}</style>
<style type="text/css">.MathJax_Hover_Frame {border-radius: .25em; -webkit-border-radius: .25em; -moz-border-radius: .25em; -khtml-border-radius: .25em; box-shadow: 0px 0px 15px #83A; -webkit-box-shadow: 0px 0px 15px #83A; -moz-box-shadow: 0px 0px 15px #83A; -khtml-box-shadow: 0px 0px 15px #83A; border: 1px solid #A6D ! important; display: inline-block; position: absolute}
.MathJax_Menu_Button .MathJax_Hover_Arrow {position: absolute; cursor: pointer; display: inline-block; border: 2px solid #AAA; border-radius: 4px; -webkit-border-radius: 4px; -moz-border-radius: 4px; -khtml-border-radius: 4px; font-family: 'Courier New',Courier; font-size: 9px; color: #F0F0F0}
.MathJax_Menu_Button .MathJax_Hover_Arrow span {display: block; background-color: #AAA; border: 1px solid; border-radius: 3px; line-height: 0; padding: 4px}
.MathJax_Hover_Arrow:hover {color: white!important; border: 2px solid #CCC!important}
.MathJax_Hover_Arrow:hover span {background-color: #CCC!important}
</style>
<style type="text/css">#MathJax_About {position: fixed; left: 50%; width: auto; text-align: center; border: 3px outset; padding: 1em 2em; background-color: #DDDDDD; color: black; cursor: default; font-family: message-box; font-size: 120%; font-style: normal; text-indent: 0; text-transform: none; line-height: normal; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; z-index: 201; border-radius: 15px; -webkit-border-radius: 15px; -moz-border-radius: 15px; -khtml-border-radius: 15px; box-shadow: 0px 10px 20px #808080; -webkit-box-shadow: 0px 10px 20px #808080; -moz-box-shadow: 0px 10px 20px #808080; -khtml-box-shadow: 0px 10px 20px #808080; filter: progid:DXImageTransform.Microsoft.dropshadow(OffX=2, OffY=2, Color='gray', Positive='true')}
#MathJax_About.MathJax_MousePost {outline: none}
.MathJax_Menu {position: absolute; background-color: white; color: black; width: auto; padding: 5px 0px; border: 1px solid #CCCCCC; margin: 0; cursor: default; font: menu; text-align: left; text-indent: 0; text-transform: none; line-height: normal; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; z-index: 201; border-radius: 5px; -webkit-border-radius: 5px; -moz-border-radius: 5px; -khtml-border-radius: 5px; box-shadow: 0px 10px 20px #808080; -webkit-box-shadow: 0px 10px 20px #808080; -moz-box-shadow: 0px 10px 20px #808080; -khtml-box-shadow: 0px 10px 20px #808080; filter: progid:DXImageTransform.Microsoft.dropshadow(OffX=2, OffY=2, Color='gray', Positive='true')}
.MathJax_MenuItem {padding: 1px 2em; background: transparent}
.MathJax_MenuArrow {position: absolute; right: .5em; padding-top: .25em; color: #666666; font-size: .75em}
.MathJax_MenuActive .MathJax_MenuArrow {color: white}
.MathJax_MenuArrow.RTL {left: .5em; right: auto}
.MathJax_MenuCheck {position: absolute; left: .7em}
.MathJax_MenuCheck.RTL {right: .7em; left: auto}
.MathJax_MenuRadioCheck {position: absolute; left: .7em}
.MathJax_MenuRadioCheck.RTL {right: .7em; left: auto}
.MathJax_MenuLabel {padding: 1px 2em 3px 1.33em; font-style: italic}
.MathJax_MenuRule {border-top: 1px solid #DDDDDD; margin: 4px 3px}
.MathJax_MenuDisabled {color: GrayText}
.MathJax_MenuActive {background-color: #606872; color: white}
.MathJax_MenuDisabled:focus, .MathJax_MenuLabel:focus {background-color: #E8E8E8}
.MathJax_ContextMenu:focus {outline: none}
.MathJax_ContextMenu .MathJax_MenuItem:focus {outline: none}
#MathJax_AboutClose {top: .2em; right: .2em}
.MathJax_Menu .MathJax_MenuClose {top: -10px; left: -10px}
.MathJax_MenuClose {position: absolute; cursor: pointer; display: inline-block; border: 2px solid #AAA; border-radius: 18px; -webkit-border-radius: 18px; -moz-border-radius: 18px; -khtml-border-radius: 18px; font-family: 'Courier New',Courier; font-size: 24px; color: #F0F0F0}
.MathJax_MenuClose span {display: block; background-color: #AAA; border: 1.5px solid; border-radius: 18px; -webkit-border-radius: 18px; -moz-border-radius: 18px; -khtml-border-radius: 18px; line-height: 0; padding: 8px 0 6px}
.MathJax_MenuClose:hover {color: white!important; border: 2px solid #CCC!important}
.MathJax_MenuClose:hover span {background-color: #CCC!important}
.MathJax_MenuClose:hover:focus {outline: none}
</style>
<style type="text/css">.MathJax_Preview .MJXf-math {color: inherit!important}
</style>
<style type="text/css">.MJX_Assistive_MathML {position: absolute!important; top: 0; left: 0; clip: rect(1px, 1px, 1px, 1px); padding: 1px 0 0 0!important; border: 0!important; height: 1px!important; width: 1px!important; overflow: hidden!important; display: block!important; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none}
.MJX_Assistive_MathML.MJX_Assistive_MathML_Block {width: 100%!important}
</style>
<style type="text/css">#MathJax_Zoom {position: absolute; background-color: #F0F0F0; overflow: auto; display: block; z-index: 301; padding: .5em; border: 1px solid black; margin: 0; font-weight: normal; font-style: normal; text-align: left; text-indent: 0; text-transform: none; line-height: normal; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; -webkit-box-sizing: content-box; -moz-box-sizing: content-box; box-sizing: content-box; box-shadow: 5px 5px 15px #AAAAAA; -webkit-box-shadow: 5px 5px 15px #AAAAAA; -moz-box-shadow: 5px 5px 15px #AAAAAA; -khtml-box-shadow: 5px 5px 15px #AAAAAA; filter: progid:DXImageTransform.Microsoft.dropshadow(OffX=2, OffY=2, Color='gray', Positive='true')}
#MathJax_ZoomOverlay {position: absolute; left: 0; top: 0; z-index: 300; display: inline-block; width: 100%; height: 100%; border: 0; padding: 0; margin: 0; background-color: white; opacity: 0; filter: alpha(opacity=0)}
#MathJax_ZoomFrame {position: relative; display: inline-block; height: 0; width: 0}
#MathJax_ZoomEventTrap {position: absolute; left: 0; top: 0; z-index: 302; display: inline-block; border: 0; padding: 0; margin: 0; background-color: white; opacity: 0; filter: alpha(opacity=0)}
</style>
<style type="text/css">.MathJax_Preview {color: #888}
#MathJax_Message {position: fixed; left: 1em; bottom: 1.5em; background-color: #E6E6E6; border: 1px solid #959595; margin: 0px; padding: 2px 8px; z-index: 102; color: black; font-size: 80%; width: auto; white-space: nowrap}
#MathJax_MSIE_Frame {position: absolute; top: 0; left: 0; width: 0px; z-index: 101; border: 0px; margin: 0px; padding: 0px}
.MathJax_Error {color: #CC0000; font-style: italic}
</style>
<style type="text/css"></style>
<style type="text/css"></style>
<style type="text/css"></style>
<style type="text/css"></style>
<style type="text/css"></style>
<style type="text/css"></style>
<style type="text/css"></style>
<style type="text/css"></style>
<style type="text/css"></style>
<style type="text/css"></style>
<style type="text/css"></style>
<style type="text/css">.MJXp-script {font-size: .8em}
.MJXp-right {-webkit-transform-origin: right; -moz-transform-origin: right; -ms-transform-origin: right; -o-transform-origin: right; transform-origin: right}
.MJXp-bold {font-weight: bold}
.MJXp-italic {font-style: italic}
.MJXp-scr {font-family: MathJax_Script,'Times New Roman',Times,STIXGeneral,serif}
.MJXp-frak {font-family: MathJax_Fraktur,'Times New Roman',Times,STIXGeneral,serif}
.MJXp-sf {font-family: MathJax_SansSerif,'Times New Roman',Times,STIXGeneral,serif}
.MJXp-cal {font-family: MathJax_Caligraphic,'Times New Roman',Times,STIXGeneral,serif}
.MJXp-mono {font-family: MathJax_Typewriter,'Times New Roman',Times,STIXGeneral,serif}
.MJXp-largeop {font-size: 150%}
.MJXp-largeop.MJXp-int {vertical-align: -.2em}
.MJXp-math {display: inline-block; line-height: 1.2; text-indent: 0; font-family: 'Times New Roman',Times,STIXGeneral,serif; white-space: nowrap; border-collapse: collapse}
.MJXp-display {display: block; text-align: center; margin: 1em 0}
.MJXp-math span {display: inline-block}
.MJXp-box {display: block!important; text-align: center}
.MJXp-box:after {content: " "}
.MJXp-rule {display: block!important; margin-top: .1em}
.MJXp-char {display: block!important}
.MJXp-mo {margin: 0 .15em}
.MJXp-mfrac {margin: 0 .125em; vertical-align: .25em}
.MJXp-denom {display: inline-table!important; width: 100%}
.MJXp-denom > * {display: table-row!important}
.MJXp-surd {vertical-align: top}
.MJXp-surd > * {display: block!important}
.MJXp-script-box > * {display: table!important; height: 50%}
.MJXp-script-box > * > * {display: table-cell!important; vertical-align: top}
.MJXp-script-box > *:last-child > * {vertical-align: bottom}
.MJXp-script-box > * > * > * {display: block!important}
.MJXp-mphantom {visibility: hidden}
.MJXp-munderover {display: inline-table!important}
.MJXp-over {display: inline-block!important; text-align: center}
.MJXp-over > * {display: block!important}
.MJXp-munderover > * {display: table-row!important}
.MJXp-mtable {vertical-align: .25em; margin: 0 .125em}
.MJXp-mtable > * {display: inline-table!important; vertical-align: middle}
.MJXp-mtr {display: table-row!important}
.MJXp-mtd {display: table-cell!important; text-align: center; padding: .5em 0 0 .5em}
.MJXp-mtr > .MJXp-mtd:first-child {padding-left: 0}
.MJXp-mtr:first-child > .MJXp-mtd {padding-top: 0}
.MJXp-mlabeledtr {display: table-row!important}
.MJXp-mlabeledtr > .MJXp-mtd:first-child {padding-left: 0}
.MJXp-mlabeledtr:first-child > .MJXp-mtd {padding-top: 0}
.MJXp-merror {background-color: #FFFF88; color: #CC0000; border: 1px solid #CC0000; padding: 1px 3px; font-style: normal; font-size: 90%}
.MJXp-scale0 {-webkit-transform: scaleX(.0); -moz-transform: scaleX(.0); -ms-transform: scaleX(.0); -o-transform: scaleX(.0); transform: scaleX(.0)}
.MJXp-scale1 {-webkit-transform: scaleX(.1); -moz-transform: scaleX(.1); -ms-transform: scaleX(.1); -o-transform: scaleX(.1); transform: scaleX(.1)}
.MJXp-scale2 {-webkit-transform: scaleX(.2); -moz-transform: scaleX(.2); -ms-transform: scaleX(.2); -o-transform: scaleX(.2); transform: scaleX(.2)}
.MJXp-scale3 {-webkit-transform: scaleX(.3); -moz-transform: scaleX(.3); -ms-transform: scaleX(.3); -o-transform: scaleX(.3); transform: scaleX(.3)}
.MJXp-scale4 {-webkit-transform: scaleX(.4); -moz-transform: scaleX(.4); -ms-transform: scaleX(.4); -o-transform: scaleX(.4); transform: scaleX(.4)}
.MJXp-scale5 {-webkit-transform: scaleX(.5); -moz-transform: scaleX(.5); -ms-transform: scaleX(.5); -o-transform: scaleX(.5); transform: scaleX(.5)}
.MJXp-scale6 {-webkit-transform: scaleX(.6); -moz-transform: scaleX(.6); -ms-transform: scaleX(.6); -o-transform: scaleX(.6); transform: scaleX(.6)}
.MJXp-scale7 {-webkit-transform: scaleX(.7); -moz-transform: scaleX(.7); -ms-transform: scaleX(.7); -o-transform: scaleX(.7); transform: scaleX(.7)}
.MJXp-scale8 {-webkit-transform: scaleX(.8); -moz-transform: scaleX(.8); -ms-transform: scaleX(.8); -o-transform: scaleX(.8); transform: scaleX(.8)}
.MJXp-scale9 {-webkit-transform: scaleX(.9); -moz-transform: scaleX(.9); -ms-transform: scaleX(.9); -o-transform: scaleX(.9); transform: scaleX(.9)}
.MathJax_PHTML .noError {vertical-align: ; font-size: 90%; text-align: left; color: black; padding: 1px 3px; border: 1px solid}
</style>
<style type="text/css">#rwl-iqxin{position:fixed;transform:translate(-95px,0);width:85px;height:25px;font-size:12px;font-weight: 500;font-family:Verdana, Arial, '宋体';color:#fff;background:#333;z-index:2147483647;margin: 0;opacity:0.05;transition:0.3s;overflow:hidden;user-select:none;text-align:center;white-space:nowrap;line-height:25px;padding:0 16px;border:1px solid #ccc;border-width:1px 1px 1px 0;border-bottom-right-radius:5px;box-sizing: content-box;}#rwl-iqxin input{margin: 0;padding: 0;vertical-align:middle;-webkit-appearance:checkbox;-moz-appearance:checkbox;position: static;clip: auto;opacity: 1;cursor: pointer;}#rwl-iqxin.rwl-active-iqxin{left: 0px;transform:translate(0,0);opacity: 0.9;height: 32px;line-height: 32px}#rwl-iqxin label{margin:0;padding:0;font-weight:500;}#rwl-iqxin #rwl-setbtn{margin: 0 4px 0 0;padding: 0 0 0 4px;border: none;border-radius: 2px;cursor: pointer;background: #fff;color: #000;} </style>
<style type="text/css"></style>
<style type="text/css"></style>
<style>.imgViewDom{display:none;position:fixed;top:0;left:0;height:100%;width:100%;z-index:99999999;background: rgba(255, 255, 255,0.8);overflow: auto;display:-webkit-box;-webkit-box-align:center;-webkit-box-pack:center;display:-moz-box;-moz-box-align:center;-moz-box-pack:center;display:-o-box;-o-box-align:center;-o-box-pack:center;display:-ms-box;-ms-box-align:center;-ms-box-pack:center; display:box;box-align:center;box-pack:center;}.imgViewDom img{cursor: zoom-out;}</style>
<style class="mx-wc-style">
body {padding-top: 20px;}
.mx-wc-main img {max-width: 100%;}
.mx-wc-main{
box-sizing: content-box;
background-color: rgb(245, 246, 247) !important;
margin: 0 auto;
max-width: 980px;
}
@media (min-width: 768px) {
.mx-wc-main { padding: 15px 15px 80px 15px }
}
@media (max-width: 767px) {
.mx-wc-main { padding: 15px 3px 80px 3px }
}
</style>
</head>
<body style="background-color: #464646 !important; min-height: 100%; height: auto; position: static !important; overflow: auto !important; padding-bottom: 0px !important;" id="" class="nodata ">
<div class="mx-wc-main">
<DIV class="main_father clearfix d-flex justify-content-center" style="height: 100%;display: block !important;float: none !important;position: relative !important;top: 0 !important;left: 0 !important;border: 0px !important;width: 100% !important;min-width: 100% !important;max-width: 100% !important;height: auto !important;min-height: auto !important;max-height: 100% !important;margin: 0px !important;padding: 0px !important;"><DIV class="container clearfix" id="mainBox" style="display: block !important;float: none !important;position: relative !important;top: 0 !important;left: 0 !important;border: 0px !important;width: 100% !important;min-width: 100% !important;max-width: 100% !important;height: auto !important;min-height: auto !important;max-height: 100% !important;margin: 0px !important;padding: 0px !important;"><MAIN style="display: block !important;float: none !important;position: relative !important;top: 0 !important;left: 0 !important;border: 0px !important;width: 100% !important;min-width: 100% !important;max-width: 100% !important;height: auto !important;min-height: auto !important;max-height: 100% !important;margin: 0px !important;padding: 0px !important;"><DIV class="blog-content-box" style="display: block !important;float: none !important;position: relative !important;top: 0 !important;left: 0 !important;border: 0px !important;width: 100% !important;min-width: 100% !important;max-width: 100% !important;height: auto !important;min-height: auto !important;max-height: 100% !important;margin: 0px !important;padding: 0px !important;"><ARTICLE class="baidu_pl" style="display: block !important;float: none !important;position: relative !important;top: 0 !important;left: 0 !important;border: 0px !important;width: 100% !important;min-width: 100% !important;max-width: 100% !important;height: auto !important;min-height: auto !important;max-height: 100% !important;margin: 0px !important;padding: 0px !important;"><DIV id="article_content" class="article_content clearfix" style="display: block !important;float: none !important;position: relative !important;top: 0 !important;left: 0 !important;border: 0px !important;width: 100% !important;min-width: 100% !important;max-width: 100% !important;height: auto !important;min-height: auto !important;max-height: 100% !important;margin: 0px !important;padding: 0px !important;"><div class="htmledit_views mx-wc-selected-elem" id="content_views" style="display: block; float: none !important; position: relative !important; top: 0px !important; left: 0px !important; margin: 0px !important; flex: unset !important; width: 100% !important; max-width: 100% !important;">
<p style="text-indent:50px;">最近公司有个视频的项目,需要调用FFMPEG的API来实现部分功能,这么多语言用下来,还是C#最舒服,所以就还是希望用C#来写,但C#不能直接调用ffmpeg的静态库,动态库又得采用pinvoke方式,ffmpeg那么多API,还涉及类型转换,要完全实现工作量真不小,开源项目<a href="http://www.baidu.com/link?url=X24d3bnuEtlk69dOLoB-d01xybEA6DgSdtrxTDLaL5TEb-zG6zDBzznZyYC_yNaLvMpWt9E_BwJ2vTj32W4ejK" rel="noopener noreferrer" target="_blank" referrerpolicy="no-referrer">SharpFFmpeg</a>也很久没更新了,版本太老,正要自己实现的时候发现了ffmpeg.autogen这个项目,几乎是全部支持ffmpeg的API,而且一直在更新,所以就采用了这个项目,用下来还真不错。啰嗦了这么多,还是上个简单的例子 。</p>
<p> </p>
<p><strong>FFmpeg拉取RTMP流并播放</strong></p>
<p> </p>
<p> </p>
<ul><li>1. 项目添加ffmpeg.autogen引用,nuget可以直接获取到,因为我用的FFmpeg是3.4版本,ffmpeg.autogen也用的3.4版本,如图。</li>
</ul><p><img alt="" class="has" height="782" src="assets/1585390350-a952d88e80e4c56e6e88806609c6d51d.png" width="1200"></p>
<p> </p>
<ul><li>2.创建一个frmPlayer窗体,来显示图像,为了方便,我这里用一个PictureBox来显示图像。</li>
</ul><p>FFmpeg解码后是YUV图像,需通过sws_scale转会成RGB,然后构造成 System.Drawing.Bitmap给PictureBox显示。</p>
<p><img alt="" class="has" height="509" src="assets/1585390350-b7dcca5cc9617921f5670974956c443d.png" width="1045"></p>
<p> </p>
<ul><li>3. FFmpeg拉流和解码类 里面有详细注释。</li>
</ul><pre class="has" name="code"><code class="language-cs hljs"><ol class="hljs-ln hundred" style="width:1252px"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">using</span> FFmpeg.AutoGen;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">using</span> System;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">using</span> System.Drawing;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">using</span> System.Drawing.Imaging;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">using</span> System.Runtime.InteropServices;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">namespace</span> <span class="hljs-title">FFmpegDemo</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">{</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">public</span> <span class="hljs-keyword">unsafe</span> <span class="hljs-keyword">class</span> <span class="hljs-title">tstRtmp</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"><summary></span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment"><span class="hljs-doctag">///</span> 显示图片委托</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"></summary></span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"><param name="bitmap"></span><span class="hljs-doctag"></param></span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="16"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">delegate</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ShowBitmap</span>(<span class="hljs-params">Bitmap bitmap</span>)</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="17"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"><summary></span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="18"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment"><span class="hljs-doctag">///</span> 执行控制变量</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="19"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"></summary></span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="20"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">bool</span> CanRun;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="21"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"><summary></span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="22"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment"><span class="hljs-doctag">///</span> 对读取的264数据包进行解码和转换</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="23"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"></summary></span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="24"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"><param name="show"></span>解码完成回调函数<span class="hljs-doctag"></param></span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="25"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"><param name="url"></span>播放地址,也可以是本地文件地址<span class="hljs-doctag"></param></span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="26"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">unsafe</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Start</span>(<span class="hljs-params">ShowBitmap show, <span class="hljs-keyword">string</span> url</span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="27"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="28"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> CanRun = <span class="hljs-literal">true</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="29"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="30"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> Console.WriteLine(<span class="hljs-string">@"Current directory: "</span> + Environment.CurrentDirectory);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="31"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> Console.WriteLine(<span class="hljs-string">@"Runnung in {0}-bit mode."</span>, Environment.Is64BitProcess ? <span class="hljs-string">@"64"</span> : <span class="hljs-string">@"32"</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="32"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment">//FFmpegDLL目录查找和设置</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="33"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> FFmpegBinariesHelper.RegisterFFmpegBinaries();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="34"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="35"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-meta">#<span class="hljs-meta-keyword">region</span> ffmpeg 初始化</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="36"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment">// 初始化注册ffmpeg相关的编码器</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="37"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> ffmpeg.av_register_all();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="38"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> ffmpeg.avcodec_register_all();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="39"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> ffmpeg.avformat_network_init();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="40"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="41"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> Console.WriteLine(<span class="hljs-string">$"FFmpeg version info: <span class="hljs-subst">{ffmpeg.av_version_info()}</span>"</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="42"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-meta">#<span class="hljs-meta-keyword">endregion</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="43"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="44"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-meta">#<span class="hljs-meta-keyword">region</span> ffmpeg 日志</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="45"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment">// 设置记录ffmpeg日志级别</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="46"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> ffmpeg.av_log_set_level(ffmpeg.AV_LOG_VERBOSE);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="47"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> av_log_set_callback_callback logCallback = (p0, level, format, vl) =></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="48"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="49"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">if</span> (level > ffmpeg.av_log_get_level()) <span class="hljs-keyword">return</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="50"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="51"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">var</span> lineSize = <span class="hljs-number">1024</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="52"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">var</span> lineBuffer = <span class="hljs-keyword">stackalloc</span> <span class="hljs-keyword">byte</span>[lineSize];</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="53"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">var</span> printPrefix = <span class="hljs-number">1</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="54"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> ffmpeg.av_log_format_line(p0, level, format, vl, lineBuffer, lineSize, &printPrefix);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="55"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">var</span> line = Marshal.PtrToStringAnsi((IntPtr)lineBuffer);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="56"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> Console.Write(line);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="57"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> };</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="58"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> ffmpeg.av_log_set_callback(logCallback);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="59"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="60"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-meta">#<span class="hljs-meta-keyword">endregion</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="61"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="62"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-meta">#<span class="hljs-meta-keyword">region</span> ffmpeg 转码</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="63"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="64"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="65"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment">// 分配音视频格式上下文</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="66"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">var</span> pFormatContext = ffmpeg.avformat_alloc_context();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="67"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="68"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">int</span> error;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="69"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="70"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment">//打开流</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="71"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> error = ffmpeg.avformat_open_input(&pFormatContext, url, <span class="hljs-literal">null</span>, <span class="hljs-literal">null</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="72"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">if</span> (error != <span class="hljs-number">0</span>) <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> ApplicationException(GetErrorMessage(error));</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="73"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="74"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment">// 读取媒体流信息</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="75"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> error = ffmpeg.avformat_find_stream_info(pFormatContext, <span class="hljs-literal">null</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="76"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">if</span> (error != <span class="hljs-number">0</span>) <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> ApplicationException(GetErrorMessage(error));</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="77"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="78"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment">// 这里只是为了打印些视频参数</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="79"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> AVDictionaryEntry* tag = <span class="hljs-literal">null</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="80"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">while</span> ((tag = ffmpeg.av_dict_get(pFormatContext->metadata, <span class="hljs-string">""</span>, tag, ffmpeg.AV_DICT_IGNORE_SUFFIX)) != <span class="hljs-literal">null</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="81"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="82"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">var</span> key = Marshal.PtrToStringAnsi((IntPtr)tag->key);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="83"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">var</span> <span class="hljs-keyword">value</span> = Marshal.PtrToStringAnsi((IntPtr)tag-><span class="hljs-keyword">value</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="84"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> Console.WriteLine(<span class="hljs-string">$"<span class="hljs-subst">{key}</span> = <span class="hljs-subst">{<span class="hljs-keyword">value</span>}</span>"</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="85"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="86"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="87"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment">// 从格式化上下文获取流索引</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="88"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> AVStream* pStream = <span class="hljs-literal">null</span>, aStream;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="89"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = <span class="hljs-number">0</span>; i < pFormatContext->nb_streams; i++)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="90"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="91"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">if</span> (pFormatContext->streams[i]->codec->codec_type == AVMediaType.AVMEDIA_TYPE_VIDEO)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="92"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="93"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> pStream = pFormatContext->streams[i];</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="94"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="95"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="96"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (pFormatContext->streams[i]->codec->codec_type == AVMediaType.AVMEDIA_TYPE_AUDIO)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="97"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="98"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> aStream = pFormatContext->streams[i];</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="99"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="100"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="101"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="102"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">if</span> (pStream == <span class="hljs-literal">null</span>) <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> ApplicationException(<span class="hljs-string">@"Could not found video stream."</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="103"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="104"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment">// 获取流的编码器上下文</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="105"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">var</span> codecContext = *pStream->codec;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="106"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="107"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> Console.WriteLine(<span class="hljs-string">$"codec name: <span class="hljs-subst">{ffmpeg.avcodec_get_name(codecContext.codec_id)}</span>"</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="108"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment">// 获取图像的宽、高及像素格式</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="109"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">var</span> width = codecContext.width;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="110"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">var</span> height = codecContext.height;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="111"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">var</span> sourcePixFmt = codecContext.pix_fmt;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="112"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="113"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment">// 得到编码器ID</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="114"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">var</span> codecId = codecContext.codec_id;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="115"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment">// 目标像素格式</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="116"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">var</span> destinationPixFmt = AVPixelFormat.AV_PIX_FMT_BGR24;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="117"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="118"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="119"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment">// 某些264格式codecContext.pix_fmt获取到的格式是AV_PIX_FMT_NONE 统一都认为是YUV420P</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="120"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">if</span> (sourcePixFmt == AVPixelFormat.AV_PIX_FMT_NONE && codecId == AVCodecID.AV_CODEC_ID_H264)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="121"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="122"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> sourcePixFmt = AVPixelFormat.AV_PIX_FMT_YUV420P;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="123"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="124"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="125"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment">// 得到SwsContext对象:用于图像的缩放和转换操作</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="126"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">var</span> pConvertContext = ffmpeg.sws_getContext(width, height, sourcePixFmt,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="127"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> width, height, destinationPixFmt,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="128"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> ffmpeg.SWS_FAST_BILINEAR, <span class="hljs-literal">null</span>, <span class="hljs-literal">null</span>, <span class="hljs-literal">null</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="129"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">if</span> (pConvertContext == <span class="hljs-literal">null</span>) <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> ApplicationException(<span class="hljs-string">@"Could not initialize the conversion context."</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="130"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="131"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment">//分配一个默认的帧对象:AVFrame</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="132"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">var</span> pConvertedFrame = ffmpeg.av_frame_alloc();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="133"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment">// 目标媒体格式需要的字节长度</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="134"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">var</span> convertedFrameBufferSize = ffmpeg.av_image_get_buffer_size(destinationPixFmt, width, height, <span class="hljs-number">1</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="135"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment">// 分配目标媒体格式内存使用</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="136"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">var</span> convertedFrameBufferPtr = Marshal.AllocHGlobal(convertedFrameBufferSize);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="137"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">var</span> dstData = <span class="hljs-keyword">new</span> byte_ptrArray4();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="138"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">var</span> dstLinesize = <span class="hljs-keyword">new</span> int_array4();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="139"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment">// 设置图像填充参数</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="140"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> ffmpeg.av_image_fill_arrays(<span class="hljs-keyword">ref</span> dstData, <span class="hljs-keyword">ref</span> dstLinesize, (<span class="hljs-keyword">byte</span>*)convertedFrameBufferPtr, destinationPixFmt, width, height, <span class="hljs-number">1</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="141"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="142"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-meta">#<span class="hljs-meta-keyword">endregion</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="143"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="144"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-meta">#<span class="hljs-meta-keyword">region</span> ffmpeg 解码</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="145"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment">// 根据编码器ID获取对应的解码器</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="146"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">var</span> pCodec = ffmpeg.avcodec_find_decoder(codecId);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="147"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">if</span> (pCodec == <span class="hljs-literal">null</span>) <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> ApplicationException(<span class="hljs-string">@"Unsupported codec."</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="148"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="149"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">var</span> pCodecContext = &codecContext;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="150"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="151"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">if</span> ((pCodec->capabilities & ffmpeg.AV_CODEC_CAP_TRUNCATED) == ffmpeg.AV_CODEC_CAP_TRUNCATED)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="152"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> pCodecContext->flags |= ffmpeg.AV_CODEC_FLAG_TRUNCATED;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="153"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="154"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment">// 通过解码器打开解码器上下文:AVCodecContext pCodecContext</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="155"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> error = ffmpeg.avcodec_open2(pCodecContext, pCodec, <span class="hljs-literal">null</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="156"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">if</span> (error < <span class="hljs-number">0</span>) <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> ApplicationException(GetErrorMessage(error));</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="157"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="158"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment">// 分配解码帧对象:AVFrame pDecodedFrame</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="159"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">var</span> pDecodedFrame = ffmpeg.av_frame_alloc();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="160"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="161"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment">// 初始化媒体数据包</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="162"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">var</span> packet = <span class="hljs-keyword">new</span> AVPacket();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="163"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">var</span> pPacket = &packet;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="164"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> ffmpeg.av_init_packet(pPacket);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="165"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="166"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">var</span> frameNumber = <span class="hljs-number">0</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="167"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">while</span> (CanRun)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="168"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="169"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">try</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="170"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="171"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">do</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="172"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="173"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment">// 读取一帧未解码数据</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="174"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> error = ffmpeg.av_read_frame(pFormatContext, pPacket);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="175"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> Console.WriteLine(pPacket->dts);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="176"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">if</span> (error == ffmpeg.AVERROR_EOF) <span class="hljs-keyword">break</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="177"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">if</span> (error < <span class="hljs-number">0</span>) <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> ApplicationException(GetErrorMessage(error));</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="178"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="179"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">if</span> (pPacket->stream_index != pStream->index) <span class="hljs-keyword">continue</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="180"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="181"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment">// 解码</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="182"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> error = ffmpeg.avcodec_send_packet(pCodecContext, pPacket);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="183"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">if</span> (error < <span class="hljs-number">0</span>) <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> ApplicationException(GetErrorMessage(error));</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="184"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment">// 解码输出解码数据</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="185"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> error = ffmpeg.avcodec_receive_frame(pCodecContext, pDecodedFrame);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="186"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> } <span class="hljs-keyword">while</span> (error == ffmpeg.AVERROR(ffmpeg.EAGAIN) && CanRun);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="187"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">if</span> (error == ffmpeg.AVERROR_EOF) <span class="hljs-keyword">break</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="188"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">if</span> (error < <span class="hljs-number">0</span>) <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> ApplicationException(GetErrorMessage(error));</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="189"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="190"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">if</span> (pPacket->stream_index != pStream->index) <span class="hljs-keyword">continue</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="191"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="192"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> Console.WriteLine(<span class="hljs-string">$@"frame: <span class="hljs-subst">{frameNumber}</span>"</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="193"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment">// YUV->RGB</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="194"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> ffmpeg.sws_scale(pConvertContext, pDecodedFrame->data, pDecodedFrame->linesize, <span class="hljs-number">0</span>, height, dstData, dstLinesize);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="195"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="196"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">finally</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="197"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="198"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> ffmpeg.av_packet_unref(pPacket);<span class="hljs-comment">//释放数据包对象引用</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="199"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> ffmpeg.av_frame_unref(pDecodedFrame);<span class="hljs-comment">//释放解码帧对象引用</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="200"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="201"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="202"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment">// 封装Bitmap图片</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="203"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">var</span> bitmap = <span class="hljs-keyword">new</span> Bitmap(width, height, dstLinesize[<span class="hljs-number">0</span>], PixelFormat.Format24bppRgb, convertedFrameBufferPtr);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="204"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment">// 回调</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="205"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> show(bitmap);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="206"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment">//bitmap.Save(AppDomain.CurrentDomain.BaseDirectory + "\\264\\frame.buffer."+ frameNumber + ".jpg", ImageFormat.Jpeg);</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="207"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="208"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> frameNumber++;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="209"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="210"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment">//播放完置空播放图片 </span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="211"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> show(<span class="hljs-literal">null</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="212"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="213"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-meta">#<span class="hljs-meta-keyword">endregion</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="214"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="215"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-meta">#<span class="hljs-meta-keyword">region</span> 释放资源</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="216"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> Marshal.FreeHGlobal(convertedFrameBufferPtr);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="217"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> ffmpeg.av_free(pConvertedFrame);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="218"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> ffmpeg.sws_freeContext(pConvertContext);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="219"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="220"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> ffmpeg.av_free(pDecodedFrame);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="221"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> ffmpeg.avcodec_close(pCodecContext);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="222"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> ffmpeg.avformat_close_input(&pFormatContext);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="223"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="224"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="225"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-meta">#<span class="hljs-meta-keyword">endregion</span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="226"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="227"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="228"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"><summary></span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="229"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment"><span class="hljs-doctag">///</span> 获取ffmpeg错误信息</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="230"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"></summary></span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="231"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"><param name="error"></span><span class="hljs-doctag"></param></span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="232"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"><returns></span><span class="hljs-doctag"></returns></span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="233"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">unsafe</span> <span class="hljs-keyword">string</span> <span class="hljs-title">GetErrorMessage</span>(<span class="hljs-params"><span class="hljs-keyword">int</span> error</span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="234"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="235"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">var</span> bufferSize = <span class="hljs-number">1024</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="236"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">var</span> buffer = <span class="hljs-keyword">stackalloc</span> <span class="hljs-keyword">byte</span>[bufferSize];</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="237"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> ffmpeg.av_strerror(error, buffer, (<span class="hljs-keyword">ulong</span>)bufferSize);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="238"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">var</span> message = Marshal.PtrToStringAnsi((IntPtr)buffer);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="239"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">return</span> message;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="240"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="241"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="242"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Stop</span>(<span class="hljs-params"></span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="243"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="244"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> CanRun = <span class="hljs-literal">false</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="245"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="246"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="247"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">}</div></div></li></ol></code></pre>
<p> </p>
<ul><li>4.调用代码</li>
</ul><pre class="has" name="code"><code class="language-cs hljs"><ol class="hljs-ln"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">public</span> <span class="hljs-keyword">partial</span> <span class="hljs-keyword">class</span> <span class="hljs-title">frmPlayer</span> : <span class="hljs-title">Form</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">frmPlayer</span>(<span class="hljs-params"></span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> InitializeComponent();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> tstRtmp rtmp = <span class="hljs-keyword">new</span> tstRtmp();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> Thread thPlayer;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">void</span> <span class="hljs-title">btnStart_Click</span>(<span class="hljs-params"><span class="hljs-keyword">object</span> sender, EventArgs e</span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> btnStart.Enabled = <span class="hljs-literal">false</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">if</span> (thPlayer != <span class="hljs-literal">null</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="15"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> rtmp.Stop();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="16"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="17"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> thPlayer = <span class="hljs-literal">null</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="18"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="19"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">else</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="20"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="21"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> thPlayer = <span class="hljs-keyword">new</span> Thread(DeCoding);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="22"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> thPlayer.IsBackground = <span class="hljs-literal">true</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="23"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> thPlayer.Start();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="24"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> btnStart.Text = <span class="hljs-string">"停止播放"</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="25"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> btnStart.Enabled = <span class="hljs-literal">true</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="26"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="27"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="28"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="29"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"><summary></span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="30"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment"><span class="hljs-doctag">///</span> 播放线程执行方法</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="31"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"></summary></span></span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="32"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">unsafe</span> <span class="hljs-keyword">void</span> <span class="hljs-title">DeCoding</span>(<span class="hljs-params"></span>)</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="33"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="34"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">try</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="35"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="36"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> Console.WriteLine(<span class="hljs-string">"DeCoding run..."</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="37"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> Bitmap oldBmp = <span class="hljs-literal">null</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="38"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="39"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="40"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment">// 更新图片显示</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="41"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> tstRtmp.ShowBitmap show = (bmp) =></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="42"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="43"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">this</span>.Invoke(<span class="hljs-keyword">new</span> MethodInvoker(() =></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="44"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="45"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">this</span>.pic.Image = bmp;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="46"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">if</span> (oldBmp != <span class="hljs-literal">null</span>)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="47"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="48"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> oldBmp.Dispose();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="49"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="50"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> oldBmp = bmp;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="51"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> }));</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="52"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> };</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="53"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> rtmp.Start(show, txtUrl.Text.Trim());</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="54"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="55"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="56"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">catch</span> (Exception ex)</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="57"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="58"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> Console.WriteLine(ex);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="59"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="60"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">finally</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="61"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="62"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> Console.WriteLine(<span class="hljs-string">"DeCoding exit"</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="63"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">this</span>.Invoke(<span class="hljs-keyword">new</span> MethodInvoker(() =></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="64"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="65"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> btnStart.Text = <span class="hljs-string">"开始播放"</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="66"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> btnStart.Enabled = <span class="hljs-literal">true</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="67"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> }));</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="68"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="69"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> }</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="70"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> }</div></div></li></ol></code></pre>
<p> </p>
<p> </p>
<ul><li>5.最终运行效果</li>
</ul><p><img alt="" class="has" height="504" src="assets/1585390350-e3b57d0a739c8fe05a1f77b9a84be0cd.png" width="956"></p>
<p> </p>
<ul><li> 其他说明:</li>
</ul><ol><li>构造Bitmap给PictureBox显示的方式效率比较低,可以采用SDL_NET版本直接显示YUV;</li>
<li>音频这里没处理,音频播放可以用DirectSound 或者SDL_NET;</li>
<li>因为这里用到了指针,所以在项目中需要勾选允许不安全代码;</li>
<li>网上C#调用FFmpeg的API例子很少,大多是C/C++的,因为ffmpeg.autogen的名称与FFmpeg完全一样,所以C#中可以直接复制C/C++代码,然后在FFmpeg的方法前加入 ffmpeg. 即可;</li>
<li>ffmpeg.autogen也支持.net core 和mono。</li>
</ol><p> </p>
<p>代码放到了github上</p>
<p><a href="https://github.com/vanjoge/CSharpVideoDemo" target="_blank" referrerpolicy="no-referrer" rel="noopener noreferrer">https://github.com/vanjoge/CSharpVideoDemo</a></p>
<p> </p>
<h1><a name="t0" data-mx-warn="Empty URL"></a><a href="https://download.csdn.net/download/vanjoge/10661739" target="_blank" referrerpolicy="no-referrer" rel="noopener noreferrer">点这里下载本示例代码</a></h1>
<p> </p>
</div></DIV></ARTICLE></DIV></MAIN></DIV></DIV>
</div>
</body>
</html>
OK
@CodingOX
我尝试修复了这两个问题,打包了个版本,现希望你能在有空时帮忙测试下。如下:
下载下来的文件为 Zip,安装方式见 这里
OK ,我试用下,有问题这里反馈!
@CodingOX
我尝试修复了这两个问题,打包了个版本,现希望你能在有空时帮忙测试下。如下:
下载下来的文件为 Zip,安装方式见 这里
测试了几个网站,发现没有换行的问题已修复。 但是附件的html 裁剪为 markdown 后没有了缩进,如下图所示: beta-1.zip
@CodingOX
我裁剪了你发给我的 html ,生成的 markdown 里面的代码有缩进。但是你给我的 html 文件里面找不到你截图里面的 BeanWrapper。是不是你上传附件的时候搞错了?
@CodingOX
我裁剪了你发给我的 html ,生成的 markdown 里面的代码有缩进。但是你给我的 html 文件里面找不到你截图里面的 BeanWrapper。是不是你上传附件的时候搞错了?
貌似发错了,这个才是 beta-2.zip 不过 这 2 篇文章的问题一样,都是剪裁 markdown 后没有缩进。
@CodingOX
奇怪,我裁剪下来的都是有缩进的啊,而且你给的 bata-2 里面的代码的缩进用的是 Tab (也就是 \t
)。
你用文本编辑器打开,也是这样?
@CodingOX
奇怪,我裁剪下来的都是有缩进的啊,而且你给的 bata-2 里面的代码的缩进用的是 Tab (也就是
\t
)。你用文本编辑器打开,也是这样?
从下图的名字来看,你给的是 beta-1
我上条回复指的是你最后传的附件 beta-2.zip(怪我,没说清楚) 。我使用了 MaoXian 0.1.52 和 0.1.53-beta1 在 Firefox 和 Chrome 上都没能重现问题,也没有找到可能产生该行为的代码。
我上条回复指的是你最后传的附件 beta-2.zip(怪我,没说清楚) 。我使用了 MaoXian 0.1.52 和 0.1.53-beta1 在 Firefox 和 Chrome 上都没能重现问题,也没有找到可能产生该行为的代码。
我在windows 下测试效果还是没有缩进,很奇怪,原文地址是:https://blog.csdn.net/qq_41907991/article/details/105214244 通过vscode查看也是没有缩进的
你把裁剪方式改为浏览器也是这样?
你把 support 页面的信息 copy 到这里,我看下你的配置。
@CodingOX 有可能 WizNotePlus 在将 Markdown 存入 HTML 时,\t
被 HTML 自动删除掉了。你最好用 mx-wc “浏览器” 保存下来看看。
你把裁剪方式改为浏览器也是这样?
剪裁缓存浏览器的 markdown 没有问题了,感觉是 wiznotePlus 的原因!
@CodingOX 有可能 WizNotePlus 在将 Markdown 存入 HTML 时,
\t
被 HTML 自动删除掉了。你最好用 mx-wc “浏览器” 保存下来看看。
用浏览器没有该问题产生,看来是 WizNotePlus 的问题,这个怎么办!?
用浏览器没有该问题产生,看来是 WizNotePlus 的问题,这个怎么办!?
我大概知道问题的原因了,等我修复吧。
@altairwei
现在 WiznotePlus 是在 MaoXian 这边先把 markdown 嵌入成 html,再在 WiznotePlus 客户端那边转成 Markdown? 还是说是 Wiznote 服务器那边转成 Markdown 的?
@altairwei
现在 WiznotePlus 是在 MaoXian 这边先把 markdown 嵌入成 html,再在 WiznotePlus 客户端那边转成 Markdown? 还是说是 Wiznote 服务器那边转成 Markdown 的?
WizNote 服务端储存架构就只允许纯粹的 HTML 文件,所以官方支持 Markdown 的方式就是将其储存到 HTML 中,客户端编辑器从 HTML 中将 Markdown 提取出来再渲染。因为 HTML 有很多保留字符,所以这种方式就会导致大量的字符编码和转义问题。
WizNote 服务端储存架构就只允许纯粹的 HTML 文件,所以官方支持 Markdown 的方式就是将其储存到 HTML 中,客户端编辑器从 HTML 中将 Markdown 提取出来再渲染。因为 HTML 有很多保留字符,所以这种方式就会导致大量的字符编码和转义问题。
把 Markdown 存进去 HTML,用 <pre><code>$markdownText</code></pre>
应该可以避免转义问题。但是你那边可能情况比较复杂,需要兼容官方的客户端吧。
把 Markdown 存进去 HTML,用
<pre><code>$markdownText</code></pre>
应该可以避免转义问题。但是你那边可能情况比较复杂,需要兼容官方的客户端吧。
是的,情况比较复杂。如果用户编辑 Markdown 后,客户端没有按照 <pre><code>$markdownText</code></pre>
格式包装 Markdown ,这又会造成 \t
的丢失。所以目前的解决方案就是将 \t
替换成四个 $nbsp;
。
比如:简书的网站
https://www.jianshu.com/p/5ec142a5fd8c
还有部分 CSDN 的网站!