gstvideo.video_decoder
Module for [VideoDecoder] class
Types 3
This base class is for video decoders turning encoded data into raw video frames.
The GstVideoDecoder base class and derived subclasses should cooperate as follows:
Configuration
- Initially, GstVideoDecoder calls @start when the decoder element
is activated, which allows the subclass to perform any global setup.
- GstVideoDecoder calls @set_format to inform the subclass of caps
describing input video data that it is about to receive, including possibly configuration data. While unlikely, it might be called more than once, if changing input parameters require reconfiguration.
- Incoming data buffers are processed as needed, described in Data
Processing below.
- GstVideoDecoder calls @stop at end of all processing.
Data processing
- The base class gathers input data, and optionally allows subclass
to parse this into subsequently manageable chunks, typically corresponding to and referred to as 'frames'.
- Each input frame is provided in turn to the subclass' @handle_frame
callback.
- When the subclass enables the subframe mode with [gstvideo.video_decoder.VideoDecoder.setSubframeMode],
the base class will provide to the subclass the same input frame with different input buffers to the subclass @handle_frame callback. During this call, the subclass needs to take ownership of the input_buffer as @GstVideoCodecFrame.input_buffer will have been changed before the next subframe buffer is received. The subclass will call [gstvideo.video_decoder.VideoDecoder.haveLastSubframe] when a new input frame can be created by the base class. Every subframe will share the same @GstVideoCodecFrame.output_buffer to write the decoding result. The subclass is responsible to protect its access.
- If codec processing results in decoded data, the subclass should call
@gst_video_decoder_finish_frame to have decoded data pushed downstream. In subframe mode the subclass should call @gst_video_decoder_finish_subframe until the last subframe where it should call @gst_video_decoder_finish_frame. The subclass can detect the last subframe using GST_VIDEO_BUFFER_FLAG_MARKER on buffers or using its own logic to collect the subframes. In case of decoding failure, the subclass must call @gst_video_decoder_drop_frame or @gst_video_decoder_drop_subframe, to allow the base class to do timestamp and offset tracking, and possibly to requeue the frame for a later attempt in the case of reverse playback.
Shutdown phase
- The GstVideoDecoder class calls @stop to inform the subclass that data
parsing will be stopped.
Additional Notes
- Seeking/Flushing
- When the pipeline is seeked or otherwise flushed, the subclass is
informed via a call to its @reset callback, with the hard parameter set to true. This indicates the subclass should drop any internal data queues and timestamps and prepare for a fresh set of buffers to arrive for parsing and decoding.
- End Of Stream
- At end-of-stream, the subclass @parse function may be called some final
times with the at_eos parameter set to true, indicating that the element should not expect any more data to be arriving, and it should parse and remaining frames and call [gstvideo.video_decoder.VideoDecoder.haveFrame] if possible.
The subclass is responsible for providing pad template caps for source and sink pads. The pads need to be named "sink" and "src". It also needs to provide information about the output caps, when they are known. This may be when the base class calls the subclass' @set_format function, though it might be during decoding, before calling @gst_video_decoder_finish_frame. This is done via @gst_video_decoder_set_output_state
The subclass is also responsible for providing (presentation) timestamps (likely based on corresponding input ones). If that is not applicable or possible, the base class provides limited framerate based interpolation.
Similarly, the base class provides some limited (legacy) seeking support if specifically requested by the subclass, as full-fledged support should rather be left to upstream demuxer, parser or alike. This simple approach caters for seeking and duration reporting using estimated input bitrates. To enable it, a subclass should call @gst_video_decoder_set_estimate_rate to enable handling of incoming byte-streams.
The base class provides some support for reverse playback, in particular in case incoming data is not packetized or upstream does not provide fragments on keyframe boundaries. However, the subclass should then be prepared for the parsing and frame processing stage to occur separately (in normal forward processing, the latter immediately follows the former), The subclass also needs to ensure the parsing stage properly marks keyframes, unless it knows the upstream elements will do so properly for incoming data.
The bare minimum that a functional subclass needs to implement is:
- Provide pad templates
- Inform the base class of output caps via
@gst_video_decoder_set_output_state
- Parse input data, if it is not considered packetized from upstream
Data will be provided to @parse which should invoke @gst_video_decoder_add_to_frame and @gst_video_decoder_have_frame to separate the data belonging to each video frame.
- Accept data in @handle_frame and provide decoded results to
@gst_video_decoder_finish_frame, or call @gst_video_decoder_drop_frame.
VideoDecoder self()Returns `this`, for use in `with` statements.VideoDecoderGidBuilder builder()Get builder for [gstvideo.video_decoder.VideoDecoder] Returns: New builder objectgstvideo.types.VideoDecoderRequestSyncPointFlags automaticRequestSyncPointFlags() @propertyGet `automaticRequestSyncPointFlags` property. Returns: GstVideoDecoderRequestSyncPointFlags to use for the automatically requested sync points if `automatic-request-sync-points` is enabled.void automaticRequestSyncPointFlags(gstvideo.types.VideoDecoderRequestSyncPointFlags propval) @propertySet `automaticRequestSyncPointFlags` property. Params: propval = GstVideoDecoderRequestSyncPointFlags to use for the automatically requested sync points if `automatic-request-sync-points` is enabled.bool automaticRequestSyncPoints() @propertyGet `automaticRequestSyncPoints` property. Returns: If set to true the decoder will automatically request sync points when it seems like a good idea, e.g. if the first frames are not key frames or ...void automaticRequestSyncPoints(bool propval) @propertySet `automaticRequestSyncPoints` property. Params: propval = If set to true the decoder will automatically request sync points when it seems like a good idea, e.g. if the first frames are not key f...bool discardCorruptedFrames() @propertyGet `discardCorruptedFrames` property. Returns: If set to true the decoder will discard frames that are marked as corrupted instead of outputting them.void discardCorruptedFrames(bool propval) @propertySet `discardCorruptedFrames` property. Params: propval = If set to true the decoder will discard frames that are marked as corrupted instead of outputting them.int maxErrors() @propertyGet `maxErrors` property. Returns: Maximum number of tolerated consecutive decode errors. See [gstvideo.video_decoder.VideoDecoder.setMaxErrors] for more details.void maxErrors(int propval) @propertySet `maxErrors` property. Params: propval = Maximum number of tolerated consecutive decode errors. See [gstvideo.video_decoder.VideoDecoder.setMaxErrors] for more details.ulong minForceKeyUnitInterval() @propertyGet `minForceKeyUnitInterval` property. Returns: Minimum interval between force-key-unit events sent upstream by the decoder. Setting this to 0 will cause every event to be handled, setting this to...void minForceKeyUnitInterval(ulong propval) @propertySet `minForceKeyUnitInterval` property. Params: propval = Minimum interval between force-key-unit events sent upstream by the decoder. Setting this to 0 will cause every event to be handled, settin...bool qos() @propertyGet `qos` property. Returns: If set to true the decoder will handle QoS events received from downstream elements. This includes dropping output frames which are detected as late using the metrics r...void qos(bool propval) @propertySet `qos` property. Params: propval = If set to true the decoder will handle QoS events received from downstream elements. This includes dropping output frames which are detected as late using the ...void addToFrame(int nBytes)Removes next n_bytes of input data and adds it to currently parsed frame.gst.buffer.Buffer allocateOutputBuffer()Helper function that allocates a buffer to hold a video frame for decoder's current #GstVideoCodecState.gst.types.FlowReturn allocateOutputFrame(gstvideo.video_codec_frame.VideoCodecFrame frame)Helper function that allocates a buffer to hold a video frame for decoder's current #GstVideoCodecState. Subclass should already have configured video state and set src pad caps.gst.types.FlowReturn allocateOutputFrameWithParams(gstvideo.video_codec_frame.VideoCodecFrame frame, gst.types.BufferPoolAcquireParams params)Same as #gstvideodecoderallocateoutputframe except it allows passing #GstBufferPoolAcquireParams to the sub call gstbufferpoolacquire_buffer.gst.types.FlowReturn dropFrame(gstvideo.video_codec_frame.VideoCodecFrame frame)Similar to [gstvideo.video_decoder.VideoDecoder.finishFrame], but drops frame in any case and posts a QoS message with the frame's details on the bus. In any case, the frame is considered finished ...gst.types.FlowReturn dropSubframe(gstvideo.video_codec_frame.VideoCodecFrame frame)Drops input data. The frame is not considered finished until the whole frame is finished or dropped by the subclass.gst.types.FlowReturn finishFrame(gstvideo.video_codec_frame.VideoCodecFrame frame)frame should have a valid decoded data buffer, whose metadata fields are then appropriately set according to frame data and pushed downstream. If no output data is provided, frame is considered ski...gst.types.FlowReturn finishSubframe(gstvideo.video_codec_frame.VideoCodecFrame frame)Indicate that a subframe has been finished to be decoded by the subclass. This method should be called for all subframes except the last subframe where gstvideodecoderfinishframe should be called i...void getAllocator(out gst.allocator.Allocator allocator, out gst.allocation_params.AllocationParams params)Lets #GstVideoDecoder sub-classes to know the memory allocator used by the base class and its params.int getEstimateRate()gstvideo.video_codec_frame.VideoCodecFrame getFrame(int frameNumber)Get a pending unfinished #GstVideoCodecFramegstvideo.video_codec_frame.VideoCodecFrame[] getFrames()Get all pending unfinished #GstVideoCodecFrame Returns: pending unfinished #GstVideoCodecFrame.uint getInputSubframeIndex(gstvideo.video_codec_frame.VideoCodecFrame frame)Queries the number of the last subframe received by the decoder baseclass in the frame.void getLatency(out gst.types.ClockTime minLatency, out gst.types.ClockTime maxLatency)Query the configured decoder latency. Results will be returned via minlatency and maxlatency.gst.types.ClockTimeDiff getMaxDecodeTime(gstvideo.video_codec_frame.VideoCodecFrame frame)Determines maximum possible decoding time for frame that will allow it to decode and arrive in time (as determined by QoS events). In particular, a negative result means decoding in time is no long...int getMaxErrors()bool getNeedsFormat()Queries decoder required format handling. Returns: true if required format handling is enabled.bool getNeedsSyncPoint()Queries if the decoder requires a sync point before it starts outputting data in the beginning. Returns: true if a sync point is required in the beginning.gstvideo.video_codec_frame.VideoCodecFrame getOldestFrame()Get the oldest pending unfinished #GstVideoCodecFrame Returns: oldest pending unfinished #GstVideoCodecFrame.gstvideo.video_codec_state.VideoCodecState getOutputState()Get the #GstVideoCodecState currently describing the output stream. Returns: #GstVideoCodecState describing format of video data.bool getPacketized()Queries whether input data is considered packetized or not by the base class. Returns: TRUE if input data is considered packetized.size_t getPendingFrameSize()Returns the number of bytes previously added to the current frame by calling [gstvideo.video_decoder.VideoDecoder.addToFrame]. Returns: The number of bytes pending for the current frameuint getProcessedSubframeIndex(gstvideo.video_codec_frame.VideoCodecFrame frame)Queries the number of subframes in the frame processed by the decoder baseclass.double getQosProportion()bool getSubframeMode()Queries whether input data is considered as subframes or not by the base class. If FALSE, each input buffer will be considered as a full frame. Returns: TRUE if input data is considered as sub frames.gst.types.FlowReturn haveFrame()Gathers all data collected for currently parsed frame, gathers corresponding metadata and passes it along for further processing, i.e. handle_frame. Returns: a #GstFlowReturngst.types.FlowReturn haveLastSubframe(gstvideo.video_codec_frame.VideoCodecFrame frame)Indicates that the last subframe has been processed by the decoder in frame. This will release the current frame in video decoder allowing to receive new frames from upstream elements. This method ...void mergeTags(gst.tag_list.TagList tags, gst.types.TagMergeMode mode)Sets the audio decoder tags and how they should be merged with any upstream stream tags. This will override any tags previously-set with [gstaudio.audio_decoder.AudioDecoder.mergeTags].bool negotiate()Negotiate with downstream elements to currently configured #GstVideoCodecState. Unmark GSTPADFLAGNEEDRECONFIGURE in any case. But mark it again if negotiate fails. Returns: true if the negotiation ...gst.caps.Caps proxyGetcaps(gst.caps.Caps caps = null, gst.caps.Caps filter = null)Returns caps that express caps (or sink template caps if caps == NULL) restricted to resolution/format/... combinations supported by downstream elements.void releaseFrame(gstvideo.video_codec_frame.VideoCodecFrame frame)Similar to [gstvideo.video_decoder.VideoDecoder.dropFrame], but simply releases frame without any processing other than removing it from list of pending frames, after which it is considered finishe...void requestSyncPoint(gstvideo.video_codec_frame.VideoCodecFrame frame, gstvideo.types.VideoDecoderRequestSyncPointFlags flags)Allows the #GstVideoDecoder subclass to request from the base class that a new sync should be requested from upstream, and that frame was the frame when the subclass noticed that a new sync point i...void setEstimateRate(bool enabled)Allows baseclass to perform byte to time estimated conversion.gstvideo.video_codec_state.VideoCodecState setInterlacedOutputState(gstvideo.types.VideoFormat fmt, gstvideo.types.VideoInterlaceMode interlaceMode, uint width, uint height, gstvideo.video_codec_state.VideoCodecState reference = null)Same as #[gstvideo.video_decoder.VideoDecoder.setOutputState] but also allows you to also set the interlacing mode.void setLatency(gst.types.ClockTime minLatency, gst.types.ClockTime maxLatency)Lets #GstVideoDecoder sub-classes tell the baseclass what the decoder latency is. If the provided values changed from previously provided ones, this will also post a LATENCY message on the bus so t...void setMaxErrors(int num)Sets numbers of tolerated decoder errors, where a tolerated one is then only warned about, but more than tolerated will lead to fatal error. You can set -1 for never returning fatal errors. Defaul...void setNeedsFormat(bool enabled)Configures decoder format needs. If enabled, subclass needs to be negotiated with format caps before it can process any data. It will then never be handed any data before it has been configured. ...void setNeedsSyncPoint(bool enabled)Configures whether the decoder requires a sync point before it starts outputting data in the beginning. If enabled, the base class will discard all non-sync point frames in the beginning and after ...gstvideo.video_codec_state.VideoCodecState setOutputState(gstvideo.types.VideoFormat fmt, uint width, uint height, gstvideo.video_codec_state.VideoCodecState reference = null)Creates a new #GstVideoCodecState with the specified fmt, width and height as the output state for the decoder. Any previously set output state on decoder will be replaced by the newly created one.void setPacketized(bool packetized)Allows baseclass to consider input data as packetized or not. If the input is packetized, then the parse method will not be called.void setSubframeMode(bool subframeMode)If this is set to TRUE, it informs the base class that the subclass can receive the data at a granularity lower than one frame.void setUseDefaultPadAcceptcaps(bool use)Lets #GstVideoDecoder sub-classes decide if they want the sink pad to use the default pad query handler to reply to accept-caps queries.T automaticRequestSyncPointFlags(gstvideo.types.VideoDecoderRequestSyncPointFlags propval)Set `automaticRequestSyncPointFlags` property. Params: propval = GstVideoDecoderRequestSyncPointFlags to use for the automatically requested sync points if `automatic-request-sync-points` is enable...T automaticRequestSyncPoints(bool propval)Set `automaticRequestSyncPoints` property. Params: propval = If set to true the decoder will automatically request sync points when it seems like a good idea, e.g. if the first frames are not key f...T discardCorruptedFrames(bool propval)Set `discardCorruptedFrames` property. Params: propval = If set to true the decoder will discard frames that are marked as corrupted instead of outputting them. Returns: Builder instance for fluent...T maxErrors(int propval)Set `maxErrors` property. Params: propval = Maximum number of tolerated consecutive decode errors. See [gstvideo.video_decoder.VideoDecoder.setMaxErrors] for more details. Returns: Builder instance...T minForceKeyUnitInterval(ulong propval)Set `minForceKeyUnitInterval` property. Params: propval = Minimum interval between force-key-unit events sent upstream by the decoder. Setting this to 0 will cause every event to be handled, settin...T qos(bool propval)Set `qos` property. Params: propval = If set to true the decoder will handle QoS events received from downstream elements. This includes dropping output frames which are detected as late using the ...Fluent builder for [gstvideo.video_decoder.VideoDecoder]