< GeeXLab Reference Guide />

> Back to Reference Guide Index


gh_av library

Description

gh_av is the module that manages audio/video playback. This module is based on FFmpeg and is available for all platforms: Windows, Linux, macOS, Raspberry Pi and Tinker Board.


Number of functions: 23

  1. gh_av.decoder_close ()
  2. gh_av.decoder_open ()
  3. gh_av.get_codec_name ()
  4. gh_av.get_duration ()
  5. gh_av.get_elapsed_time ()
  6. gh_av.get_num_frames ()
  7. gh_av.get_streams_index ()
  8. gh_av.pause ()
  9. gh_av.process_frame ()
  10. gh_av.reset_streams ()
  11. gh_av.set_volume ()
  12. gh_av.start_audio_video_processing ()
  13. gh_av.stop_audio_video_processing ()
  14. gh_av.video_get_resolution ()
  15. gh_av.video_init_texture ()
  16. gh_av.video_update_texture ()
  17. gh_av.video_init_texture_rgb24 ()
  18. gh_av.video_update_texture_rgb24 ()
  19. gh_av.video_init_texture_yuv420 ()
  20. gh_av.video_update_texture_yuv420 ()
  21. gh_av.seek_frame_time ()
  22. gh_av.set_option_1i ()
  23. gh_av.set_option_str ()



decoder_close

Description

Cleans up and closes an audio-video object.


Syntax

gh_av.decoder_close(
 av_id
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_av.decoder_close(av_id)
			


decoder_open

Description

Opens an audio/video file.


Syntax

av_id = gh_av.decoder_open(
 filename,
 loop_mode
)

Languages


Parameters


Return Values


Code sample


av_id = gh_av.decoder_open(filename, 1)
			


get_codec_name

Description

Returns the codec names of video and audio streams.


Syntax

video_codec, audio_codec = gh_av.get_codec_name(
 av_id
)

Languages


Parameters


Return Values


Code sample


video_codec, audio_codec = gh_av.get_codec_name(av_id)
			


get_duration

Description

Duration of the audio-video file.


Syntax

duration = gh_av.get_duration(
 av_id
)

Languages


Parameters


Return Values


Code sample


duration = gh_av.get_duration(av_id)
			


get_elapsed_time

Description

Returns the elapsed time since the start of playing.


Syntax

elapsed_time = gh_av.get_elapsed_time(
 av_id
)

Languages


Parameters


Return Values


Code sample


elapsed_time = gh_av.get_elapsed_time(av_id)
			


get_num_frames

Description

Returns the numbers of frames of video and audio streams.


Syntax

video_frames, audio_frames = gh_av.get_num_frames(
 av_id
)

Languages


Parameters


Return Values


Code sample


video_frames, audio_frames = gh_av.get_num_frames(av_id)
			


get_streams_index

Description

Returns the audio and video stream indices. Useful to know if an audio video file has an audio or a video stream.


Syntax

video_index, audio_index = gh_av.get_streams_index(
 av_id
)

Languages


Parameters


Return Values


Code sample


audio, video = gh_av.get_streams_index(av_id)
			


pause

Description

Pauses an audio-video playback.


Syntax

gh_av.pause(
 av_id,
 state
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_av.pause(av_id, 1)
			


process_frame

Description

Process/fetch the current audio-video frame. You can call this function in a FRAME script if you don't use start_audio_video_processing() / stop_audio_video_processing().


Syntax

gh_av.process_frame(
 av_id,
 process_video,
 process_audio
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_av.process_frame(av_id, 1, 1)
			


reset_streams

Description

Resets the audio-video streams.


Syntax

gh_av.reset_streams(
 av_id
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_av.reset_streams(av_id)
			


set_volume

Description

Sets the volume of the audio stream.


Syntax

gh_av.set_volume(
 av_id,
 volume
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_av.set_volume(av_id, 0.7)
			


start_audio_video_processing

Description

Starts the audio-video processing thread.


Syntax

gh_av.start_audio_video_processing(
 av_id,
 process_video,
 process_audio
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_av.start_audio_video_processing(av_id, 1, 1)
			


stop_audio_video_processing

Description

Stops the audio-video processing thread.


Syntax

gh_av.stop_audio_video_processing(
 av_id
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_av.stop_audio_video_processing(av_id)
			


video_get_resolution

Description

Returns the resolution in pixels of video frames.


Syntax

width, height = gh_av.video_get_resolution(
 av_id
)

Languages


Parameters


Return Values


Code sample


duration = gh_av.video_get_resolution(av_id)
			


video_init_texture

Description

(DEPRECATED) Creates a texture based on video parameters. This texture can be used with all gh_texture functions.


Syntax

tex_id = gh_av.video_init_texture(
 av_id,
 pf
)

Languages


Parameters


Return Values


Code sample


tex_id = gh_av.video_init_texture(av_id, pf) -- DEPRECATED
			


video_update_texture

Description

(DEPRECATED) Updates the texture GPU memory with current video frame.


Syntax

gh_av.video_update_texture(
 av_id,
 tex_id
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_av.video_update_texture(av_id, tex_id) -- DEPRECATED
			


video_init_texture_rgb24

Description

Creates a texture based on video parameters. This texture can be used with all gh_texture functions. The texture has the RGB24 pixel format (same than PF_U8_RGB): 3 bytes per pixel.


Syntax

gh_av.video_init_texture_rgb24(
 av_id
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


tex_id = gh_av.video_init_texture_rgb24(av_id)
			


video_update_texture_rgb24

Description

Updates the texture GPU memory with current video frame. The texture must have the RGB24 pixel format.


Syntax

gh_av.video_update_texture_rgb24(
 av_id,
 tex_id
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_av.video_update_texture_rgb24(av_id, tex_id)
			


video_init_texture_yuv420

Description

Creates three textures (Y, U and V) based on video parameters. These textures can be used with all gh_texture functions. Each texture has the PF_U8_R pixel format: 1 byte per pixel.


Syntax

gh_av.video_init_texture_yuv420(
 av_id,
 texY, texU, texV
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


texY, texU, texV = gh_av.video_init_texture_rgb24(av_id)
			


video_update_texture_yuv420

Description

Updates the three YUV420 textures with current video frame. Texture must have the PF_U8_R pixel format.


Syntax

gh_av.video_update_texture_yuv420(
 av_id,
 texY,
 tuY,
 texU,
 tuU,
 texY,
 tuV
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


tuY = 0			
tuU = 1			
tuV = 2			
gh_av.video_update_texture_yuv420(av_id, texY, tuY, texU, tuU, texV, tuV)
			


seek_frame_time

Description

Allow to seek frames in seconds.


Syntax

ret = gh_av.seek_frame_time(
 av_id,
 frame_time_sec
)

Languages


Parameters


Return Values


Code sample


"Seek the frame 20 sec before the end of the video"
frame_time_sec = video_duration_sec - 20
ret = gh_av.seek_frame_time(av_id, frame_time_sec)
			


set_option_1i

Description

Sets an option.


Syntax

gh_av.set_option_1i(
 name,
 x
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


# Possible options:
# "num_video_threads"
# "num_audio_threads"

gh_av.set_option_1i("num_video_threads", 4)
			


set_option_str

Description

Sets an option.


Syntax

gh_av.set_option_str(
 name,
 x
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


# Possible options:
# "hw_device" 
#  - possible values: "cuda"

# "video_pixel_fmt"
#  - possible values: "yuv420p" and "rgb24"

gh_av.set_option_str("hw_device", "cuda")
			






GeeXLab Rootard Guide | Downloads | Contact | Newsletter