GStreamer示例
- 视频
- CPU编解码
- 采集、软编、udp转发
gst-launch-1.0 v4l2src device="/dev/video0" ! video/x-raw,width=1280,height=720 ! videoconvert ! x264enc tune=zerolatency ! rtph264pay ! udpsink host=127.0.0.1 port=5022
- udp接收、软解、播放
gst-launch-1.0 udpsrc port=5022 ! application/x-rtp,encoding-name=H264 ! rtpjitterbuffer latency=0 ! rtph264depay ! avdec_h264 ! videoconvert ! xvimagesink
- 采集、软编、udp转发
- GPU编解码
- 采集、硬编、udp转发
gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-raw, format=YUY2, width=1280, height=720, framerate=30/1 ! videoconvert ! timeoverlay ! omxh264enc ! video/x-h264, stream-format=byte-stream ! h264parse ! rtph264pay ! udpsink host=127.0.0.1 port=5022
- udp接收、硬解、播放
gst-launch-1.0 udpsrc port=5022 ! application/x-rtp,encoding-name=H264 ! rtpjitterbuffer latency=0 ! rtph264depay ! video/x-h264, framerate=30/1 ! h264parse ! omxh264dec ! videoconvert ! xvimagesink
- 采集、硬编、硬解、写文件
gst-launch-1.0 -ev v4l2src device=/dev/video0 ! video/x-raw, format=YUY2, width=1280, height=720, framerate=30/1 ! videoconvert ! timeoverlay ! omxh264enc ! h264parse ! omxh264dec ! videoconvert ! jpegenc ! avimux ! filesink location=test.avi
- 采集、硬编、udp转发
- CPU编解码
- 音频
- PCM
- 采集、udp转发
gst-launch-1.0 autoaudiosrc ! audioconvert ! audioresample ! mulawenc ! rtppcmupay ! udpsink host=127.0.0.1 port=10002
- udp接收、播放
gst-launch-1.0 -ve udpsrc port=10002 ! application/x-rtp, clock-rate=8000, payload=0 ! rtppcmudepay ! mulawdec ! audio/x-raw, format=S16LE, layout=interleaved, rate=8000 ! audioconvert ! audiomixer name=mix ! audioconvert ! audioresample ! autoaudiosink
-
采集、udp转发(alsasrc)
gst-launch-1.0 -ve alsasrc ! audio/x-raw,rate=8000,channels=1,depth=16 ! audioconvert ! mulawenc ! rtppcmupay ! udpsink host=127.0.0.1 port=10002
- udp接收、播放(alsasink)
gst-launch-1.0 -ve udpsrc port=10002 ! application/x-rtp, clock-rate=8000, payload=0, encoding-name=PCMU ! rtppcmudepay ! mulawdec ! audioconvert ! alsasink
- 采集、udp转发
- AAC
- 采集、编码、解码、播放
gst-launch-1.0 alsasrc ! audio/x-raw,rate=64000,channels=1,depth=16 ! audioconvert ! audioresample ! avenc_aac ! aacparse ! avdec_aac ! audioconvert ! audioresample ! alsasink
- 采集、udp转发
gst-launch-1.0 -ve alsasrc ! audio/x-raw,rate=64000,channels=1,depth=16 ! audioconvert ! avenc_aac ! rtpmp4apay ! udpsink host=127.0.0.1 port=10002
- udp接收、播放
gst-launch-1.0 -ve udpsrc port=10002 ! application/x-rtp, media=audio, clock-rate=64000, payload=96, encoding-name=MP4A-LATM, config=40002210adca00 ! rtpmp4adepay ! aacparse ! avdec_aac ! audioconvert ! alsasink
- 写文件
gst-launch-1.0 -ve alsasrc ! audio/x-raw,rate=64000,channels=1,depth=16 ! audioconvert ! audioresample ! avenc_aac ! queue ! mux.audio_0 mp4mux name=mux ! filesink location=test.mp4
- 采集、编码、解码、播放
- OPUS
- 采集、udp转发
gst-launch-1.0 -ve alsasrc ! audio/x-raw,rate=48000,channels=1,depth=16 ! audioconvert ! opusenc ! rtpopuspay ! udpsink host=127.0.0.1 port=10002
- udp接收、播放
gst-launch-1.0 -ve udpsrc port=10002 ! application/x-rtp, clock-rate=48000, payload=96, encoding-name=OPUS ! rtpopusdepay ! opusdec ! audioconvert ! alsasink
- 采集、udp转发
- AMR
- 采集、udp转发
gst-launch-1.0 -ve alsasrc ! audio/x-raw,rate=8000,channels=1,depth=16 ! audioconvert ! amrnbenc ! rtpamrpay ! udpsink host=127.0.0.1 port=10002
- udp接收、播放
gst-launch-1.0 -ve udpsrc port=10002 ! application/x-rtp, clock-rate=8000, payload=96, encoding-name=AMR ! rtpamrdepay ! amrnbdec ! audioconvert ! alsasink
- 采集、udp转发
- PCM
查询设备提供商
bool GetAllFac(){ GList* provider_fac_list = gst_device_provider_factory_list_get_device_providers(GST_RANK_NONE); if (!provider_fac_list){ g_printerr("didn't discover any provider\n"); return false; } for (GList *n = provider_fac_list; n; n = n->next){ GstDeviceProviderFactory *providerFactory = GST_DEVICE_PROVIDER_FACTORY(n->data); gchar ** keylist = gst_device_provider_factory_get_metadata_keys(providerFactory); for (int i = 0; keylist && keylist[i]; i++){ g_print("key = %s\n", keylist[i]); } g_print("long-name = %s\n", gst_device_provider_factory_get_metadata(providerFactory, "long-name")); g_print("klass = %s\n", gst_device_provider_factory_get_metadata(providerFactory, "klass")); g_print("author = %s\n", gst_device_provider_factory_get_metadata(providerFactory, "author")); g_print("description = %s\n", gst_device_provider_factory_get_metadata(providerFactory, "description")); GstDeviceProvider *provider = gst_device_provider_factory_get(providerFactory); // get list of v4l2 devices GList *device_list = gst_device_provider_get_devices(provider); if (!device_list){ continue; } // find the requested /dev/video* device for (GList *n = device_list; n; n = n->next){ GstDevice *device = GST_DEVICE(n->data); gchar* device_name = gst_device_get_display_name(device); g_print("found device: %s\n", g_utf8_strup(device_name, strlen(device_name))); printf("aaa %s\n", device_name); GstStructure *properties = gst_device_get_properties(device); if (properties != NULL){ g_print("%s\n", gst_structure_to_string(properties)); } GstCaps *device_caps = gst_device_get_caps(device); { const uint32_t numCaps = gst_caps_get_size(device_caps); g_print("gstCamera -- found %u caps for v4l2 device\n", numCaps); if( numCaps == 0 ) continue; for( uint32_t n=0; n < numCaps; n++ ) { GstStructure* caps = gst_caps_get_structure(device_caps, n); if( !caps ) continue; g_print("[%u] %s\n", n, gst_structure_to_string(caps)); } } } } return true; }
查询麦克风
bool GetAllMic(){ GstDeviceProvider *device_provider = gst_device_provider_factory_get_by_name("pulsedeviceprovider"); if (!device_provider){ g_printerr("failed to create alsa device provider during discovery\n"); return false; } // get list of v4l2 devices GList *device_list = gst_device_provider_get_devices(device_provider); if (!device_list){ g_printerr("didn't discover any alsa devices\n"); return false; } // find the requested /dev/video* device for (GList *n = device_list; n; n = n->next){ GstDevice *device = GST_DEVICE(n->data); printf("found alsa device: %s\n", gst_device_get_display_name(device)); GstStructure *properties = gst_device_get_properties(device); if (properties != NULL){ g_print("%s\n", gst_structure_to_string(properties)); } } return true; }