RV1106手把手教你:ffmpeg无界面使用USB摄像头录制视频
<div class='showpostmsg'> 本帖最后由 LitchiCheng 于 2024-2-17 16:17 编辑<article data-content="[{"type":"block","id":"pqdD-1708133140446","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"dbjp-1708133140447","leaves":[{"text":"安装ffmpeg","marks":[]}]}],"state":{}}]">
<p><span style="font-size:18px;">实验过程</span></p>
<p>安装ffmpeg</p>
<pre>
<code>sudo apt update
sudo apt install ffmpeg</code></pre>
<article data-content="[{"type":"block","id":"HXaK-1708133088017","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"zsSL-1708133088016","leaves":[{"text":"录制视频的指令,usb摄像头为/dev/video0","marks":[]}]}],"state":{}}]">
<p>插入usb摄像头为,对应的设备为/dev/video0,需要更新内核配置和设备树的USB模式为host,参考</p>
<p><a href="https://bbs.eeworld.com.cn/thread-1271075-1-1.html">rv1106开发板配置TypeC接口USB Host并识别USB设备 - 国产芯片交流 - 电子工程世界-论坛 (eeworld.com.cn)</a></p>
<p> </p>
<p>ffmpeg的参数说明</p>
<article data-content="[{"type":"block","id":"5JJH-1708132523065","name":"quote","data":{},"nodes":[{"type":"block","id":"pFO7-1708077143609","name":"paragraph","data":{},"nodes":[{"type":"text","id":"eMMr-1708077143608","leaves":[{"text":"-f 输出格式,使用v4l2","marks":[]}]}]},{"type":"block","id":"BoSS-1708077143611","name":"paragraph","data":{},"nodes":[{"type":"text","id":"JvC9-1708077143610","leaves":[{"text":"-s 分辨率,太大会占用过多cpu,建议比较小","marks":[]}]}]},{"type":"block","id":"m98q-1708077143613","name":"paragraph","data":{},"nodes":[{"type":"text","id":"L56x-1708077143612","leaves":[{"text":"-r 帧率,需要对应摄像头支持范围","marks":[]}]}]},{"type":"block","id":"8pck-1708077143615","name":"paragraph","data":{},"nodes":[{"type":"text","id":"aQpP-1708077143614","leaves":[{"text":"-vcodec 编码方式","marks":[]}]}]},{"type":"block","id":"jvSB-1708077143617","name":"paragraph","data":{},"nodes":[{"type":"text","id":"diLA-1708077143616","leaves":[{"text":"-i 数据输入流的路径","marks":[]}]}]},{"type":"block","id":"cX3o-1708077143619","name":"paragraph","data":{},"nodes":[{"type":"text","id":"IEC8-1708077143618","leaves":[{"text":"-b:v video码率,默认1000k","marks":[]}]}]},{"type":"block","id":"smSh-1708077143621","name":"paragraph","data":{},"nodes":[{"type":"text","id":"9xxl-1708077143620","leaves":[{"text":"-an 无audio","marks":[]}]}]},{"type":"block","id":"fpZ1-1708077143625","name":"paragraph","data":{},"nodes":[{"type":"text","id":"znw2-1708077143624","leaves":[{"text":"-pix_fmt 像素格式,需要对应摄像头支持范围,如yuv420p,yuvj422p,mjpeg","marks":[]}]}]},{"type":"block","id":"i887-1708077143627","name":"paragraph","data":{},"nodes":[{"type":"text","id":"4G9l-1708077143626","leaves":[{"text":"-b:a audio码率","marks":[]}]}]},{"type":"block","id":"pAMX-1708077143629","name":"paragraph","data":{},"nodes":[{"type":"text","id":"pbuU-1708077143628","leaves":[{"text":"-vcodec libx264,转为H264编码,可以查看ffmpeg的codec支持","marks":[]}]}]},{"type":"block","id":"GucV-1708077143631","name":"paragraph","data":{},"nodes":[{"type":"text","id":"XMoU-1708077143630","leaves":[{"text":"-preset 处理模式,有ultrafast, superfast, veryfast, faster, fast, medium","marks":[]}]}]}],"state":{}}]">
<p> -f 输出格式,使用v4l2</p>
<p> -s 分辨率,太大会占用过多cpu,建议比较小</p>
<p> -r 帧率,需要对应摄像头支持范围</p>
<p> -vcodec 编码方式</p>
<p> -i 数据输入流的路径</p>
<p> -b:v video码率,默认1000k</p>
<p> -an 无audio</p>
<p> -pix_fmt 像素格式,需要对应摄像头支持范围,如yuv420p,yuvj422p,mjpeg</p>
<p> -b:a audio码率</p>
<p> -vcodec libx264,转为H264编码,可以查看ffmpeg的codec支持</p>
<p> -preset 处理模式,有ultrafast, superfast, veryfast, faster, fast, medium</p>
<p>使用如下指令进行录制,视频文件名称v1.mp4</p>
<pre>
<code>ffmpeg -f v4l2 -s 432x240 -r 30 -vcodec mjpeg -i /dev/video0 -pix_fmt yuv420p -b:v 2000k -vcodec libx264 -preset veryfast -an v1.mp4</code></pre>
<p> </p>
<article data-content="[{"type":"block","id":"wDoc-1708132528514","name":"paragraph","data":{},"nodes":[{"type":"text","id":"Dj9F-1708132528513","leaves":[{"text":"需要使用sudo权限,录像过程如上图,结束可以输出q按键或者Ctrl-C","marks":[]}]}],"state":{}}]">
<p>需要使用sudo权限,录像过程如上图,结束可以输出q按键或者Ctrl-C </p>
<article data-content="[{"type":"block","id":"ml0w-1708132652489","name":"paragraph","data":{},"nodes":[{"type":"text","id":"yeA3-1708132652487","leaves":[{"text":"文件名为","marks":[]}]}],"state":{}}]">
<p>文件名为v1.mp4</p>
<p> </p>
<article data-content="[{"type":"block","id":"YVqp-1708132595737","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"0kZZ-1708132595738","leaves":[{"text":"打开看一下","marks":[]}]}],"state":{}}]">
<p>打开看一下</p>
<p> </p>
<p><span style="font-size:18px;">视频讲解</span></p>
<p><iframe allowfullscreen="true" frameborder="0" height="450" src="//player.bilibili.com/player.html?bvid=1Lu4m1P7yw&page=1" style="background:#eee;margin-bottom:10px;" width="700"></iframe><br />
</p>
</article>
</article>
</article>
</article>
</article>
</article>
</div><script> var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;" style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
if(parseInt(discuz_uid)==0){
(function($){
var postHeight = getTextHeight(400);
$(".showpostmsg").html($(".showpostmsg").html());
$(".showpostmsg").after(loginstr);
$(".showpostmsg").css({height:postHeight,overflow:"hidden"});
})(jQuery);
} </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script> <p>看过了视频,讲解画面稳定,音质清晰。</p>
MianQi 发表于 2024-2-17 19:14
看过了视频,讲解画面稳定,音质清晰。
<p>感谢支持,有什么使用问题可以留言</p>
<p>rv1106使用ffmpeg的时候</p>
<ul>
<li>sudo apt update无法解析域名</li>
<li>sudo apt install ffmpeg无法安装,请问要怎末解决</li>
</ul>
li-ai-meng 发表于 2024-4-20 23:36
rv1106使用ffmpeg的时候
sudo apt update无法解析域名
sudo apt install ffmpeg无法安装,请问要怎 ...
<p>你这个是没联网吧</p>
LitchiCheng 发表于 2024-4-21 10:28
你这个是没联网吧
<p>如果用网络共享把WiFi共享给网口的网卡,然后通过网线连接的ssh就自动断开了,这个要怎末解决?</p>
<p> </p>
li-ai-meng 发表于 2024-4-22 19:29
如果用网络共享把WiFi共享给网口的网卡,然后通过网线连接的ssh就自动断开了,这个要怎末解决?
  ...
<p>没碰到过,你可以自己研究下,我是直接网线</p>
<p>请问下,我用的buildroot镜像,安装ffmpeg后,无法使用libx264编码,请问怎么配置才能增加libx264的支持?</p>
LitchiCheng 发表于 2024-2-18 09:07
感谢支持,有什么使用问题可以留言
<p>请教buildroot镜像,如何增加libx264的支持,好多天都没搞好</p>
四眼兔子 发表于 2024-10-8 10:25
请教buildroot镜像,如何增加libx264的支持,好多天都没搞好
<p>你现在是怎么操作没弄好的</p>
LitchiCheng 发表于 2024-10-8 11:24
你现在是怎么操作没弄好的
<p>我修改Buildroot的配置,增加了对ffmpeg的支持,ffmpeg下的配置如下图:</p>
<p> </p>
<p> </p>
<p>对于libx264的支持,在buildroot中搜关键字”libx264“搜不到:</p>
<p> </p>
<p> </p>
<p>但是搜”x264“能搜到一个,我就给选上了,如下图:</p>
<p> </p>
<p> </p>
<p> </p>
<p>然后重新编译,生成镜像,烧录后,使用ffmpeg相关指令,调用264编码相关的参数,会报错:找不到libx264编码</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
LitchiCheng 发表于 2024-10-8 11:24
你现在是怎么操作没弄好的
<p>你好,能回复下吗?关于我再buildroot下无法添加libx264的问题</p>
页:
[1]