[GStreamer] Application Development Manual - Your first application
FFmpeg, GStreamer, VLC 2026. 4. 14. 21:54 |Application Development Manual - Your first application을 윈도우에서 컴파일하고 실행하면 아래와 같이 에러가 발생한다.


어떤 엘리먼트에서 에러가 발생했는지 정확히 파악하려면 GStreamer 디버깅 로그를 켜는 것이 좋습니다. Visual Studio에서 프로그램을 실행하기 전에 다음 환경 변수를 설정하세요.
- 환경 변수 설정: Visual Studio 프로젝트 속성 - Debugging - Environment 항목에 아래 내용 추가 GST_DEBUG=3 (또는 더 상세한 로그를 원하면 GST_DEBUG=4 지정)
이렇게 하면 콘솔 출력창이나 리눅스/윈도우 터미널에 에러를 발생시킨 конкрет한 원인(예: Not Negotiated, Wrong File Type 등)이 출력되어 디버깅에 큰 도움이 됩니다.

조금 더 자세한 내용이 표시된다.
Internal data stream error.
streaming stopped, reason not-linked (-1)
#include <gst/gst.h>
#include <glib.h>
static gboolean bus_call(GstBus* bus, GstMessage* msg, gpointer data)
{
GMainLoop* loop = (GMainLoop*)data;
switch (GST_MESSAGE_TYPE(msg)) {
case GST_MESSAGE_EOS:
g_print("End of stream\n");
g_main_loop_quit(loop);
break;
case GST_MESSAGE_ERROR: {
gchar* debug;
GError* error;
gst_message_parse_error(msg, &error, &debug);
g_free(debug);
g_printerr("Error: %s\n", error->message);
g_error_free(error);
g_main_loop_quit(loop);
break;
}
default:
break;
}
return TRUE;
}
static void on_pad_added(GstElement* element, GstPad* pad, gpointer data)
{
GstPad* sinkpad;
GstElement* decoder = (GstElement*)data;
// 새로 추가된 pad의 caps를 가져옴
GstCaps* caps = gst_pad_get_current_caps(pad);
if (!caps)
caps = gst_pad_query_caps(pad, NULL);
// caps의 구조체에서 이름을 가져옴
const gchar* name = gst_structure_get_name(gst_caps_get_structure(caps, 0));
g_print("New pad '%s' added with caps '%s'\n", GST_PAD_NAME(pad), name);
// 오디오(vorbis) 스트림인지 확인
if (g_str_has_prefix(name, "audio/x-vorbis")) {
g_print("Dynamic pad created, linking demuxer/decoder\n");
sinkpad = gst_element_get_static_pad(decoder, "sink");
// 이미 연결되어 있는지 확인
if (!gst_pad_is_linked(sinkpad)) {
GstPadLinkReturn ret = gst_pad_link(pad, sinkpad);
if (ret != GST_PAD_LINK_OK)
g_printerr("Failed to link decoder. Error code: %d\n", ret);
else
g_print("Successfully linked demuxer and decoder.\n");
}
gst_object_unref(sinkpad);
}
else {
g_print("Ignoring non-audio pad: %s\n", name);
}
gst_caps_unref(caps);
}
int main(int argc, char* argv[])
{
GMainLoop* loop;
GstElement* pipeline, * source, * demuxer, * decoder, * conv, * sink;
GstBus* bus;
guint bus_watch_id;
/* Initialisation */
gst_init(&argc, &argv);
loop = g_main_loop_new(NULL, FALSE);
/* Check input arguments */
if (argc != 2) {
g_printerr("Usage: %s <Ogg/Vorbis filename>\n", argv[0]);
return -1;
}
/* Create gstreamer elements */
pipeline = gst_pipeline_new("audio-player");
source = gst_element_factory_make("filesrc", "file-source");
demuxer = gst_element_factory_make("oggdemux", "ogg-demuxer");
decoder = gst_element_factory_make("vorbisdec", "vorbis-decoder");
conv = gst_element_factory_make("audioconvert", "converter");
sink = gst_element_factory_make("autoaudiosink", "audio-output");
//sink = gst_element_factory_make("directsoundsink", "audio-output");
// Windows에서는 autoaudiosink 대신 directsoundsink 사용
if (!pipeline || !source || !demuxer || !decoder || !conv || !sink) {
g_printerr("One element could not be created. Exiting.\n");
return -1;
}
/* Set up the pipeline */
/* we set the input filename to the source element */
g_object_set(G_OBJECT(source), "location", argv[1], NULL);
/* we add a message handler */
bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
bus_watch_id = gst_bus_add_watch(bus, bus_call, loop);
gst_object_unref(bus);
/* we add all elements into the pipeline */
/* file-source | ogg-demuxer | vorbis-decoder | converter | alsa-output */
gst_bin_add_many(GST_BIN(pipeline), source, demuxer, decoder, conv, sink, NULL);
/* we link the elements together */
/* file-source -> ogg-demuxer ~> vorbis-decoder -> converter -> alsa-output */
gst_element_link(source, demuxer);
gst_element_link_many(decoder, conv, sink, NULL);
g_signal_connect(demuxer, "pad-added", G_CALLBACK(on_pad_added), decoder);
/* note that the demuxer will be linked to the decoder dynamically.
The reason is that Ogg may contain various streams (for example
audio and video). The source pad(s) will be created at run time,
by the demuxer when it detects the amount and nature of streams.
Therefore we connect a callback function which will be executed
when the "pad-added" is emitted.*/
/* Set the pipeline to "playing" state*/
g_print("Now playing: %s\n", argv[1]);
gst_element_set_state(pipeline, GST_STATE_PLAYING);
/* Iterate */
g_print("Running...\n");
g_main_loop_run(loop);
/* Out of the main loop, clean up nicely */
g_print("Returned, stopping playback\n");
gst_element_set_state(pipeline, GST_STATE_NULL);
g_print("Deleting pipeline\n");
gst_object_unref(GST_OBJECT(pipeline));
g_source_remove(bus_watch_id);
g_main_loop_unref(loop);
return 0;
}
더 자세한 내용을 알기 위해 on_pad_added()를 위와 같이 수정하고 Debugging - Environment에 추가했던 GST_DEBUG=3을 삭제하고(출력 내용을 간결하게 하기 위해) 실행해 보자.

■ 에러 코드별 의미 및 해결법:
-1 (GST_PAD_LINK_WRONG_HIERARCHY): 요소(element)들이 서로 같은 파이프라인 버스(Bin) 안에 있지 않을 때. (현재 코드상엔 잘 들어있으므로 제외)
-2 (GST_PAD_LINK_WAS_LINKED) / -6 (GST_PAD_LINK_REFUSED): 이미 연결되었거나 디코더 측에서 패드 연결을 거부한 경우입니다.
-4 (GST_PAD_LINK_NOFORMAT): 가장 빈번하게 발생합니다. 디코더와 컨버터, 혹은 컨버터와 오디오 싱크 간에 데이터를 주고받을 포맷 협상(Negotiation)에 실패한 것입니다. 이 경우 다음을 점검해야 합니다.
▶오디오 재생 장치 문제: 윈도우 환경에서 autoaudiosink가 기본 오디오 장치를 잘 잡지 못하는 경우가 있습니다. main 함수에서 autoaudiosink를 directsoundsink 또는 wasapisink 로 교체해 보세요.
▶Vorbis 플러그인 누락: 개발 환경의 GStreamer 버전에 gst-plugins-base 또는 Ogg 관련 플러그인이 누락되어 디코더가 정상 동작하지 않을 수 있습니다.
/* Create gstreamer elements */
pipeline = gst_pipeline_new("audio-player");
source = gst_element_factory_make("filesrc", "file-source");
demuxer = gst_element_factory_make("oggdemux", "ogg-demuxer");
decoder = gst_element_factory_make("vorbisdec", "vorbis-decoder");
conv = gst_element_factory_make("audioconvert", "converter");
//sink = gst_element_factory_make("autoaudiosink", "audio-output");
sink = gst_element_factory_make("directsoundsink", "audio-output");
// Windows에서는 autoaudiosink 대신 directsoundsink 사용
main()에서 sink만 위와 같이 수정한다.


'FFmpeg, GStreamer, VLC' 카테고리의 다른 글
| [GStreamer] Tutorial 튜토리얼 정리 (0) | 2026.04.16 |
|---|---|
| [GStreamer] 간단한 설명 (0) | 2026.04.13 |
| Reason of RTSP Streaming with Delay and Pixelation 스트리밍과 딜레이 그리고 픽셀레이션(깍뚜기) 현상의 원인 (0) | 2026.04.08 |
| [VLC] LibVLCSharp 영상 재생 2 (feat. 간단한 동영상 플레이어) (0) | 2026.04.05 |
| [FFmpeg] Winform PictureBox 동영상 비트맵 재생 (0) | 2026.04.05 |
