All pastes #838637 Raw Edit

Someone

public text v1 · immutable
#838637 ·published 2007-12-30 15:24 UTC
rendered paste body
	int64 requestFrame(int64 frame) {
		int64 currentFrame;
		GstFormat format = GST_FORMAT_DEFAULT;
		
		// Seek to the specified frame's most recent keyframe.
		bool out = (TRUE == gst_element_seek(pipeline, 1.0, format,
			(GstSeekFlags)(GST_SEEK_FLAG_KEY_UNIT | GST_SEEK_FLAG_FLUSH),
			GST_SEEK_TYPE_SET, frame, GST_SEEK_TYPE_SET, -1));

		// Get the GStreamer bus to tell us when the seek is done.
		GstBus* bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
		GstMessage* msg = gst_bus_poll(bus, GST_MESSAGE_ASYNC_DONE, -1);
		gst_message_unref(msg);
		gst_object_unref(bus);
		
		// Return the correct value for success/failure.
		if (TRUE == gst_element_query_position(pipeline, &format, &currentFrame)) {
			cout << "Frame: " << currentFrame << endl;
			return currentFrame;
		}
		return -1;
		
	}
	
Use case:

	// try to seek some places
	for (int64 i = 0; i < 100; ++i) {
		int64 sought = q->requestFrame(i);
		if (sought == i) {
			cout << "k";
		} else {
			cout << ".";
		}
		cout.flush();
	}
	cout << endl;