This module includes video and audio utilities to go along with the core module to make synthetic video generation a smooth experience.

Time utils

A collection of functions for time related operations.

to_hhmmss[source]

to_hhmmss(x:int)

Convert time from secs (int) to hh:mm:ss (str).

to_hhmmss(5)
'00:00:05'
to_hhmmss(10000)
'02:46:40'

test_eq(to_hhmmss(100), '00:01:40')
test_eq(to_hhmmss(0), '00:00:00')
test_fail(to_hhmmss, -1)

to_secs[source]

to_secs(x:str)

Convert time from hh:mm:ss (str) format to seconds (int).

to_secs('02:46:40')
10000
to_secs('00:01:05')
65
test_eq(to_secs('00:00:00'), 0)
test_eq(to_secs('00:00:05'), 5)

Video utils

A collection of functions for video related operations

display_video[source]

display_video(video)

display_video('Anna.mp4')

check_resolution[source]

check_resolution(video:Union[str, Path])

Check the resolution of a video.

check_resolution('Anna.mp4')
{'height': 720, 'width': 1280}
assert check_resolution('Anna.mp4') == {'height': 720, 'width': 1280}

check_fps[source]

check_fps(video:Union[str, Path], round_res=False)

Get the fps of a video

check_fps('Anna.mp4')
29.97
check_fps('Anna.mp4', round_res = True)
30
assert check_fps('Anna.mp4') == 29.97
assert check_fps('Anna.mp4', True) == 30

Audio utils

A collection of functions for audio related operations

play_audio[source]

play_audio(audio)

change_audio_format[source]

change_audio_format(audio:Union[str, Path], outfile:Union[str, Path])

Change the format of audio file. Example, converting mp3 to wav. Works with all formats supported by ffmpeg.

Let's convert a .wav file to a .mp3 file

change_audio_format('demo_audio.wav', 'my_audio.mp3')
change_audio_format('my_audio.mp3', 'another_audio.flac')
play_audio('my_audio.mp3')

trim_audio[source]

trim_audio(audio:Union[str, Path], start_time:int, end_time:int, outfile:Union[str, Path]='trimmed_audio.mp3')

Trim an audio file. Start and end times are in seconds. Works with all formats supported by ffmpeg.

trim_audio('my_audio.mp3', 0, 5)
Path('trimmed_audio.mp3')
play_audio('trimmed_audio.mp3')
trim_audio('my_audio.mp3', 5, 10, 'small_audio.mp3')
Path('small_audio.mp3')
play_audio('small_audio.mp3')

trim_audio('my_audio.mp3', 10, 15, 'small_audio.wav')
Path('small_audio.wav')
play_audio('small_audio.wav')

change_volume[source]

change_volume(audio:Union[str, Path], vol, outfile='changed_vol.mp3')

Increase or decrease the volume of an audio by 'vol' dB.

play_audio('small_audio.wav')
loud_audio = change_volume('small_audio.wav', 5)
play_audio(loud_audio)
quiet_audio = change_volume('small_audio.wav', -5)
play_audio(quiet_audio)

loop_audio[source]

loop_audio(audio, times=2, outfile='looped_audio.mp3')

Loop an audio times times.

looped_audio = loop_audio('small_audio.mp3')
play_audio(looped_audio)
looped_audio = loop_audio('small_audio.mp3', 4)
play_audio(looped_audio)

concat_audios[source]

concat_audios(audio, other_audios, outfile='concat_audios.mp3')

concat audios. Pass a main audio and one or more (list of audios) to concat

c = concat_audios('trimmed_audio.mp3', 'small_audio.mp3')
play_audio(c)
c = concat_audios('trimmed_audio.mp3', ['small_audio.mp3', 'small_audio.wav'])
play_audio(c)