Skip to main content

GStreamer: gst-launch-1.0 実行例

環境変数設定

RTSP_URL=rtsp://...

実行例

テスト映像を再生

gst-launch-1.0 \
videotestsrc \
! autovideosink

テスト映像を mp4 ファイルに保存

gst-launch-1.0 \
-e \
videotestsrc pattern=ball \
! video/x-raw,width=1280,height=720,framerate=5/1 \
! vtenc_h264 \
! mp4mux \
! filesink location=output.mp4

mp4 ファイルの映像を再生

gst-launch-1.0 \
filesrc location=${MP4_FILE} \
! decodebin \
! videoconvert \
! autovideosink

または

gst-launch-1.0 \
filesrc location=${MP4_FILE} \
! qtdemux \
! h264parse \
! decodebin \
! videoconvert \
! autovideosink
  • filesrc : ファイルから入力
  • qtdemux : mov ファイルの映像/音声を分離
  • h264parse : H.264 形式の解析
  • decodebin : RAW 形式に変換(デコード)
  • videoconvert : RAW 形式の映像を出力先に合わせて変換
  • autovideosink : 出力先を自動的に検出して映像を出力

mp4 ファイル (AAC) の音声を再生

gst-launch-1.0 \
filesrc location=${MP4_FILE} \
! decodebin \
! audioconvert \
! audioresample \
! autoaudiosink

または

gst-launch-1.0 \
filesrc location=${MP4_FILE} \
! qtdemux \
! aacparse \
! decodebin \
! audioconvert \
! audioresample \
! autoaudiosink

RTSP の映像を再生

gst-launch-1.0 \
rtspsrc location="${RTSP_URL}" \
! decodebin \
! autovideosink

RTSP (H.264) の映像を mp4 ファイルに保存

gst-launch-1.0 \
-e \
rtspsrc location="${RTSP_URL}" \
! rtph264depay \
! h264parse \
! mp4mux \
! filesink location=output.mp4

-e オプションをつけることで、Ctrl+C で止めたときにファイナライズされます。つけないと正常な mp4 ファイルが出力されません。

  • rtph264depay : RTP パケットから H.264 映像を抽出
  • h264parse : H.264 形式の解析
  • mp4mux : 映像/音声を結合して MPEG-4 ファイル形式を出力
  • filesink : ファイルに保存

RTSP の映像を mp4 ファイルに保存 (H.264 にエンコード)

gst-launch-1.0 \
-e \
rtspsrc location="${RTSP_URL}" \
! decodebin \
! x264enc \
! mp4mux \
! filesink location=output.mp4

RTSP (G.711 A-Law) の音声を再生

gst-launch-1.0 \
rtspsrc location="${RTSP_URL}" \
! rtppcmadepay \
! decodebin \
! audioconvert \
! audioresample \
! autoaudiosink

※G.711 u-law の場合は rtppcmudepay、G.726 の場合は rtpg726depay を使用する。

RTSP (G.711 A-Law) の音声を wav ファイルに保存

gst-launch-1.0 \
-e \
rtspsrc location="${RTSP_URL}" \
! rtppcmadepay \
! decodebin \
! audioconvert \
! audioresample \
! audio/x-raw,format=S16LE,channel=1,rate=8000 \
! wavenc \
! filesink location=output.wav

RTSP (H.264 + G.711 A-law) の映像/音声を再生

gst-launch-1.0 \
rtspsrc location="${RTSP_URL}" name=src \
src. \
! rtph264depay \
! h264parse \
! decodebin \
! videoconvert \
! autovideosink sync=false \
src. \
! rtppcmadepay \
! decodebin \
! audioconvert \
! audioresample \
! autoaudiosink sync=false

RTSP (H.264 + G.711 A-law) の映像/音声を mp4 ファイルに保存

gst-launch-1.0 \
-e \
rtspsrc location="${RTSP_URL}" name=src \
src. \
! queue \
! rtph264depay \
! h264parse \
! mux. \
src. \
! queue \
! rtppcmadepay \
! decodebin \
! audioconvert \
! audioresample \
! avenc_aac \
! mux. \
mp4mux name=mux \
! filesink location=output.mp4

RTSP (AAC) の音声を再生

gst-launch-1.0 \
rtspsrc location="${RTSP_URL}" \
! rtpmp4gdepay \
! decodebin \
! audioconvert \
! autoaudiosink sync=false
  • rtpmp4gdepay : RTP パケットから MPEG4 ストリームを抽出

RTSP (H.264 + AAC) の映像/音声を再生

gst-launch-1.0 \
rtspsrc location="${RTSP_URL}" name=src \
src. \
! queue \
! rtph264depay \
! h264parse \
! decodebin \
! videoconvert \
! autovideosink sync=false \
src. \
! queue \
! rtpmp4gdepay \
! decodebin \
! audioconvert \
! audioresample \
! autoaudiosink sync=false

RTSP (H.264 + AAC) の映像/音声を mp4 ファイルに保存

gst-launch-1.0 \
-e \
rtspsrc location="${RTSP_URL}" name=src \
src. \
! queue \
! rtph264depay \
! h264parse \
! mux. \
src. \
! queue \
! rtpmp4gdepay \
! aacparse \
! mux. \
mp4mux name=mux \
! filesink location=output.mp4