Loop a file using playbin without artefacts
Nikos Chantziaras
realnc at gmail.com
Thu May 21 10:54:26 PDT 2015
On 21/05/15 19:20, Arnaud Loonstra wrote:
> On 2015-05-21 18:13, Nikos Chantziaras wrote:
>> On 21/05/15 19:02, Arnaud Loonstra wrote:
>>> Hi all,
>>>
>>> I'm doing a simple looping of a h264 file (raspbian provided test.h264
>>> for example)
>>>
>>> When I receive a SEGMENT_DONE message on the bus I seek to the
>>> beginning:
>>>
>>> flags = Gst.SeekFlags.FLUSH | Gst.SeekFlags.KEY_UNIT |
>>> Gst.SeekFlags.SEGMENT
>>> self.playbin.seek(1.0, Gst.Format.TIME, flags, Gst.SeekType.SET, 0,
>>> Gst.SeekType.SET, -1)
>>
>>
>> Try this instead:
>>
>> gst_element_seek_simple(pipeline, GST_FORMAT_TIME,
>> GST_SEEK_FLAG_SEGMENT, 0);
>>
>
> In python that would be
>
> self.playbin.seek_simple(Gst.Format.TIME, Gst.SeekFlags.SEGMENT, 0)
>
> But that just makes the video freeze at the end frame giving nonstop
> SEGMENT_DONE messages.
> If I add a FLUSH it does loop but with the artefacts.
I tried many approaches, and the way I ended up with that works very
reliably is to first put the pipeline into the playing state first, wait
for the transition to complete, and then do a seek to the end:
gst_element_set_state(pipeline, GST_STATE_PLAYING);
// Wait for the state change to complete.
gst_element_get_state(pipeline, 0, 0, GST_CLOCK_TIME_NONE);
// Seek to the end.
gst_element_seek(pipeline, 1.0, GST_FORMAT_TIME,
GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_SEGMENT,
GST_SEEK_TYPE_END, 0, GST_SEEK_TYPE_NONE,
GST_CLOCK_TIME_NONE);
The above is in my play() routine. In the event handler for
GST_MESSAGE_SEGMENT_DONE, I simply do:
gst_element_seek_simple(pipeline, GST_FORMAT_TIME,
GST_SEEK_FLAG_SEGMENT, 0);
This works extremely well for all videos (except for segmented MP4 files
intended for online streaming; a known GStreamer limitation.)
Are you really sure the artifacts you're seeing aren't actually part of
the video? Can you post the video somewhere to see if it's reproducible
by others? Also, have you tried other videos? Do you get the problem
with other videos as well?
More information about the gstreamer-devel
mailing list