LoginSignup
2
0

More than 5 years have passed since last update.

ffmpeg で MJPEG on RTP

Last updated at Posted at 2018-07-28

rfc2435 RTP Payload Format for JPEG-compressed Videoというのがあるので一応標準化された技術なんだけど、ffmpegで動かしてる例が全然見当たらなかった。
h.264が普及した世の中でMJPEG使う意味があるのかよくわからないが、なんとなく気になってしまったので動かしてみた。

$ ffmpeg -re \
-f lavfi \
-i testsrc=duration=600:size=1280x720:rate=7 \
-pix_fmt yuvj420p \
-c:v mjpeg \
-force_duplicated_matrix 1 \
-an \
-f rtp rtp://0.0.0.0:8004

でいけた。

Macのカメラを使うなら、

$ ffmpeg -re \
-pix_fmt uyvy422 \
-f avfoundation \
-framerate 30 \
-i "0:" \
-r 6 \
-pix_fmt yuvj420p \
-c:v mjpeg \
-force_duplicated_matrix 1 \
-an \
-f rtp rtp://0.0.0.0:8004

-pix_fmt yuvj420prtpenc_jpeg.c を参考にした。
-force_duplicated_matrix 1 は何を意味してるのかよくわかってないんだけど、libavのML に書いてあった。これがないとRFC 2435 suggests two quantization tables, 1 providedという警告が大量に出てくる。

VLC Player 単体でうまく再生できなかったので、

$ ffmpeg -i rtp://127.0.0.1:8004 \
-vcodec libx264 \
-profile:v baseline \
-level 1 \
-preset veryfast \
-tune zerolatency \
-an \
-f mpegts udp://127.0.0.1:1234

とやって再エンコードしてからVLC Playerから udp://@:1234 を開いたら映像が流れてきた。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0