gstreamerでMJPEGからH.264などにトランスコードするときのメモ

Amazon Kinesis Video StreamsでPanasonicやAXISのMJPEGの映像をアップロードするメモ - 続かない日記

前回、MJPEG APIWebカメラからのイメージをH.264にして、Kinesis Video Streamsに送る際に、下のようなパイプラインを組んでいたが、 どうもフレームレートが合わなくて再生がうまく行かなかった。

$ gst-launch-1.0 souphttpsrc location=http://<webcam mjpeg api uri> ! jpegparse ! jpegdec ! queue ! x264enc tune=zerolatency ! h264parse ! kvssink stream-name=<stream name>

でわかったのは、 jpegparse フィルタが souphttpsrc から受けた時点で framerate=1/1にしてるということ

$ timeout -s INT 3 gst-launch-1.0 -v souphttpsrc location=<webcam mjpeg api uri> ! jpegparse ! fakesink
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
/GstPipeline:pipeline0/GstJpegParse:jpegparse0.GstPad:src: caps = "image/jpeg\,\ parsed\=\(boolean\)true\,\ format\=\(string\)I420\,\ width\=\(int\)320\,\ height\=\(int\)240\,\ framerate\=\(fraction\)1/1"
/GstPipeline:pipeline0/GstFakeSink:fakesink0.GstPad:sink: caps = "image/jpeg\,\ parsed\=\(boolean\)true\,\ format\=\(string\)I420\,\ width\=\(int\)320\,\ height\=\(int\)240\,\ framerate\=\(fraction\)1/1"
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
handling interrupt.
Interrupt: Stopping pipeline ...
Execution ended after 0:00:02.788853712
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...
$

なので、jpegparseせずに、 image/jpeg,width=640,height=480,framerate=30/1 のように typefindfunction 使ってやったらフレームレートが合った。

じっさい Kinesis Video Streams にアップロードするときは、30フレもいらないのでこうした。

$ gst-launch-1.0 souphttpsrc location=<webcam mjpeg api uri> ! image/jpeg,width=640,height=480,framerate=30/1 ! jpegdec ! videorate ! video/x-raw,framerate=1/1 !  ! x264enc tune=zerolatency ! h264parse ! kvssink stream-name=<stream name>