Discussion:
Crash when trying to stop pipeline containing encodebin
Michael Guinzbourg
2016-05-10 14:36:58 UTC
Permalink
Hello,

64-bit GST 1.8.1 on 64-bit Windows 7 or higher (also reproducible in
earlier versions of gstreamer).

After I get EOS in my pipeline I'm trying to restart it using
gst_element_set_state
(pipeline, GST_STATE_READY);
As this statement is executed I have a crash.
I've examined every element of the pipeline and found that crash only
occurs if I have encodebin element in my pipeline.
Also if my container is mpegts and my video stream is to be encoded to
mpeg2 it crashes, otherwise is survives.
I'm not sure if the mpegts container or mpeg2 encoder causes the crash or
maybe it is a combination.
But I hope somebody would look into it since it's very easy to reproduce.

Thanks a lot in advance.
Michael
Chuck Crisler
2016-05-11 02:02:48 UTC
Permalink
I can't answer your questions but I can offer some direction. Get a
detailed GStreamer log (debug level 5 or 6) and a backtrace when it
crashes. I am out of date on Windows so I can't offer advice on how to get
the GStreamer log, but you can find the answer with Google.
Post by Michael Guinzbourg
Hello,
64-bit GST 1.8.1 on 64-bit Windows 7 or higher (also reproducible in
earlier versions of gstreamer).
After I get EOS in my pipeline I'm trying to restart it using gst_element_set_state
(pipeline, GST_STATE_READY);
As this statement is executed I have a crash.
I've examined every element of the pipeline and found that crash only
occurs if I have encodebin element in my pipeline.
Also if my container is mpegts and my video stream is to be encoded to
mpeg2 it crashes, otherwise is survives.
I'm not sure if the mpegts container or mpeg2 encoder causes the crash or
maybe it is a combination.
But I hope somebody would look into it since it's very easy to reproduce.
Thanks a lot in advance.
Michael
_______________________________________________
gstreamer-devel mailing list
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Sebastian Dröge
2016-05-11 05:43:03 UTC
Permalink
Post by Chuck Crisler
I can't answer your questions but I can offer some direction. Get a
detailed GStreamer log (debug level 5 or 6) and a backtrace when it
crashes. I am out of date on Windows so I can't offer advice on how
to get the GStreamer log, but you can find the answer with Google.
You just set GST_DEBUG=6 in the environment like on other platforms, or
call gst_debug_set_default_threshold(6) in your code.

For getting a backtrace you will have to run your application in gdb
and make it crash. You can get gdb binaries from here:
https://sourceforge.net/projects/mingw-w64/files/External%20binary%20packages%20%28Win64%20hosted%29/gdb/
--
Sebastian Dröge, Centricular Ltd · http://www.centricular.com
Michael Guinzbourg
2016-05-11 06:07:07 UTC
Permalink
I've set GST_DEBUG to "encodebin:6". I've got all kinds of all good info
during encodebin initialization (I will copy it below my report). All the
debug messages were posted before pipeline started to run and there was
absolutely nothing until the sudden crash at the bold line in my code
below. The piece of code that produces the crash is here (in the bus
callback):

case GST_MESSAGE_EOS:
g_print("EOS received on OBJ NAME
%s\n",GST_OBJECT_NAME(msg->src));
*gst_element_set_state (pipeline, GST_STATE_READY);*
gst_element_set_state (pipeline, GST_STATE_PLAYING);
break;

If I change my encoding to H264 - this code runs normally and restart the
pipeline without any problem.
Below is the debug output - there's nothing at all after the pipeline
starts running.

Again, if I replace *gst_element_set_state (pipeline, GST_STATE_READY);*
line with *gst_element_set_state (<element_name>, GST_STATE_READY); *where
<element_name> is any element except for encodebin then gstreamer doesn't
crash. It only crashes when I command the pipeline or encodebin to stop. It
looks to me that gstreamer crashes when I try to bring encodebin to the
stopped state, which is something to do with inability to sync the
encodebin clock with the rest of the pipeline.
Below is the copy of the debug output.


Encoding parameters
Container format : MPEG-2 Transport Stream (video/mpegts,
systemstream=(boolea
n)true, packetsize=(int)188)
Video format : MPEG-2 Video (video/mpeg, mpegversion=(int)2,
systemstream=(boo
lean)false, bitrate=(int)3000000)
Audio format : MPEG-4 AAC (audio/mpeg, mpegversion=(int)4,
rate=(int)16000, bi
trate=(int)192)
0:00:01.290090655 1764 0000000002C2F600 DEBUG encodebin
gstencodeb
in.c:2277:plugin_init: binding text domain gst-plugins-base-1.0 to locale
dir /c
/gstreamer/1.0/x86_64/share/locale
0:00:01.292118751 1764 0000000002C2F600 DEBUG encodebin
gstencodeb
in.c:2191:gst_encode_bin_set_profile:<encodebin0> profile
(0000000001C61660) : t
est-application-profile
0:00:01.292836790 1764 0000000002C2F600 DEBUG encodebin
gstencodeb
in.c:2172:gst_encode_bin_setup_profile: Setting up profile
0000000001C61660:test
-application-profile (type:container)
0:00:01.293517955 1764 0000000002C2F600 DEBUG encodebin
gstencodeb
in.c:1871:create_elements_and_pads: Current profile :
test-application-profile
0:00:01.294195067 1764 0000000002C2F600 DEBUG encodebin
gstencodeb
in.c:1799:_get_muxer: Getting list of muxers for format video/mpegts,
systemstre
am=(boolean)true, packetsize=(int)188
0:00:01.295206481 1764 0000000002C2F600 DEBUG encodebin
gstencodeb
in.c:1826:_get_muxer: Trying muxer mpegtsmux
0:00:01.297157181 1764 0000000002C2F600 DEBUG encodebin
gstencodeb
in.c:905:_create_element_and_set_preset: Creating element from factory
mpegtsmux
(preset factory name: (null) preset name: (null))
0:00:01.302493849 1764 0000000002C2F600 DEBUG encodebin
gstencodeb
in.c:1903:create_elements_and_pads: Trying stream profile with presence 1
0:00:01.303809984 1764 0000000002C2F600 DEBUG encodebin
gstencodeb
in.c:1200:_create_stream_group: Creating group. format video/mpeg,
mpegversion=(
int)2, systemstream=(boolean)false, for caps (NULL)
0:00:01.305385051 1764 0000000002C2F600 DEBUG encodebin
gstencodeb
in.c:1201:_create_stream_group: avoid_reencoding:0
0:00:01.307263218 1764 0000000002C2F600 DEBUG encodebin
gstencodeb
in.c:1730:_get_formatter: Getting list of formatters for format video/mpeg,
mpeg
version=(int)2, systemstream=(boolean)false
0:00:01.308975247 1764 0000000002C2F600 DEBUG encodebin
gstencodeb
in.c:1269:_create_stream_group: Adding output capsfilter for video/mpeg,
mpegver
sion=(int)2, systemstream=(boolean)false
0:00:01.310349327 1764 0000000002C2F600 DEBUG encodebin
gstencodeb
in.c:863:_get_parser: Getting list of parsers for format video/mpeg,
mpegversion
=(int)2, systemstream=(boolean)false
0:00:01.316105392 1764 0000000002C2F600 DEBUG encodebin
gstencodeb
in.c:1283:_create_stream_group: Got a parser mpegvparse0
0:00:01.318034210 1764 0000000002C2F600 DEBUG encodebin
gstencodeb
in.c:1325:_create_stream_group: Adding ghost pad video_0
0:00:01.319327248 1764 0000000002C2F600 LOG encodebin
gstencodeb
in.c:1379:_create_stream_group: Adding encoder
0:00:01.320683094 1764 0000000002C2F600 DEBUG encodebin
gstencodeb
in.c:946:_get_encoder: Getting list of encoders for format video/mpeg,
mpegversi
on=(int)2, systemstream=(boolean)false
0:00:01.323295508 1764 0000000002C2F600 DEBUG encodebin
gstencodeb
in.c:905:_create_element_and_set_preset: Creating element from factory
avenc_mpe
g2video (preset factory name: customMpeg2videoPreset preset name: (null))
0:00:01.325417614 1764 0000000002C2F600 LOG encodebin
gstencodeb
in.c:1408:_create_stream_group: Adding capsfilter for restriction caps :
(NULL)
0:00:01.326664052 1764 0000000002C2F600 LOG encodebin
gstencodeb
in.c:1440:_create_stream_group: Adding conversion elements for video stream
0:00:01.331920082 1764 0000000002C2F600 DEBUG encodebin
gstencodeb
in.c:1559:_create_stream_group: Adding ghostpad '':video_0
0:00:01.333334684 1764 0000000002C2F600 DEBUG encodebin
gstencodeb
in.c:1566:_create_stream_group: Done creating elements, adding StreamGroup
to ou
r controlled stream list
0:00:01.334781298 1764 0000000002C2F600 DEBUG encodebin
gstencodeb
in.c:1903:create_elements_and_pads: Trying stream profile with presence 0
Running...
Received new pad 'src_0' from 'source':
Link succeeded (type 'video/x-raw').
EOS received on OBJ NAME test-pipeline
Post by Sebastian Dröge
Post by Chuck Crisler
I can't answer your questions but I can offer some direction. Get a
detailed GStreamer log (debug level 5 or 6) and a backtrace when it
crashes. I am out of date on Windows so I can't offer advice on how
to get the GStreamer log, but you can find the answer with Google.
You just set GST_DEBUG=6 in the environment like on other platforms, or
call gst_debug_set_default_threshold(6) in your code.
For getting a backtrace you will have to run your application in gdb
https://sourceforge.net/projects/mingw-w64/files/External%20binary%20packages%20%28Win64%20hosted%29/gdb/
--
Sebastian Dröge, Centricular Ltd · http://www.centricular.com
_______________________________________________
gstreamer-devel mailing list
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Sebastian Dröge
2016-05-11 06:09:12 UTC
Permalink
Post by Michael Guinzbourg
I've set GST_DEBUG to "encodebin:6". I've got all kinds of all good
info during encodebin initialization (I will copy it below my
report). All the debug messages were posted before pipeline started
to run and there was absolutely nothing until the sudden crash at the
bold line in my code below. The piece of code that produces the crash
 case GST_MESSAGE_EOS: 
                    g_print("EOS received on OBJ NAME
%s\n",GST_OBJECT_NAME(msg->src));
    gst_element_set_state (pipeline, GST_STATE_READY);
            gst_element_set_state (pipeline,
GST_STATE_PLAYING);
                    break; 
If I change my encoding to H264 - this code runs normally and restart
the pipeline without any problem.
Below is the debug output - there's nothing at all after the pipeline
starts running.
Again, if I replace gst_element_set_state (pipeline,
GST_STATE_READY); line with gst_element_set_state (<element_name>,
GST_STATE_READY); where <element_name> is any element except for
encodebin then gstreamer doesn't crash. It only crashes when I
command the pipeline or encodebin to stop. It looks to me that
gstreamer crashes when I try to bring encodebin to the stopped state,
which is something to do with inability to sync the encodebin clock
with the rest of the pipeline.
Below is the copy of the debug output.
Can you get a backtrace (of all threads) of the crash with gdb?

It's a bit curious that you don't get any further debug output. Can you
also share your code, or simplified code that reproduces the problem?
--
Sebastian Dröge, Centricular Ltd · http://www.centricular.com
Michael Guinzbourg
2016-05-11 06:19:53 UTC
Permalink
here's the piece of my code which builds the pipeline:

gst_bin_add_many (GST_BIN (pipeline), data.source, data.q,data.convert,
data.filter, ebin, data.q1, data.sink, NULL);
if (!gst_element_link_many (data.q, data.convert, data.filter, ebin,
data.q1, data.sink, NULL)) {
g_printerr ("Elements could not be linked.\n");
gst_object_unref (pipeline);
return -1;
}

on padd added signal callback I link data.source and data.q.
My source is a live video stream which plays chunks of video and ends every
5 sec. at the EOS event I try to restart pipeline so I can play the next
chunk. If I encode in H264 this works perfect. If I encode in mpeg2 it
crashes at the following line (in bold):

case GST_MESSAGE_EOS:
g_print("EOS received on OBJ NAME
%s\n",GST_OBJECT_NAME(msg->src));
*gst_element_set_state (pipeline, GST_STATE_READY);*
gst_element_set_state (pipeline, GST_STATE_PLAYING);
break;

encode element doesn't print any debug info after pipeline starts running,
just crashes with no cry for help at *gst_element_set_state (pipeline,
GST_STATE_READY);*
Post by Sebastian Dröge
Post by Michael Guinzbourg
I've set GST_DEBUG to "encodebin:6". I've got all kinds of all good
info during encodebin initialization (I will copy it below my
report). All the debug messages were posted before pipeline started
to run and there was absolutely nothing until the sudden crash at the
bold line in my code below. The piece of code that produces the crash
g_print("EOS received on OBJ NAME
%s\n",GST_OBJECT_NAME(msg->src));
gst_element_set_state (pipeline, GST_STATE_READY);
gst_element_set_state (pipeline,
GST_STATE_PLAYING);
break;
If I change my encoding to H264 - this code runs normally and restart
the pipeline without any problem.
Below is the debug output - there's nothing at all after the pipeline
starts running.
Again, if I replace gst_element_set_state (pipeline,
GST_STATE_READY); line with gst_element_set_state (<element_name>,
GST_STATE_READY); where <element_name> is any element except for
encodebin then gstreamer doesn't crash. It only crashes when I
command the pipeline or encodebin to stop. It looks to me that
gstreamer crashes when I try to bring encodebin to the stopped state,
which is something to do with inability to sync the encodebin clock
with the rest of the pipeline.
Below is the copy of the debug output.
Can you get a backtrace (of all threads) of the crash with gdb?
It's a bit curious that you don't get any further debug output. Can you
also share your code, or simplified code that reproduces the problem?
--
Sebastian Dröge, Centricular Ltd · http://www.centricular.com
_______________________________________________
gstreamer-devel mailing list
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Michael Guinzbourg
2016-05-11 06:24:14 UTC
Permalink
I think the issue is very easy to reproduce: build any pipeline which has
encodebin element and ask encodebin to encode in mpeg2. then play any file
and try to restart pipeline when it reaches the end of file.
Post by Michael Guinzbourg
gst_bin_add_many (GST_BIN (pipeline), data.source, data.q,data.convert,
data.filter, ebin, data.q1, data.sink, NULL);
if (!gst_element_link_many (data.q, data.convert, data.filter, ebin,
data.q1, data.sink, NULL)) {
g_printerr ("Elements could not be linked.\n");
gst_object_unref (pipeline);
return -1;
}
on padd added signal callback I link data.source and data.q.
My source is a live video stream which plays chunks of video and ends
every 5 sec. at the EOS event I try to restart pipeline so I can play the
next chunk. If I encode in H264 this works perfect. If I encode in mpeg2 it
g_print("EOS received on OBJ NAME
%s\n",GST_OBJECT_NAME(msg->src));
*gst_element_set_state (pipeline, GST_STATE_READY);*
gst_element_set_state (pipeline, GST_STATE_PLAYING);
break;
encode element doesn't print any debug info after pipeline starts running,
just crashes with no cry for help at *gst_element_set_state (pipeline,
GST_STATE_READY);*
Post by Sebastian Dröge
Post by Michael Guinzbourg
I've set GST_DEBUG to "encodebin:6". I've got all kinds of all good
info during encodebin initialization (I will copy it below my
report). All the debug messages were posted before pipeline started
to run and there was absolutely nothing until the sudden crash at the
bold line in my code below. The piece of code that produces the crash
g_print("EOS received on OBJ NAME
%s\n",GST_OBJECT_NAME(msg->src));
gst_element_set_state (pipeline, GST_STATE_READY);
gst_element_set_state (pipeline,
GST_STATE_PLAYING);
break;
If I change my encoding to H264 - this code runs normally and restart
the pipeline without any problem.
Below is the debug output - there's nothing at all after the pipeline
starts running.
Again, if I replace gst_element_set_state (pipeline,
GST_STATE_READY); line with gst_element_set_state (<element_name>,
GST_STATE_READY); where <element_name> is any element except for
encodebin then gstreamer doesn't crash. It only crashes when I
command the pipeline or encodebin to stop. It looks to me that
gstreamer crashes when I try to bring encodebin to the stopped state,
which is something to do with inability to sync the encodebin clock
with the rest of the pipeline.
Below is the copy of the debug output.
Can you get a backtrace (of all threads) of the crash with gdb?
It's a bit curious that you don't get any further debug output. Can you
also share your code, or simplified code that reproduces the problem?
--
Sebastian Dröge, Centricular Ltd · http://www.centricular.com
_______________________________________________
gstreamer-devel mailing list
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Sebastian Dröge
2016-05-11 06:33:20 UTC
Permalink
Post by Michael Guinzbourg
I think the issue is very easy to reproduce: build any pipeline which
has encodebin element and ask encodebin to encode in mpeg2. then play
any file and try to restart pipeline when it reaches the end of file.
Can you provide such code then? That makes it more likely someone tries
to find the reason for your crash. Your code does not really provide a
lot of details about what you're doing there.

Also please provide a backtrace of all threads with gdb.
--
Sebastian Dröge, Centricular Ltd · http://www.centricular.com
Michael Guinzbourg
2016-05-12 01:21:46 UTC
Permalink
I've made for you very simple application which you can use to reproduce
the problem. It takes the video stream as a source, decodes it, encodes it
into mpeg2, mux it into mpegts container, saves it to file. you can use any
video file as a source. As the file reaches the end pipeline receives EOS
event, at the event I try to set pipeline to GST_STATE_READY, it causes a
crash. Here's complete code below. I will try to give you backtrace with
gdb later.

typedef struct _CustomData {
//GstElement *pipeline;
GstElement *source;
GstElement *convert;
GstElement *q;
GstElement *q1;
GstElement *sink;
GstElement *filter;
GstCaps *filtercaps;
} CustomData;

static CustomData data;

GstElement *pipeline;
GstElement *ebin;
GstEncodingProfile *prof;

GstBus *bus;
GstMessage *msg;
GstStateChangeReturn ret;

GstPadLinkReturn res;
GMainLoop *loop;

gchar *format= "video/mpegts,systemstream=True,packetsize=188";
gchar *aformat= "audio/mpeg, mpegversion=(int)4, rate=(int)16000,
stream-format=(string)adts, base-profile=(string)lc, bitrate=(int)192";
//audio/x-ac3";
gchar *vformat= "video/mpeg,mpegversion=2,systemstream=False,
bitrate=(int)7500";//"video/x-h264";


static GstEncodingProfile *
create_profile (GstCaps * cf, GstCaps * vf, GstCaps * af)
{
GstEncodingContainerProfile *cprof = NULL;
GstEncodingProfile * vtmp = NULL;

cprof = gst_encoding_container_profile_new ((gchar *)
"test-application-profile", NULL, cf, NULL);

if (vf)
{
vtmp = (GstEncodingProfile *) gst_encoding_video_profile_new (vf, NULL,
NULL, 0);
gst_encoding_container_profile_add_profile (cprof, vtmp);
}

if (af)
gst_encoding_container_profile_add_profile (cprof, (GstEncodingProfile
*)
gst_encoding_audio_profile_new (af, NULL, NULL, 0));

/* print out some info */
{
gchar *desc = gst_pb_utils_get_codec_description (cf);
gchar *cd = gst_caps_to_string (cf);
g_print ("Encoding parameters\n");
g_print (" Container format : %s (%s)\n", desc, cd);
g_free (desc);
g_free (cd);
if (vf) {
desc = gst_pb_utils_get_codec_description (vf);
cd = gst_caps_to_string (vf);
g_print (" Video format : %s (%s)\n", desc, cd);
g_free (desc);
g_free (cd);
}
if (af) {
desc = gst_pb_utils_get_codec_description (af);
cd = gst_caps_to_string (af);
g_print (" Audio format : %s (%s)\n", desc, cd);
g_free (desc);
g_free (cd);
}
}

return (GstEncodingProfile *) cprof;
}

static GstEncodingProfile *
create_profile_from_string (gchar * format, gchar * vformat, gchar *
aformat)
{
GstEncodingProfile *prof = NULL;
GstCaps *cf = NULL, *vf = NULL, *af = NULL;

if (format)
cf = gst_caps_from_string (format);
if (vformat)
vf = gst_caps_from_string (vformat);
if (aformat)
af = gst_caps_from_string (aformat);

if (G_UNLIKELY ((vformat && (vf == NULL)) || (aformat && (af == NULL))))
goto beach;

prof = create_profile (cf, vf, af);

beach:
if (cf)
gst_caps_unref (cf);
if (vf)
gst_caps_unref (vf);
if (af)
gst_caps_unref (af);

return prof;
}

gboolean bus_call(GstBus *bus, GstMessage *msg, void *data)
{
gchar *debug;
GError *err;
GMainLoop *loop = (GMainLoop*)data;
switch (GST_MESSAGE_TYPE(msg))
{
case GST_MESSAGE_EOS:
g_print("EOS received on OBJ NAME
%s\n",GST_OBJECT_NAME(msg->src));
//g_main_loop_quit (loop);
gst_element_set_state (pipeline, GST_STATE_READY);
gst_element_set_state (pipeline, GST_STATE_PLAYING);
break;
case GST_MESSAGE_ERROR:
gst_message_parse_error(msg, &err, &debug);
g_free(debug);
g_print("BUS CALL %s\n", err->message);
g_error_free(err);
g_main_loop_quit (loop);
break;
default:
break;
}
return TRUE;
}

/* This function will be called by the pad-added signal */
static void pad_added_handler (GstElement *src, GstPad *new_pad, GstElement
*sink) {
GstPad *gsink_pad = gst_element_get_static_pad (sink, "sink");
GstPadLinkReturn ret;
GstCaps *new_pad_caps = NULL;
GstStructure *new_pad_struct = NULL;
const gchar *new_pad_type = NULL;

g_print ("Received new pad '%s' from '%s':\n", GST_PAD_NAME (new_pad),
GST_ELEMENT_NAME (src));

/* Check the new pad's type */
new_pad_caps = gst_pad_query_caps (new_pad, NULL);
new_pad_struct = gst_caps_get_structure (new_pad_caps, 0);
new_pad_type = gst_structure_get_name (new_pad_struct);
if (!g_str_has_prefix (new_pad_type, "video/x-raw") && !g_str_has_prefix
(new_pad_type, "audio/x-raw")) {
g_print (" It has type '%s' which is not raw video or audio.
Ignoring.\n", new_pad_type);
goto exit;
}

if (g_str_has_prefix (new_pad_type, "video/x-raw"))
{
ret = gst_pad_link (new_pad, gsink_pad);
}
else
{
return;
}

if (GST_PAD_LINK_FAILED (ret)) {
g_print (" Type is '%s' but link failed.\n", new_pad_type);
} else {
g_print (" Link succeeded (type '%s').\n", new_pad_type);
}

exit:
/* Unreference the new pad's caps, if we got them */
if (new_pad_caps != NULL)
gst_caps_unref (new_pad_caps);

/* Unreference the sink pad */
gst_object_unref (gsink_pad);
}

int
main (int argc,
char *argv[])
{
gst_init (&argc, &argv);

g_print ("gstreamer initialized.\n");
/* Create the elements */
data.source = gst_element_factory_make ("uridecodebin", "source");
data.convert = gst_element_factory_make ("videoscale", "convert");
data.q = gst_element_factory_make ("queue", "q");
data.q1 = gst_element_factory_make ("queue", "q1");
data.sink = gst_element_factory_make ("filesink", "sink");
g_object_set (G_OBJECT (data.sink), "location", "c:\\tmp\\channel.ts",
NULL);
data.filter = gst_element_factory_make("capsfilter","filter");
data.filtercaps = gst_caps_new_simple ("video/x-raw",
"format", G_TYPE_STRING, "I420",
"width", G_TYPE_INT, 854,
"height", G_TYPE_INT, 480,
NULL);
g_object_set (G_OBJECT (data.filter), "caps", data.filtercaps, NULL);

g_print ("starting profile initialization\n");

/* Create the profile */
prof = create_profile_from_string (format, vformat, aformat);
if (G_UNLIKELY (prof == NULL)) {
g_print ("Encoding arguments are not valid !\n");
return -1;
}

/* Create the encodebin */
ebin = gst_element_factory_make ("encodebin", NULL);
g_object_set (ebin, "profile", prof, NULL);

/* Create the empty pipeline */
pipeline = gst_pipeline_new ("test-pipeline");

loop = g_main_loop_new (NULL, FALSE);

if (!pipeline || !data.source || !data.q || !data.sink) {
g_printerr ("Not all elements could be created.\n");
return -1;
}

/* Build the pipeline. */
gst_bin_add_many (GST_BIN (pipeline), data.source, data.q,data.convert,
data.filter, ebin, data.q1, data.sink, NULL);
if (!gst_element_link_many (data.q, data.convert, data.filter, ebin,
data.q1, data.sink, NULL)) {
g_printerr ("Elements could not be linked.\n");
gst_object_unref (pipeline);
return -1;
}

/* Set the URI to play */
g_object_set (data.source, "uri", "
http://www.quebec511.info/diffusion/fr/camera/camera.ashx?format=mp4&id=3505",
NULL);

/* Connect to the pad-added signal */
g_signal_connect (data.source, "pad-added", G_CALLBACK
(pad_added_handler), data.q);

/* we add a message handler */
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
gst_bus_add_watch (bus, bus_call, loop);
gst_object_unref (bus);

/* Set the pipeline to "playing" state*/
gst_element_set_state (pipeline, GST_STATE_PLAYING);

/* Iterate */
g_print ("Running...\n");

//g_timeout_add_seconds (1, timeout_cb, loop);

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));

return 0;
}
Post by Sebastian Dröge
Post by Michael Guinzbourg
I think the issue is very easy to reproduce: build any pipeline which
has encodebin element and ask encodebin to encode in mpeg2. then play
any file and try to restart pipeline when it reaches the end of file.
Can you provide such code then? That makes it more likely someone tries
to find the reason for your crash. Your code does not really provide a
lot of details about what you're doing there.
Also please provide a backtrace of all threads with gdb.
--
Sebastian Dröge, Centricular Ltd · http://www.centricular.com
_______________________________________________
gstreamer-devel mailing list
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Sebastian Dröge
2016-05-12 06:13:13 UTC
Permalink
Post by Michael Guinzbourg
I've made for you very simple application which you can use to
reproduce the problem. It takes the video stream as a source, decodes
it, encodes it into mpeg2, mux it into mpegts container, saves it to
file. you can use any video file as a source. As the file reaches the
end pipeline receives EOS event, at the event I try to set pipeline
to GST_STATE_READY, it causes a crash. Here's complete code below. I
will try to give you backtrace with gdb later.
Your code was missing includes. Please provide *complete* code in the
future :)

It does not crash on Linux here with GStreamer 1.8.1. Which version are
you running, and this is on Windows? 32 bit or 64 bit?

Maybe the gdb backtrace will show something useful.
--
Sebastian Dröge, Centricular Ltd · http://www.centricular.com
Michael Guinzbourg
2016-05-12 10:47:40 UTC
Permalink
I'm on Windows 7, 64 bit, GST version 1.8.1,
Thanks for helping me, backtrace is coming. I need to learn how to use gdb.

Sent from my iPhone
Post by Sebastian Dröge
Post by Michael Guinzbourg
I've made for you very simple application which you can use to
reproduce the problem. It takes the video stream as a source, decodes
it, encodes it into mpeg2, mux it into mpegts container, saves it to
file. you can use any video file as a source. As the file reaches the
end pipeline receives EOS event, at the event I try to set pipeline
to GST_STATE_READY, it causes a crash. Here's complete code below. I
will try to give you backtrace with gdb later.
Your code was missing includes. Please provide *complete* code in the
future :)
It does not crash on Linux here with GStreamer 1.8.1. Which version are
you running, and this is on Windows? 32 bit or 64 bit?
Maybe the gdb backtrace will show something useful.
--
Sebastian Dröge, Centricular Ltd · http://www.centricular.com
_______________________________________________
gstreamer-devel mailing list
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Michael Guinzbourg
2016-06-04 17:32:49 UTC
Permalink
after some more investigation I finally got the error from the element at
fault: avenc_mpeg2video error invalid pts (40) <= last (50)
this error is produced immediately when pipeline receives EOS. After this
error avenc_mpeg2video plugin is not operational.
the exact trace is below:

0:00:05.358383054 6440 0000000003A53F80 ERROR libav
gstavvidenc.c:706:gst_ffmpegvidenc_handle_frame:<customMpeg2videoPreset>
avenc_mpeg2video:
failed to encode buffer.

Any idea from you is highly appreciated.
Post by Michael Guinzbourg
I'm on Windows 7, 64 bit, GST version 1.8.1,
Thanks for helping me, backtrace is coming. I need to learn how to use gdb.
Sent from my iPhone
Post by Sebastian Dröge
Post by Michael Guinzbourg
I've made for you very simple application which you can use to
reproduce the problem. It takes the video stream as a source, decodes
it, encodes it into mpeg2, mux it into mpegts container, saves it to
file. you can use any video file as a source. As the file reaches the
end pipeline receives EOS event, at the event I try to set pipeline
to GST_STATE_READY, it causes a crash. Here's complete code below. I
will try to give you backtrace with gdb later.
Your code was missing includes. Please provide *complete* code in the
future :)
It does not crash on Linux here with GStreamer 1.8.1. Which version are
you running, and this is on Windows? 32 bit or 64 bit?
Maybe the gdb backtrace will show something useful.
--
Sebastian Dröge, Centricular Ltd · http://www.centricular.com
_______________________________________________
gstreamer-devel mailing list
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Michael Guinzbourg
2016-06-04 17:36:27 UTC
Permalink
sorry for the incomplete trace, here it is:

0:00:05.380162265 6452 00000000038D2F80 ERROR libav :0::
Invalid pts (72) <= last (77)
0:00:05.380587743 6452 00000000038D2F80 ERROR libav
gstavvidenc.c:706:gst_ffmpegvidenc_handle_frame:<customMpeg2videoPreset>
avenc_mpeg2video: failed to encode buffer
Post by Michael Guinzbourg
after some more investigation I finally got the error from the element at
fault: avenc_mpeg2video error invalid pts (40) <= last (50)
this error is produced immediately when pipeline receives EOS. After this
error avenc_mpeg2video plugin is not operational.
0:00:05.358383054 6440 0000000003A53F80 ERROR libav
gstavvidenc.c:706:gst_ffmpegvidenc_handle_frame:<customMpeg2videoPreset>
failed to encode buffer.
Any idea from you is highly appreciated.
Post by Michael Guinzbourg
I'm on Windows 7, 64 bit, GST version 1.8.1,
Thanks for helping me, backtrace is coming. I need to learn how to use gdb.
Sent from my iPhone
Post by Sebastian Dröge
Post by Michael Guinzbourg
I've made for you very simple application which you can use to
reproduce the problem. It takes the video stream as a source, decodes
it, encodes it into mpeg2, mux it into mpegts container, saves it to
file. you can use any video file as a source. As the file reaches the
end pipeline receives EOS event, at the event I try to set pipeline
to GST_STATE_READY, it causes a crash. Here's complete code below. I
will try to give you backtrace with gdb later.
Your code was missing includes. Please provide *complete* code in the
future :)
It does not crash on Linux here with GStreamer 1.8.1. Which version are
you running, and this is on Windows? 32 bit or 64 bit?
Maybe the gdb backtrace will show something useful.
--
Sebastian Dröge, Centricular Ltd · http://www.centricular.com
_______________________________________________
gstreamer-devel mailing list
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Sebastian Dröge
2016-06-06 07:21:25 UTC
Permalink
0:00:05.380162265  6452 00000000038D2F80 ERROR                  libav
:0:: Invalid pts (72) <= last (77)
0:00:05.380587743  6452 00000000038D2F80 ERROR                  libav
gstavvidenc.c:706:gst_ffmpegvidenc_handle_frame:<customMpeg2videoPres
et> avenc_mpeg2video:  failed to encode buffer
This still is very incomplete with only two lines.

Please try to provide an as simple as possible testcase (with as few
elements as needed, which as little dynamic behaviour as possible) to
reproduce this problem.
--
Sebastian Dröge, Centricular Ltd · http://www.centricular.com
Michael Guinzbourg
2016-06-09 14:17:26 UTC
Permalink
Sebastian, thank you so much for your great support and patience. I think I
figured out the root cause of the problem here.
The errors are due to the fact that I'm trying to encode a stream which is
taken as an output from the playbin (I have custom videosink connected to
playbin). The source video is a playlist which plays live feed from web
cam. The problem is that the source plays the same stream several times
before it shifts to the next available time. The encoder reads same stream
several times and expect that we move forward in time but we keep playing
same chunk of data many times. There's perfect output from the playbin for
this stream but if I direct it to the encodeer it complains with the errors
like pts is less then it should be. Could you please advice me how I can
handle this problem? So somehow I need to tell encoder - please ignore pts
and treat all incoming data as sequential. I couldn't find how I can do it
but you may have some idea for me.
Thanks,
MG
Post by Sebastian Dröge
Post by Michael Guinzbourg
0:00:05.380162265 6452 00000000038D2F80 ERROR libav
:0:: Invalid pts (72) <= last (77)
0:00:05.380587743 6452 00000000038D2F80 ERROR libav
gstavvidenc.c:706:gst_ffmpegvidenc_handle_frame:<customMpeg2videoPres
et> avenc_mpeg2video: failed to encode buffer
This still is very incomplete with only two lines.
Please try to provide an as simple as possible testcase (with as few
elements as needed, which as little dynamic behaviour as possible) to
reproduce this problem.
--
Sebastian Dröge, Centricular Ltd · http://www.centricular.com
_______________________________________________
gstreamer-devel mailing list
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Sebastian Dröge
2016-06-10 07:26:49 UTC
Permalink
Post by Michael Guinzbourg
Sebastian, thank you so much for your great support and patience. I
think I figured out the root cause of the problem here.
The errors are due to the fact that I'm trying to encode a stream
which is taken as an output from the playbin (I have custom videosink
connected to playbin). The source video is a playlist which plays
live feed from web cam. The problem is that the source plays the same
stream several times before it shifts to the next available time. The
encoder reads same stream several times and expect that we move
forward in time but we keep playing same chunk of data many times.
There's perfect output from the playbin for this stream but if I
direct it to the encodeer it complains with the errors like pts is
less then it should be. Could you please advice me how I can handle
this problem? So somehow I need to tell encoder - please ignore pts
and treat all incoming data as sequential. I couldn't find how I can
do it but you may have some idea for me.
You will have to offset (gst_pad_set_offset() for example) the running
time by the amount of time that was played after every track, or
alternatively use the gapless feature of playbin (the about-to-finish
signal), which also does that. If switching from one track to another
involves going back to the READY state, or flushing seeks, you will
have to solve that so the encoder sees a continuous timeline.

Maybe for your use case it would be best to use GES, which allows you
to set up a timeline of clips in some way and then render that to a
file or to the display.
https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer-editing-services/html/

It should make what you're doing here almost trivial :)
--
Sebastian Dröge, Centricular Ltd · http://www.centricular.com
Michael Guinzbourg
2016-06-10 19:32:49 UTC
Permalink
Thanks a lot for the ideas. I will definitely look into GES. From the first
10 min reading I couldn't find how GES pipeline can stream the resulted
stream to the network. My application is reading live stream from the
network, making some manipulation and stream the output to the network.
I've seen GES sink has audio and video sinks for the preview but I'm
looking into muxing into mpegts container and streaming it to UDP.
Talking about time adjustment, my current pipeline is using playbin and
convert live web stream (which are items in m3u8 playlist) into the
continuous stream. And the reason for this design is the abilty of the
playbin to connect playlist items together using 'about-to-finish' signal
into endless stream. The pipeline doesn't hit EOS, it just plays it
gaplessly. If I use playbin's default video sink the quality of stream is
perfect, no gaps. I thought that if I connect videosink to my custom bin
which contains encoder, etc, then I will have perfect solution. Instead,
encoder complains about pts not coming in order. I've searched devel
discussions and found similar questions but I couldn't find any
resolutions. I really appreciate if anybody can come up with the reasonable
solution. Thanks a lot again for the help!
Post by Sebastian Dröge
Post by Michael Guinzbourg
Sebastian, thank you so much for your great support and patience. I
think I figured out the root cause of the problem here.
The errors are due to the fact that I'm trying to encode a stream
which is taken as an output from the playbin (I have custom videosink
connected to playbin). The source video is a playlist which plays
live feed from web cam. The problem is that the source plays the same
stream several times before it shifts to the next available time. The
encoder reads same stream several times and expect that we move
forward in time but we keep playing same chunk of data many times.
There's perfect output from the playbin for this stream but if I
direct it to the encodeer it complains with the errors like pts is
less then it should be. Could you please advice me how I can handle
this problem? So somehow I need to tell encoder - please ignore pts
and treat all incoming data as sequential. I couldn't find how I can
do it but you may have some idea for me.
You will have to offset (gst_pad_set_offset() for example) the running
time by the amount of time that was played after every track, or
alternatively use the gapless feature of playbin (the about-to-finish
signal), which also does that. If switching from one track to another
involves going back to the READY state, or flushing seeks, you will
have to solve that so the encoder sees a continuous timeline.
Maybe for your use case it would be best to use GES, which allows you
to set up a timeline of clips in some way and then render that to a
file or to the display.
https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer-editing-services/html/
It should make what you're doing here almost trivial :)
--
Sebastian Dröge, Centricular Ltd · http://www.centricular.com
_______________________________________________
gstreamer-devel mailing list
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Sebastian Dröge
2016-06-13 07:24:26 UTC
Permalink
Post by Michael Guinzbourg
Thanks a lot for the ideas. I will definitely look into GES. From the
first 10 min reading I couldn't find how GES pipeline can stream the
resulted stream to the network. My application is reading live stream
from the network, making some manipulation and stream the output to
the network. I've seen GES sink has audio and video sinks for the
preview but I'm looking into muxing into mpegts container and
streaming it to UDP.
Instead of rendering to a file, it should also be possible to render to
an MPEG-TS container and send over UDP. But your live requirements
might make GES not an ideal choice, you would have to try.

In any case you would have to implement similar mechanisms for the time
offsetting, maybe simpler. However as you use playbin's gapless
mechanism, it should already do that for you.
Post by Michael Guinzbourg
Talking about time adjustment, my current pipeline is using playbin
and convert live web stream (which are items in m3u8 playlist) into
the continuous stream. And the reason for this design is the abilty
of the playbin to connect playlist items together using 'about-to-
finish' signal into endless stream. The pipeline doesn't hit EOS, it
just plays it gaplessly. If I use playbin's default video sink the
quality of stream is perfect, no gaps. I thought that if I connect
videosink to my custom bin which contains encoder, etc, then I will
have perfect solution. Instead, encoder complains about pts not
coming in order.
This should actually work, it might be that the encoder is looking at
the actual PTS (and complains about it jumping backwards) instead of
looking at the running time (which should be monotonically increasing).

Please check the PTS and running times of the buffers that you get in
your custom video-sink :)
--
Sebastian Dröge, Centricular Ltd · http://www.centricular.com
Michael Guinzbourg
2016-06-13 14:38:30 UTC
Permalink
I have this errors (below) and therefore no output only if I use
avenc_mpeg2video
encoder (mpeg2 encoder from libav library)

0:00:05.380162265 6452 00000000038D2F80 ERROR libav:0::
Invalid pts (72) <= last (77)
0:00:05.380587743 6452 00000000038D2F80 ERROR libav
gstavvidenc.c:706:gst_ffmpegvidenc_handle_frame:<customMpeg2videoPreset>
avenc_mpeg2video: failed to encode buffer

If I use exact same pipeline but use h264 encoder instead of mpeg2 - it
doesn't complain and produce perfect quality output.
I've tried to see if I can find any specific encoder settings which could
fix my problem but couldn't find anything. No matter what I try in
avenc_mpeg2video
settings give me the same error (posted above).

Answering your last message - what's the best way to check PTS and running
times of the buffers in my video-sink?
Thanks,
MG
Post by Sebastian Dröge
Post by Michael Guinzbourg
Thanks a lot for the ideas. I will definitely look into GES. From the
first 10 min reading I couldn't find how GES pipeline can stream the
resulted stream to the network. My application is reading live stream
from the network, making some manipulation and stream the output to
the network. I've seen GES sink has audio and video sinks for the
preview but I'm looking into muxing into mpegts container and
streaming it to UDP.
Instead of rendering to a file, it should also be possible to render to
an MPEG-TS container and send over UDP. But your live requirements
might make GES not an ideal choice, you would have to try.
In any case you would have to implement similar mechanisms for the time
offsetting, maybe simpler. However as you use playbin's gapless
mechanism, it should already do that for you.
Post by Michael Guinzbourg
Talking about time adjustment, my current pipeline is using playbin
and convert live web stream (which are items in m3u8 playlist) into
the continuous stream. And the reason for this design is the abilty
of the playbin to connect playlist items together using 'about-to-
finish' signal into endless stream. The pipeline doesn't hit EOS, it
just plays it gaplessly. If I use playbin's default video sink the
quality of stream is perfect, no gaps. I thought that if I connect
videosink to my custom bin which contains encoder, etc, then I will
have perfect solution. Instead, encoder complains about pts not
coming in order.
This should actually work, it might be that the encoder is looking at
the actual PTS (and complains about it jumping backwards) instead of
looking at the running time (which should be monotonically increasing).
Please check the PTS and running times of the buffers that you get in
your custom video-sink :)
--
Sebastian Dröge, Centricular Ltd · http://www.centricular.com
_______________________________________________
gstreamer-devel mailing list
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Sebastian Dröge
2016-06-14 06:06:26 UTC
Permalink
Post by Michael Guinzbourg
Answering your last message - what's the best way to check PTS and
running times of the buffers in my video-sink?
Just use GST_BUFFER_PTS() and gst_segment_to_running_time() to get both
and then print them with GST_TIME_FORMAT / GST_TIME_ARGS. Check the
docs for details how to use them
--
Sebastian Dröge, Centricular Ltd · http://www.centricular.com
Michael Guinzbourg
2016-07-14 21:19:19 UTC
Permalink
Sebastian, thank you so much for helping me to resolve the issue. I was
able to fix my gapless loop by changing the "do-timestamp" property of the
source element to TRUE.
After that mpeg encoder was very happy about the timestamp read from the
every buffer even if it was taken from the already played chunk of video.
I still have some dropped frames between chunks, which I hope will be fixed
in playbin3.
thanks,
MG
Post by Sebastian Dröge
Post by Michael Guinzbourg
Answering your last message - what's the best way to check PTS and
running times of the buffers in my video-sink?
Just use GST_BUFFER_PTS() and gst_segment_to_running_time() to get both
and then print them with GST_TIME_FORMAT / GST_TIME_ARGS. Check the
docs for details how to use them
--
Sebastian Dröge, Centricular Ltd · http://www.centricular.com
_______________________________________________
gstreamer-devel mailing list
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Loading...