How does gstreamer obtain the playback duration and current playback position?

Source: Internet
Author: User
Tags decode all gstreamer
1. There are several ways to get the duration: (1) Listening to the stst_message_duration on the bus. If the message arrives, you can use the stst_message_parse_duration command. However, the element usually does not send such a message. (2) create a duration query with stst_query_new_duration, and then query it with stst_element_query (pipeline, query. This method is commonly used. Generally, you can link all the pipeline elements and query them when the pipeline status is running.

2. There are several ways to get the position of the current playback: (1) if element in the pipeline supports ststst_query_position, You can query the position. Generally, the position query is provided by the sink element, because the data goes through Demux and decode all the way from SRC, which consumes time. Therefore, if the position is not provided by the non-sink element, it is inaccurate. (2) If the query cannot be performed, add the event and buffer probe on the sink element. Listen to the newsegment event in event probe. Generally, the start value in newsegment is 0 at the beginning of playing. After receiving the event, perform some corresponding actions. Then, record the timestamp of the first buffer in the buffer probe, and then perform subtraction with the timestamp of the first buffer for the subsequent buffer, the difference value divided by duration is the current position. Note: If the newsegment event is received during playback, the timestamp of the first buffer must be re-calculated. When calculating the position, remember to add start in newsegment and divide it by duration. This is correct.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.