androidmedia: Reverse Play
Submitted by Andy Devar
Link to original bug (#766514)
Description
Reverse play (negative rates) do not work with androidmedia.
Application: https://cgit.freedesktop.org/~slomo/gst-sdk-tutorials/tree/gst-sdk/tutorials/android-tutorial-5
To change to reverse direction, I added the following code:
/* Send seek event to change rate */
static void send_seek_event (CustomData *data) {
gint64 position;
GstEvent *seek_event;
/* Obtain the current position, needed for the seek event */
if (!gst_element_query_position (data->pipeline, GST_FORMAT_TIME, &position)) {
GST_DEBUG ("Unable to retrieve current position.\n");
return;
}
/* Get video sink */
if (data->video_sink == NULL) {
// If we have not done so, obtain the sink through which we will send the seek events
g_object_get (data->pipeline, "video-sink", &data->video_sink, NULL);
}
/* Create the seek event */
if (data->rate > 0) {
gst_element_seek(data->video_sink, data->rate, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE,
GST_SEEK_TYPE_SET, position, GST_SEEK_TYPE_NONE, 0);
} else {
gst_element_seek(data->video_sink, data->rate, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE | GST_SEEK_FLAG_TRICKMODE_KEY_UNITS | GST_SEEK_FLAG_TRICKMODE_NO_AUDIO,
GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_SET, position);
}
GST_DEBUG ("Current rate: %g\n", data->rate);
}
static void gst_native_change_direction (JNIEnv* env, jobject thiz) {
CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id);
if (!data) return;
data->rate *= -1.0;
send_seek_event (data);
}
As in the original tutorial-5, I use playbin:
data->pipeline = gst_parse_launch("playbin", &error);
Results:
- With androidmedia:
a) Forward play (rate=1):
Videos play smoothly (tried up to 1980x800) regardless of GOP size.
b) Reverse play (rate=-1):
A new frame is displayed only every few seconds. Eventually, video stops to play.
Same behavior regardless of resolution (even with 320x132) and GOP size (tried dynamic, 5 and 1).
CPU utilisation is no higher than with forward play, so I assume hardware acceleration is also used with reverse play.
- Without androidmedia (commented out in plugins.mk):
(just for comparison - meets my expectation)
a) Forward play (rate=1):
1280x532, dynamic GOP size: Smooth
1280x532, GOP size 1: Smooth
640x266, dynamic GOP size: Smooth
640x266, GOP size 1: Smooth
b) Reverse play (rate=-1):
1280x532, dynamic GOP size: Choppy
1280x532, GOP size 1: Choppy
640x266, GOP size 1: Smooth
640x266, dynamic GOP size: Choppy
The video I used can be downloaded here:
http://www.dvdloc8.com/clip.php?movieid=12167&clipid=3
To create other resolutions/GOP sizes, I used FFMPEG.
Example (GOP size 1, resolution 640x266):
ffmpeg -i "The Simpsons Movie - 1080p Trailer.mp4" -g 1 scale=640:266 "The Simpsons Movie - 1080p Trailer_GOP0001_640.mp4"
Hardware: Lenovo Tab2 A10/30
Qualcomm APQ8009
Android 5.1.1
Version: 1.8.1