GStreamer는 linux나 mobile linux환경에서 멀티미디어를 재생, 녹화등을 가능하게 하는 middleware입니다.
사용방법은 너무나 방대해서 여기에는 필요한 것들만 기술 하도록 하겠습니다.
설치 방법이나 빌드 방법등은 여러 사이트에 있으므로 찾아 보시기 바랍니다.
1. gst-inspect 사용법
설치되어 있는 library나 element등을 확인 할 때 사용합니다. 예를 들어 현재 설치되어 있는 library를 보고자 할 경우에는 단순히 prompt 상에서 명령어를 입력하면 됩니다.
$ gst-inspect-0.10
......
typefindfunctions: audio/x-ttafile: tta
typefindfunctions: application/x-apetag: mp3, ape, mpc, wv
typefindfunctions: application/x-id3v1: mp3, mp2, mp1, mpga, ogg, flac, tta
typefindfunctions: application/x-id3v2: mp3, mp2, mp1, mpga, ogg, flac, tta
typefindfunctions: video/x-fli: flc, fli
typefindfunctions: audio/mobile-xmf: mxmf
typefindfunctions: audio/riff-midi: mid, midi
typefindfunctions: audio/midi: mid, midi
typefindfunctions: audio/x-imelody: imy, ime, imelody
typefindfunctions: video/x-vcd: dat
typefindfunctions: video/x-cdxa: dat
typefindfunctions: audio/qcelp: qcp
typefindfunctions: video/x-msvideo: avi
typefindfunctions: audio/x-au: au, snd
typefindfunctions: audio/x-musepack: mpc, mpp, mp+
typefindfunctions: video/x-ms-asf: asf, wm, wma, wmv
amrwbdec: amrwbdec: AMR-WB audio decoder
alsa: alsasink: Audio sink (ALSA)
alsa: alsasrc: Audio source (ALSA)
alsa: alsamixer: Alsa mixer
uridecodebin: uridecodebin: URI Decoder
uridecodebin: decodebin2: Decoder Bin
ffmpegcolorspace: ffmpegcolorspace: FFMPEG Colorspace converter
staticelements: bin: Generic bin
staticelements: pipeline: Pipeline object
Total count: 250 plugins, 1146 features
특정 요소에 대해서 자세히 보고 싶은 경우에도 역시 사용됩니다.
위에서 확인한 alasink에 대해서 자세히 알고 싶으면 다음과 같이 입력하면 됩니다.
$ gst-inspect-0.10 alsasink
Factory Details:
Long name: Audio sink (ALSA)
Class: Sink/Audio
Description: Output to a sound card via ALSA
Author(s): Wim Taymans <wim@fluendo.com>
Rank: primary (256)
Plugin Details:
Name: alsa
Description: ALSA plugin library
Filename: /usr/lib/i386-linux-gnu/gstreamer-0.10/libgstalsa.so
Version: 0.10.36
License: LGPL
Source module: gst-plugins-base
Source release date: 2012-02-20
Binary package: GStreamer Base Plugins (Ubuntu)
Origin URL: https://launchpad.net/distros/ubuntu/+source/gst-plugins-base0.10
GObject
+----GstObject
+----GstElement
+----GstBaseSink
+----GstBaseAudioSink
+----GstAudioSink
+----GstAlsaSink
Implemented Interfaces:
GstPropertyProbe
Pad Templates:
SINK template: 'sink'
Availability: Always
Capabilities:
audio/x-raw-int
endianness: { 1234, 4321 }
signed: { true, false }
width: 32
depth: 32
rate: [ 1, 2147483647 ]
channels: [ 1, 2147483647 ]
audio/x-raw-int
endianness: { 1234, 4321 }
signed: { true, false }
width: 24
depth: 24
rate: [ 1, 2147483647 ]
channels: [ 1, 2147483647 ]
audio/x-raw-int
endianness: { 1234, 4321 }
signed: { true, false }
width: 32
depth: 24
rate: [ 1, 2147483647 ]
channels: [ 1, 2147483647 ]
audio/x-raw-int
endianness: { 1234, 4321 }
signed: { true, false }
width: 16
depth: 16
rate: [ 1, 2147483647 ]
channels: [ 1, 2147483647 ]
audio/x-raw-int
signed: { true, false }
width: 8
depth: 8
rate: [ 1, 2147483647 ]
channels: [ 1, 2147483647 ]
audio/x-iec958
Element Flags:
no flags set
Element Implementation:
Has change_state() function: gst_base_audio_sink_change_state
Has custom save_thyself() function: gst_element_save_thyself
Has custom restore_thyself() function: gst_element_restore_thyself
Element has no clocking capabilities.
Element has no indexing capabilities.
Element has no URI handling capabilities.
Pads:
SINK: 'sink'
Implementation:
Has chainfunc(): gst_base_sink_chain
Has custom eventfunc(): gst_base_sink_event
Has custom queryfunc(): gst_base_audio_sink_query_pad
Has custom iterintlinkfunc(): gst_pad_iterate_internal_links_default
Has bufferallocfunc(): gst_base_sink_pad_buffer_alloc
Has getcapsfunc(): gst_base_sink_pad_getcaps
Has setcapsfunc(): gst_base_sink_pad_setcaps
Has acceptcapsfunc(): gst_pad_acceptcaps_default
Has fixatecapsfunc(): gst_base_sink_pad_fixate
Pad Template: 'sink'
Element Properties:
name : The name of the object
flags: readable, writable
String. Default: "alsasink0"
preroll-queue-len : Number of buffers to queue during preroll
flags: readable, writable
Unsigned Integer. Range: 0 - 4294967295 Default: 0
sync : Sync on the clock
flags: readable, writable
Boolean. Default: true
max-lateness : Maximum number of nanoseconds that a buffer can be late before it is dropped (-1 unlimited)
flags: readable, writable
Integer64. Range: -1 - 9223372036854775807 Default: -1
qos : Generate Quality-of-Service events upstream
flags: readable, writable
Boolean. Default: false
async : Go asynchronously to PAUSED
flags: readable, writable
Boolean. Default: true
ts-offset : Timestamp offset in nanoseconds
flags: readable, writable
Integer64. Range: -9223372036854775808 - 9223372036854775807 Default: 0
enable-last-buffer : Enable the last-buffer property
flags: readable, writable
Boolean. Default: false
last-buffer : The last buffer received in the sink
flags: readable
MiniObject of type "GstBuffer"
blocksize : Size in bytes to pull per buffer (0 = default)
flags: readable, writable
Unsigned Integer. Range: 0 - 4294967295 Default: 4096
render-delay : Additional render delay of the sink in nanoseconds
flags: readable, writable
Unsigned Integer64. Range: 0 - 18446744073709551615 Default: 0
throttle-time : The time to keep between rendered buffers (unused)
flags: readable, writable
Unsigned Integer64. Range: 0 - 18446744073709551615 Default: 0
buffer-time : Size of audio buffer in microseconds
flags: readable, writable
Integer64. Range: 1 - 9223372036854775807 Default: 200000
latency-time : Audio latency in microseconds
flags: readable, writable
Integer64. Range: 1 - 9223372036854775807 Default: 10000
provide-clock : Provide a clock to be used as the global pipeline clock
flags: readable, writable
Boolean. Default: true
slave-method : Algorithm to use to match the rate of the masterclock
flags: readable, writable
Enum "GstBaseAudioSinkSlaveMethod" Default: 1, "skew"
(0): resample - GST_BASE_AUDIO_SINK_SLAVE_RESAMPLE
(1): skew - GST_BASE_AUDIO_SINK_SLAVE_SKEW
(2): none - GST_BASE_AUDIO_SINK_SLAVE_NONE
can-activate-pull : Allow pull-based scheduling
flags: readable, writable
Boolean. Default: false
alignment-threshold : Timestamp alignment threshold in nanoseconds
flags: readable, writable
Unsigned Integer64. Range: 1 - 18446744073709551614 Default: 40000000
drift-tolerance : Tolerance for clock drift in microseconds
flags: readable, writable
Integer64. Range: 1 - 9223372036854775807 Default: 40000
discont-wait : Window of time in nanoseconds to wait before creating a discontinuity
flags: readable, writable
Unsigned Integer64. Range: 0 - 18446744073709551614 Default: 1000000000
device : ALSA device, as defined in an asound configuration file
flags: readable, writable
String. Default: "default"
device-name : Human-readable name of the sound device
flags: readable
String. Default: null
card-name : Human-readable name of the sound card
flags: readable
String. Default: "Intel 82801BA-ICH2"
각 Element에서 property를 확인 할 때 사용하면 유용합니다.
2. gst-typefine 사용법
멀티미디어 화일에 대한 정보를 보여줍니다.
$ gst-typefine test.avi
./test.avi - video/x-msvideo
3. gst-launch 사용법
gst-launch는 멀티미디어를 재생하거나 녹화하는 경우에 사용합니다.
사용방법은 다소 복잡하나 단순화 해 보면 이해하기 쉽습니다.
- 화일의 재생
gst-launch-0.10 -v filesrc location=./test.avi ! \
avidemux name=demux \
demux.video_00 ! queue ! h264parse ! ffdec_h264 ! autovideosink \
demux.audio_00 ! queue ! aacparse ! ffdec_aac ! alsasink
코덱에 상관없이 재생하고 싶은 경우에는 playbin이나 decodebin을 사용해야 합니다. bin과 pipeline등은 기본적인 설명을 하는 곳을 참조하십시요.
gst-launch filesrc location=./test.avi ! avidemux name=avi avi.video_00 ! queue ! h264parse ! clvdec ! cldusink device=/dev/fb0 window=primary top=0 left=0 right=800 bottom=480 sx=0 sy=0 width=800 height=480 avi.audio_00 ! queue ! decodebin ! alsasink
gst-launch v4l2src device=/dev/video0 ! video/x-raw-yuv, width=1280, height=720, framerate=30/1 ! \
queue ! ffenc_mpeg4 ! queue ! mux. \
alsasrc blocksize=4410 ! audio/x-raw-int, rate=22050, channels=1 ! queue ! mux. \
avimux name=mux ! \
filesink location=./test.avi
v4l2src : video 입력을 지정합니다. width와 hegith, framerate등을 지정합니다.
ffenc_mpeg4는 video 사용될 코덱을 지정합니다.
mux.는 avimux에 사용될 video mux의 끝을 의미합니다.
alsasrc는 audio source를 지정합니다. rate, channel등을 지정합니다.
mux.는 avimux에 사용될 audio mux의 끝을 의미합니다.
avimux는 avi화일로 만드는 것을 의미합니다.
filesink는 저장할 화일을 지정합니다.
gst-launch v4l2src device=/dev/video0 ! video/x-raw-yuv, width=1280, height=720, framerate=30/1 ! queue ! clvenc ! queue ! mux. alsasrc blocksize=4410 ! audio/x-raw-int, rate=22050, channels=1 ! queue ! mux. avimux name=mux ! filesink location=/mnt/mmc/file-test.avi
프리뷰를 보면서 녹화를 하는 경우에는 다음과 같이 사용합니다. (tee를 사용해서 출력을 추가하게 됩니다.)
gst-launch v4l2src device=/dev/video0 ! video/x-raw-yuv, width=1280, height=720, framerate=30/1 ! \
tee name=preview ! autovideosink preview. ! \
queue ! ffenc_mpeg4 ! queue ! mux. \
alsasrc blocksize=4410 ! audio/x-raw-int, rate=22050, channels=1 ! queue ! mux. \
avimux name=mux ! \
filesink location=./test.avi
모션 감지등의 element를 사용하는 경우
gst-launch v4l2src device=/dev/video0 ! video/x-raw-yuv, width=1280, height=720, framerate=30/1 ! \
tee name=preview ! autovideosink preview. ! \
tee name=motion ! \
queue ! ffenc_mpeg4 ! queue ! mux. \
motion. ! queue ! motion_detect \
alsasrc blocksize=4410 ! audio/x-raw-int, rate=22050, channels=1 ! queue ! mux. \
avimux name=mux ! \
filesink location=./test.avi
gst-launch v4l2src device=/dev/video0 ! video/x-raw-yuv, width=1280, height=720, framerate=30/1 ! tee name=preview ! cldusink device=/dev/fb0 window=primary left=0 right=800 top=0 bottom=480 scale=0 order=1 preview. ! tee name=motion ! queue max-size-buffers=2 ! clvenc ! queue ! mux. motion. ! queue ! clpp width=800 height=480 ! clmd width=1280 height=720 UseThread=true enable=true decimate=3 alsasrc blocksize=4410 ! queue ! audio/x-raw-int, rate=22050, channels=1 ! queue ! mux. avimux name=mux ! filesink location=/mnt/mmc/file-test.avi
- 여러개의 화일로 녹화하는 경우
이 경우에는 filesink대신에 multifilesink를 사용합니다.
gst-launch v4l2src device=/dev/video0 ! video/x-raw-yuv, width=1280, height=720, framerate=30/1 ! \
queue ! ffenc_mpeg4 ! queue ! mux. \
alsasrc blocksize=4410 ! audio/x-raw-int, rate=22050, channels=1 ! queue ! mux. \
avimux name=mux ! \
multifilesink post-messages=1 next-file=key-frame location=./test-%05d.avi
multifilesink를 사용해서 key-frame별로 화일을 생성하게 합니다.
gst-launch v4l2src device=/dev/video0 ! video/x-raw-yuv, width=1280, height=720, framerate=30/1 ! tee name=preview ! cldusink device=/dev/fb0 window=primary left=0 right=800 top=0 bottom=480 scale=0 order=1 preview. ! queue ! clvenc ! queue ! mux. alsasrc blocksize=4410 ! audio/x-raw-int, rate=22050, channels=1 !queue ! mux. avimux name=mux ! multifilesink post-messages=1 next-file=key-frame location=/mnt/mmc/file-%05d.avi
avi ! avidemux name=avi avi.video_00 ! queue ! h264parse ! clvdec ! cldusink dev
ice=/dev/fb0 window=primary top=0 left=0 right=800 bottom=480 sx=0 sy=0 width=80
0 height=480 avi.audio_00 ! queue ! decodebin ! alsasink
<motion detect preview multi file>
gst-launch v4l2src device=/dev/video0 ! video/x-raw-yuv, width=1280, height=720, framerate=30/1 ! tee name=preview ! cldusink device=/dev/fb0 window=primary left=0 right=800 top=0 bottom=480 scale=0 order=1 preview. ! tee name=motion ! queue max-size-buffers=2 ! clvenc ! queue ! mux. motion. ! queue ! clpp width=800 height=480 ! clmd width=1280 height=720 UseThread=true enable=true decimate=3 alsasrc blocksize=4410 ! queue ! audio/x-raw-int, rate=22050, channels=1 ! queue ! mux. avimux name=mux ! multifilesink post-messages=1 next-file=key-frame location=/mnt/mmc/file-%05d.avi
<motion detect no preview multi file>
gst-launch v4l2src device=/dev/video0 ! video/x-raw-yuv, width=1280, height=720, framerate=30/1 ! tee name=motion ! queue max-size-buffers=2 ! clvenc ! queue ! mux. motion. ! queue ! clpp width=800 height=480 ! clmd width=1280 height=720 UseThread=true enable=true decimate=3 alsasrc blocksize=4410 ! queue ! audio/x-raw-int, rate=22050, channels=1 ! queue ! mux. avimux name=mux ! multifilesink post-messages=1 next-file=key-frame location=/mnt/mmc/file-%05d.avi
- sink는 video/audio 드라이버에서 제공하게 됩니다. [본문으로]
'Embeded' 카테고리의 다른 글
STM32CubeIDE 사용 팁 (0) | 2019.05.14 |
---|---|
STM32CubeIDE (0) | 2019.05.14 |
dmesg log 초기화 (0) | 2014.03.12 |
decodebin 사용시 (0) | 2014.03.07 |
IAR로 STM32 컴파일시 오류 (0) | 2013.03.06 |