< 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
- gh_av.decoder_close ()
- gh_av.decoder_open ()
- gh_av.get_codec_name ()
- gh_av.get_duration ()
- gh_av.get_elapsed_time ()
- gh_av.get_num_frames ()
- gh_av.get_streams_index ()
- gh_av.pause ()
- gh_av.process_frame ()
- gh_av.reset_streams ()
- gh_av.set_volume ()
- gh_av.start_audio_video_processing ()
- gh_av.stop_audio_video_processing ()
- gh_av.video_get_resolution ()
- gh_av.video_init_texture ()
- gh_av.video_update_texture ()
- gh_av.video_init_texture_rgb24 ()
- gh_av.video_update_texture_rgb24 ()
- gh_av.video_init_texture_yuv420 ()
- gh_av.video_update_texture_yuv420 ()
- gh_av.seek_frame_time ()
- gh_av.set_option_1i ()
- 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
- av_id [ID]: audio-video object identifier
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
- filename [STRING]: audio filename
- loop_mode [BOOLEAN]: looping: 1 (true) or 0 (false)
Return Values
- av_id [ID]: audio-video object identifier
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
- av_id [ID]: audio-video object identifier
Return Values
- video_codec, audio_codec [STRING]: codec names
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
- av_id [ID]: audio-video object identifier
Return Values
- duration [REAL]: duration in seconds
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
- av_id [ID]: audio-video object identifier
Return Values
- elapsed_time [REAL]: elapsed time in seconds since the start of playing
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
- av_id [ID]: audio-video object identifier
Return Values
- video_frames, audio_frames [INTEGER]: number of frames
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
- av_id [ID]: audio-video object identifier
Return Values
- video_index, audio_index [INTEGER]: video and audio streams indices: -1 if the stream is not present and >= 0 if the stream is present
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
- av_id [ID]: audio-video object identifier
- state [BOOLEAN]: pause: 1 (true) or 0 (false)
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
- av_id [ID]: audio-video object identifier
- process_video [BOOLEAN]: video stream processing: 1 (enabled) or 0 (disabled)
- process_audio [BOOLEAN]: audio stream processing: 1 (enabled) or 0 (disabled)
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
- av_id [ID]: audio-video object identifier
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
- av_id [ID]: audio-video object identifier
- volume [REAL]: volume from 0.0 to 1.0
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
- av_id [ID]: audio-video object identifier
- process_video [BOOLEAN]: video stream processing: 1 (enabled) or 0 (disabled)
- process_audio [BOOLEAN]: audio stream processing: 1 (enabled) or 0 (disabled)
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
- av_id [ID]: audio-video object identifier
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
- av_id [ID]: audio-video object identifier
Return Values
- width, height [INTEGER]: resolution
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
- av_id [ID]: audio-video object identifier
- pf [INTEGER]: pixel format
Return Values
- tex_id [ID]: texture identifier
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
- av_id [ID]: audio-video object identifier
- tex_id [ID]: texture identifier
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
- av_id [ID]: audio-video object identifier
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
- av_id [ID]: audio-video object identifier
- tex_id [ID]: texture identifier
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
- av_id [ID]: audio-video object identifier
- texY, texU, texV [ID]: the three texture identifiers
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
- av_id [ID]: audio-video object identifier
- texY [ID]: texture identifier
- tuY [INTEGER]: texture unit for texY
- texU [ID]: texture identifier
- tuU [INTEGER]: texture unit for texU
- texY [ID]: texture identifier
- tuV [INTEGER]: texture unit for texV
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
- av_id [ID]: audio-video object identifier
- frame_time_sec [INTEGER]: frame time in seconds
Return Values
- ret [BOOLEAN]: return code: 1 (success) or 0 (error)
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
- name [STRING]: name of the option
- x [INTEGER]: value
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
- name [STRING]: name of the option
- x [STRING]: value
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")
| |