ffmpegでラズパイゼロからカメラ画像をUDP配信する方法
※ 当ページには【広告/PR】を含む場合があります。
2021/07/21
ffmpeg(Linux)でUDP送受信
192.168.0.101
192.168.0.102
動画受送信のテスト
/dev/video0
video4linux2
v4l2
$ ffmpeg -f video4linux2 -list_formats all -i /dev/video0
ffmpeg version 4.1.6-1~deb10u1+rpt2 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 8 (Raspbian 8.3.0-6+rpi1)
configuration: --prefix=/usr --extra-version='1~deb10u1+rpt2' --toolchain=hardened --incdir=/usr/include/arm-linux-gnueabihf --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-omx-rpi --enable-mmal --enable-neon --enable-rpi --enable-vout-drm --enable-v4l2-request --enable-libudev --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared --libdir=/usr/lib/arm-linux-gnueabihf --cpu=arm1176jzf-s --arch=arm
libavutil 56. 22.100 / 56. 22.100
libavcodec 58. 35.100 / 58. 35.100
libavformat 58. 20.100 / 58. 20.100
libavdevice 58. 5.100 / 58. 5.100
libavfilter 7. 40.101 / 7. 40.101
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
libpostproc 55. 3.100 / 55. 3.100
[video4linux2,v4l2 @ 0x1e93e40] Raw : yuv420p : Planar YUV 4:2:0 : {32-3280, 2}x{32-2464, 2}
[video4linux2,v4l2 @ 0x1e93e40] Raw : yuyv422 : YUYV 4:2:2 : {32-3280, 2}x{32-2464, 2}
[video4linux2,v4l2 @ 0x1e93e40] Raw : rgb24 : 24-bit RGB 8-8-8 : {32-3280, 2}x{32-2464, 2}
[video4linux2,v4l2 @ 0x1e93e40] Compressed: mjpeg : JFIF JPEG : {32-3280, 2}x{32-2464, 2}
[video4linux2,v4l2 @ 0x1e93e40] Compressed: h264 : H.264 : {32-3280, 2}x{32-2464, 2}
[video4linux2,v4l2 @ 0x1e93e40] Compressed: mjpeg : Motion-JPEG : {32-3280, 2}x{32-2464, 2}
[video4linux2,v4l2 @ 0x1e93e40] Raw : Unsupported : YVYU 4:2:2 : {32-3280, 2}x{32-2464, 2}
[video4linux2,v4l2 @ 0x1e93e40] Raw : Unsupported : VYUY 4:2:2 : {32-3280, 2}x{32-2464, 2}
[video4linux2,v4l2 @ 0x1e93e40] Raw : uyvy422 : UYVY 4:2:2 : {32-3280, 2}x{32-2464, 2}
[video4linux2,v4l2 @ 0x1e93e40] Raw : nv12 : Y/CbCr 4:2:0 : {32-3280, 2}x{32-2464, 2}
[video4linux2,v4l2 @ 0x1e93e40] Raw : bgr24 : 24-bit BGR 8-8-8 : {32-3280, 2}x{32-2464, 2}
[video4linux2,v4l2 @ 0x1e93e40] Raw : yuv420p : Planar YVU 4:2:0 : {32-3280, 2}x{32-2464, 2}
[video4linux2,v4l2 @ 0x1e93e40] Raw : Unsupported : Y/CrCb 4:2:0 : {32-3280, 2}x{32-2464, 2}
[video4linux2,v4l2 @ 0x1e93e40] Raw : Unsupported : 32-bit XBGR 8-8-8-8 : {32-3280, 2}x{32-2464, 2}
$ ffplay -fflags nobuffer udp://192.168.0.102:12000
#もしくは
$ ffplay -fflags nobuffer udp://localhost:12000
$ ffmpeg \
-f v4l2 \
-s 320x240 \
-r 15 \
-thread_queue_size 8192 \
-i /dev/video0 \
-c:v libx264 \
-preset ultrafast \
-tune zerolatency \
-f h264 \
udp://192.168.0.102:12000?pkt_size=1024
h264_omx
$ ffmpeg \
-f v4l2 \
-s 320x240 \
-r 15 \
-thread_queue_size 8192 \
-i /dev/video0 \
-c:v h264_omx \
-b:v 2048k \
-preset ultrafast \
-tune zerolatency \
-f h264 \
udp://192.168.0.102:12000?pkt_size=1024
h264_omx
200kbps
-b:v
余談〜raspividコマンドを使う
raspivid
$ raspivid -t 0 -w 320 -h 240 \
-hf -ih -fps 15 \
-o udp://192.168.0.102:12000
マルチキャスト配信にする
ユニキャスト
239.1.1.1
$ ffplay -fflags nobuffer udp://239.1.1.1:12345
$ ffmpeg \
-f v4l2 \
-s 320x240 \
-r 15 \
-thread_queue_size 8192 \
-i /dev/video0 \
-c:v h264_omx \
-b:v 2048k \
-preset ultrafast \
-tune zerolatency \
-f h264 \
udp://239.1.1.1:12345?pkt_size=1024
まとめ
参考サイト
記事を書いた人
ナンデモ系エンジニア
電子工作を身近に知っていただけるように、材料調達からDIYのハウツーまで気になったところをできるだけ細かく記事にしてブログ配信してます。
カテゴリー