before the discusstion:
play_rate问题是我们做gstreamer开发经常遇到的问题
这也许有一点令人费解, play rate的设定是放在gst_element_seek ()、gst_event_new_seek 里面实现的。
1 basic from gstreamer
Goal
Fast-forward, reverse-playback and slow-motion are all techniques collectively known as trick modes and they all have in common that modify the normal playback rate. This tutorial shows how to achieve these effects and adds frame-stepping into the deal. In particular, it shows:
How to change the playback rate, faster and slower than normal, forward and backwards.
How to advance a video frame-by-frame
Introduction
Fast-forward is the technique that plays a media at a speed higher than its normal (intended) speed; whereas slow-motion uses a speed lower than the intended one. Reverse playback does the same thing but backwards, from the end of the stream to the beginning.
All these techniques do is change the playback rate, which is a variable equal to 1.0 for normal playback, greater than 1.0 (in absolute value) for fast modes, lower than 1.0 (in absolute value) for slow modes, positive for forward playback and negative for reverse playback.
提供两种方法,如下:
GStreamer provides two mechanisms to change the playback rate: Step Events and Seek Events. Step Events allow skipping a given amount of media besides changing the subsequent playback rate (only to positive values). Seek Events, additionally, allow jumping to any position in the stream and set positive and negative playback rates.
In Basic tutorial 4: Time management seek events have already been shown, using a helper function to hide their complexity. This tutorial explains a bit more how to use these events.
Step Events are a more convenient way of changing the playback rate, due to the reduced number of parameters needed to create them; however, their implementation in GStreamer still needs a bit more polishing so Seek Events are used in this tutorial instead.
To use these events, they are created and then passed onto the pipeline, where theypropagate upstream until they reach an element that can handle them. If an event is passed onto a bin element like playbin2, it will simply feed the event to all its sinks, which will result in multiple seeks being performed. The common approach is to retrieve one of playbin2’s sinks through the video-sink or audio-sink properties and feed the event directly into the sink.
Frame stepping is a technique that allows playing a video frame by frame. It is implemented by pausing the pipeline, and then sending Step Events to skip one frame each time.
2 the setting functions for gst_event_new_seek ()
GstEvent *
gst_event_new_seek (gdouble rate,
GstFormat format,
GstSeekFlags flags,
GstSeekType start_type,
gint64 start,
GstSeekType stop_type,
gint64 stop);
Allocate a new seek event with the given parameters.
The seek event configures playback of the pipeline between start to stop at the speed given in rate , also called a playback segment. The start and stop values are expressed in format .
A rate of 1.0 means normal playback rate, 2.0 means double speed. Negatives values means backwards playback. A value of 0.0 for the rate is not allowed and should be accomplished instead by PAUSING the pipeline.
A pipeline has a default playback segment configured with a start position of 0, a stop position of -1 and a rate of 1.0. The currently configured playback segment can be queried with GST_QUERY_SEGMENT.
start_type and stop_type specify how to adjust the currently configured start and stop fields in playback segment. Adjustments can be made relative or absolute to the last configured values. A type of GST_SEEK_TYPE_NONE means that the position should not be updated.
When the rate is positive and start has been updated, playback will start from the newly configured start position.
For negative rates, playback will start from the newly configured stop position (if any). If the stop position is updated, it must be different from -1 (GST_CLOCK_TIME_NONE) for negative rates.
It is not possible to seek relative to the current playback position, to do this, PAUSE the pipeline, query the current playback position with GST_QUERY_POSITION and update the playback segment current position with a GST_SEEK_TYPE_SET to the desired position.
Parameters
rate
The new playback rate
format
The format of the seek values
flags
The optional seek flags
start_type
The type and flags for the new start position
start
The value of the new start position
stop_type
The type and flags for the new stop position
stop
The value of the new stop position
Returns
a new seek event.
1 basic from s
http://docs.gstreamer.com/display/GstSDK/Basic+tutorial+13%3A+Playback+speed
2 gst_element_seek ()
http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer/html/GstElement.html#gst-element-seek
3 gst_event_new_seek ()
https://developer.gnome.org/gstreamer/stable/gstreamer-GstEvent.html#gst-event-new-seek
Discuss with me @QQ: 28044280