AudioClip

AudioClip

class moviepy.audio.AudioClip.AudioClip(make_frame=None, duration=None)[source]

Bases: moviepy.Clip.Clip

Base class for audio clips.

See AudioFileClip and CompositeSoundClip for usable classes.

An AudioClip is a Clip with a make_frame attribute of the form `` t -> [ f_t ]`` for mono sound and t-> [ f1_t, f2_t ] for stereo sound (the arrays are Numpy arrays). The f_t are floats between -1 and 1. These bounds can be trespassed wihtout problems (the program will put the sound back into the bounds at conversion time, without much impact).

Parameters:

make_frame

A function t-> frame at time t. The frame does not mean much for a sound, it is just a float. What ‘makes’ the sound are the variations of that float in the time.

nchannels

Number of channels (one or two for mono or stereo).

Examples

>>> # Plays the note A (a sine wave of frequency 404HZ)
>>> import numpy as np
>>> make_frame = lambda t : 2*[ np.sin(404 * 2 * np.pi * t) ]
>>> clip = AudioClip(make_frame, duration=5)
>>> clip.preview()
copy()

Shallow copy of the clip.

Returns a shwallow copy of the clip whose mask and audio will be shallow copies of the clip’s mask and audio if they exist.

This method is intensively used to produce new clips every time there is an outplace transformation of the clip (clip.resize, clip.subclip, etc.)

cutout(ta, tb)

Returns a clip playing the content of the current clip but skips the extract between ta and tb, which can be expressed in seconds (15.35), in (min, sec), in (hour, min, sec), or as a string: ‘01:03:05.35’. If the original clip has a duration attribute set, the duration of the returned clip is automatically computed as `` duration - (tb - ta)``.

The resulting clip’s audio and mask will also be cutout if they exist.

fl(fun, apply_to=[], keep_duration=True)

General processing of a clip.

Returns a new Clip whose frames are a transformation (through function fun) of the frames of the current clip.

Parameters:

fun

A function with signature (gf,t -> frame) where gf will represent the current clip’s get_frame method, i.e. gf is a function (t->image). Parameter t is a time in seconds, frame is a picture (=Numpy array) which will be returned by the transformed clip (see examples below).

apply_to

Can be either 'mask', or 'audio', or ['mask','audio']. Specifies if the filter fl should also be applied to the audio or the mask of the clip, if any.

keep_duration

Set to True if the transformation does not change the duration of the clip.

Examples

In the following newclip a 100 pixels-high clip whose video content scrolls from the top to the bottom of the frames of clip.

>>> fl = lambda gf,t : gf(t)[int(t):int(t)+50, :]
>>> newclip = clip.fl(fl, apply_to='mask')
fl_time(t_func, apply_to=[], keep_duration=False)

Returns a Clip instance playing the content of the current clip but with a modified timeline, time t being replaced by another time t_func(t).

Parameters:

t_func:

A function t-> new_t

apply_to:

Can be either ‘mask’, or ‘audio’, or [‘mask’,’audio’]. Specifies if the filter fl should also be applied to the audio or the mask of the clip, if any.

keep_duration:

False (default) if the transformation modifies the duration of the clip.

Examples

>>> # plays the clip (and its mask and sound) twice faster
>>> newclip = clip.fl_time(lambda: 2*t, apply_to=['mask','audio'])
>>>
>>> # plays the clip starting at t=3, and backwards:
>>> newclip = clip.fl_time(lambda: 3-t)
fx(func, *args, **kwargs)

Returns the result of func(self, *args, **kwargs). for instance

>>> newclip = clip.fx(resize, 0.2, method='bilinear')

is equivalent to

>>> newclip = resize(clip, 0.2, method='bilinear')

The motivation of fx is to keep the name of the effect near its parameters, when the effects are chained:

>>> from moviepy.video.fx import volumex, resize, mirrorx
>>> clip.fx( volumex, 0.5).fx( resize, 0.3).fx( mirrorx )
>>> # Is equivalent, but clearer than
>>> resize( volumex( mirrorx( clip ), 0.5), 0.3)
get_frame(t)

Gets a numpy array representing the RGB picture of the clip at time t or (mono or stereo) value for a sound clip

is_playing(t)

If t is a time, returns true if t is between the start and the end of the clip. t can be expressed in seconds (15.35), in (min, sec), in (hour, min, sec), or as a string: ‘01:03:05.35’. If t is a numpy array, returns False if none of the t is in theclip, else returns a vector [b_1, b_2, b_3...] where b_i is true iff tti is in the clip.

iter_chunks(chunksize=None, chunk_duration=None, fps=None, quantize=False, nbytes=2, progress_bar=False)[source]

Iterator that returns the whole sound array of the clip by chunks

iter_frames(fps=None, with_times=False, progress_bar=False, dtype=None)

Iterates over all the frames of the clip.

Returns each frame of the clip as a HxWxN np.array, where N=1 for mask clips and N=3 for RGB clips.

This function is not really meant for video editing. It provides an easy way to do frame-by-frame treatment of a video, for fields like science, computer vision...

The fps (frames per second) parameter is optional if the clip already has a fps attribute.

Use dtype=”uint8” when using the pictures to write video, images...

Examples

>>> # prints the maximum of red that is contained
>>> # on the first line of each frame of the clip.
>>> from moviepy.editor import VideoFileClip
>>> myclip = VideoFileClip('myvideo.mp4')
>>> print ( [frame[0,:,0].max()
             for frame in myclip.iter_frames()])
set_duration(t, change_end=True)

Returns a copy of the clip, with the duration attribute set to t, which can be expressed in seconds (15.35), in (min, sec), in (hour, min, sec), or as a string: ‘01:03:05.35’. Also sets the duration of the mask and audio, if any, of the returned clip. If change_end is False, the start attribute of the clip will be modified in function of the duration and the preset end of the clip.

set_end(t)

Returns a copy of the clip, with the end attribute set to t, which can be expressed in seconds (15.35), in (min, sec), in (hour, min, sec), or as a string: ‘01:03:05.35’. Also sets the duration of the mask and audio, if any, of the returned clip.

set_fps(fps)

Returns a copy of the clip with a new default fps for functions like write_videofile, iterframe, etc.

set_ismask(ismask)

Says wheter the clip is a mask or not (ismask is a boolean)

set_make_frame(make_frame)

Sets a make_frame attribute for the clip. Useful for setting arbitrary/complicated videoclips.

set_memoize(memoize)

Sets wheter the clip should keep the last frame read in memory

set_start(t, change_end=True)

Returns a copy of the clip, with the start attribute set to t, which can be expressed in seconds (15.35), in (min, sec), in (hour, min, sec), or as a string: ‘01:03:05.35’.

If change_end=True and the clip has a duration attribute, the end atrribute of the clip will be updated to start+duration.

If change_end=False and the clip has a end attribute, the duration attribute of the clip will be updated to end-start

These changes are also applied to the audio and mask clips of the current clip, if they exist.

subclip(t_start=0, t_end=None)

Returns a clip playing the content of the current clip between times t_start and t_end, which can be expressed in seconds (15.35), in (min, sec), in (hour, min, sec), or as a string: ‘01:03:05.35’. If t_end is not provided, it is assumed to be the duration of the clip (potentially infinite). If t_end is a negative value, it is reset to ``clip.duration + t_end. ``. For instance:

>>> # cut the last two seconds of the clip:
>>> newclip = clip.subclip(0,-2)

If t_end is provided or if the clip has a duration attribute, the duration of the returned clip is set automatically.

The mask and audio of the resulting subclip will be subclips of mask and audio the original clip, if they exist.

to_audiofile(*a, **kw)

The function to_audiofile is deprecated and is kept temporarily for backwards compatibility. Please use the new name, write_audiofile, instead.

to_soundarray(tt=None, fps=None, quantize=False, nbytes=2, buffersize=50000)[source]

Transforms the sound into an array that can be played by pygame or written in a wav file. See AudioClip.preview.

Parameters:

fps

Frame rate of the sound for the conversion. 44100 for top quality.

nbytes

Number of bytes to encode the sound: 1 for 8bit sound, 2 for 16bit, 4 for 32bit sound.

write_audiofile(filename, fps=44100, nbytes=2, buffersize=2000, codec=None, bitrate=None, ffmpeg_params=None, write_logfile=False, verbose=True, progress_bar=True)[source]

Writes an audio file from the AudioClip.

Parameters:

filename

Name of the output file

fps

Frames per second

nbyte

Sample width (set to 2 for 16-bit sound, 4 for 32-bit sound)

codec

Which audio codec should be used. If None provided, the codec is determined based on the extension of the filename. Choose ‘pcm_s16le’ for 16-bit wav and ‘pcm_s32le’ for 32-bit wav.

bitrate

Audio bitrate, given as a string like ‘50k’, ‘500k’, ‘3000k’. Will determine the size and quality of the output file. Note that it mainly an indicative goal, the bitrate won’t necessarily be the this in the output file.

ffmpeg_params

Any additional parameters you would like to pass, as a list of terms, like [‘-option1’, ‘value1’, ‘-option2’, ‘value2’]

write_logfile

If true, produces a detailed logfile named filename + ‘.log’ when writing the file

verbose

Boolean indicating whether to print infomation

progress_bar

Boolean indicating whether to show the progress bar.

AudioFileClip

class moviepy.audio.io.AudioFileClip.AudioFileClip(filename, buffersize=200000, nbytes=2, fps=44100)[source]

Bases: moviepy.audio.AudioClip.AudioClip

An audio clip read from a sound file, or an array. The whole file is not loaded in memory. Instead, only a portion is read and stored in memory. this portion includes frames before and after the last frames read, so that it is fast to read the sound backward and forward.

Parameters:

snd

Either a soundfile name (of any extension supported by ffmpeg) or an array representing a sound. If the soundfile is not a .wav, it will be converted to .wav first, using the fps and bitrate arguments.

buffersize:

Size to load in memory (in number of frames)

temp_wav:

Name for the temporary wav file in case conversion is required. If not provided, the default will be filename.wav with some prefix. If the temp_wav already exists it will not be rewritten.

Examples

>>> snd = AudioFileClip("song.wav")
>>> snd = AudioFileClip("song.mp3", fps = 44100, bitrate=3000)
>>> snd = AudioFileClip(mySoundArray,fps=44100) # from a numeric array

Attributes

nbytes Number of bits per frame of the original audio file.
fps Number of frames per second in the audio file
buffersize See Parameters.
copy()

Shallow copy of the clip.

Returns a shwallow copy of the clip whose mask and audio will be shallow copies of the clip’s mask and audio if they exist.

This method is intensively used to produce new clips every time there is an outplace transformation of the clip (clip.resize, clip.subclip, etc.)

coreader()[source]

Returns a copy of the AudioFileClip, i.e. a new entrance point to the audio file. Use copy when you have different clips watching the audio file at different times.

cutout(ta, tb)

Returns a clip playing the content of the current clip but skips the extract between ta and tb, which can be expressed in seconds (15.35), in (min, sec), in (hour, min, sec), or as a string: ‘01:03:05.35’. If the original clip has a duration attribute set, the duration of the returned clip is automatically computed as `` duration - (tb - ta)``.

The resulting clip’s audio and mask will also be cutout if they exist.

fl(fun, apply_to=[], keep_duration=True)

General processing of a clip.

Returns a new Clip whose frames are a transformation (through function fun) of the frames of the current clip.

Parameters:

fun

A function with signature (gf,t -> frame) where gf will represent the current clip’s get_frame method, i.e. gf is a function (t->image). Parameter t is a time in seconds, frame is a picture (=Numpy array) which will be returned by the transformed clip (see examples below).

apply_to

Can be either 'mask', or 'audio', or ['mask','audio']. Specifies if the filter fl should also be applied to the audio or the mask of the clip, if any.

keep_duration

Set to True if the transformation does not change the duration of the clip.

Examples

In the following newclip a 100 pixels-high clip whose video content scrolls from the top to the bottom of the frames of clip.

>>> fl = lambda gf,t : gf(t)[int(t):int(t)+50, :]
>>> newclip = clip.fl(fl, apply_to='mask')
fl_time(t_func, apply_to=[], keep_duration=False)

Returns a Clip instance playing the content of the current clip but with a modified timeline, time t being replaced by another time t_func(t).

Parameters:

t_func:

A function t-> new_t

apply_to:

Can be either ‘mask’, or ‘audio’, or [‘mask’,’audio’]. Specifies if the filter fl should also be applied to the audio or the mask of the clip, if any.

keep_duration:

False (default) if the transformation modifies the duration of the clip.

Examples

>>> # plays the clip (and its mask and sound) twice faster
>>> newclip = clip.fl_time(lambda: 2*t, apply_to=['mask','audio'])
>>>
>>> # plays the clip starting at t=3, and backwards:
>>> newclip = clip.fl_time(lambda: 3-t)
fx(func, *args, **kwargs)

Returns the result of func(self, *args, **kwargs). for instance

>>> newclip = clip.fx(resize, 0.2, method='bilinear')

is equivalent to

>>> newclip = resize(clip, 0.2, method='bilinear')

The motivation of fx is to keep the name of the effect near its parameters, when the effects are chained:

>>> from moviepy.video.fx import volumex, resize, mirrorx
>>> clip.fx( volumex, 0.5).fx( resize, 0.3).fx( mirrorx )
>>> # Is equivalent, but clearer than
>>> resize( volumex( mirrorx( clip ), 0.5), 0.3)
get_frame(t)

Gets a numpy array representing the RGB picture of the clip at time t or (mono or stereo) value for a sound clip

is_playing(t)

If t is a time, returns true if t is between the start and the end of the clip. t can be expressed in seconds (15.35), in (min, sec), in (hour, min, sec), or as a string: ‘01:03:05.35’. If t is a numpy array, returns False if none of the t is in theclip, else returns a vector [b_1, b_2, b_3...] where b_i is true iff tti is in the clip.

iter_chunks(chunksize=None, chunk_duration=None, fps=None, quantize=False, nbytes=2, progress_bar=False)

Iterator that returns the whole sound array of the clip by chunks

iter_frames(fps=None, with_times=False, progress_bar=False, dtype=None)

Iterates over all the frames of the clip.

Returns each frame of the clip as a HxWxN np.array, where N=1 for mask clips and N=3 for RGB clips.

This function is not really meant for video editing. It provides an easy way to do frame-by-frame treatment of a video, for fields like science, computer vision...

The fps (frames per second) parameter is optional if the clip already has a fps attribute.

Use dtype=”uint8” when using the pictures to write video, images...

Examples

>>> # prints the maximum of red that is contained
>>> # on the first line of each frame of the clip.
>>> from moviepy.editor import VideoFileClip
>>> myclip = VideoFileClip('myvideo.mp4')
>>> print ( [frame[0,:,0].max()
             for frame in myclip.iter_frames()])
set_duration(t, change_end=True)

Returns a copy of the clip, with the duration attribute set to t, which can be expressed in seconds (15.35), in (min, sec), in (hour, min, sec), or as a string: ‘01:03:05.35’. Also sets the duration of the mask and audio, if any, of the returned clip. If change_end is False, the start attribute of the clip will be modified in function of the duration and the preset end of the clip.

set_end(t)

Returns a copy of the clip, with the end attribute set to t, which can be expressed in seconds (15.35), in (min, sec), in (hour, min, sec), or as a string: ‘01:03:05.35’. Also sets the duration of the mask and audio, if any, of the returned clip.

set_fps(fps)

Returns a copy of the clip with a new default fps for functions like write_videofile, iterframe, etc.

set_ismask(ismask)

Says wheter the clip is a mask or not (ismask is a boolean)

set_make_frame(make_frame)

Sets a make_frame attribute for the clip. Useful for setting arbitrary/complicated videoclips.

set_memoize(memoize)

Sets wheter the clip should keep the last frame read in memory

set_start(t, change_end=True)

Returns a copy of the clip, with the start attribute set to t, which can be expressed in seconds (15.35), in (min, sec), in (hour, min, sec), or as a string: ‘01:03:05.35’.

If change_end=True and the clip has a duration attribute, the end atrribute of the clip will be updated to start+duration.

If change_end=False and the clip has a end attribute, the duration attribute of the clip will be updated to end-start

These changes are also applied to the audio and mask clips of the current clip, if they exist.

subclip(t_start=0, t_end=None)

Returns a clip playing the content of the current clip between times t_start and t_end, which can be expressed in seconds (15.35), in (min, sec), in (hour, min, sec), or as a string: ‘01:03:05.35’. If t_end is not provided, it is assumed to be the duration of the clip (potentially infinite). If t_end is a negative value, it is reset to ``clip.duration + t_end. ``. For instance:

>>> # cut the last two seconds of the clip:
>>> newclip = clip.subclip(0,-2)

If t_end is provided or if the clip has a duration attribute, the duration of the returned clip is set automatically.

The mask and audio of the resulting subclip will be subclips of mask and audio the original clip, if they exist.

to_audiofile(*a, **kw)

The function to_audiofile is deprecated and is kept temporarily for backwards compatibility. Please use the new name, write_audiofile, instead.

to_soundarray(tt=None, fps=None, quantize=False, nbytes=2, buffersize=50000)

Transforms the sound into an array that can be played by pygame or written in a wav file. See AudioClip.preview.

Parameters:

fps

Frame rate of the sound for the conversion. 44100 for top quality.

nbytes

Number of bytes to encode the sound: 1 for 8bit sound, 2 for 16bit, 4 for 32bit sound.

write_audiofile(filename, fps=44100, nbytes=2, buffersize=2000, codec=None, bitrate=None, ffmpeg_params=None, write_logfile=False, verbose=True, progress_bar=True)

Writes an audio file from the AudioClip.

Parameters:

filename

Name of the output file

fps

Frames per second

nbyte

Sample width (set to 2 for 16-bit sound, 4 for 32-bit sound)

codec

Which audio codec should be used. If None provided, the codec is determined based on the extension of the filename. Choose ‘pcm_s16le’ for 16-bit wav and ‘pcm_s32le’ for 32-bit wav.

bitrate

Audio bitrate, given as a string like ‘50k’, ‘500k’, ‘3000k’. Will determine the size and quality of the output file. Note that it mainly an indicative goal, the bitrate won’t necessarily be the this in the output file.

ffmpeg_params

Any additional parameters you would like to pass, as a list of terms, like [‘-option1’, ‘value1’, ‘-option2’, ‘value2’]

write_logfile

If true, produces a detailed logfile named filename + ‘.log’ when writing the file

verbose

Boolean indicating whether to print infomation

progress_bar

Boolean indicating whether to show the progress bar.

CompositeAudioClip

class moviepy.audio.AudioClip.CompositeAudioClip(clips)[source]

Bases: moviepy.audio.AudioClip.AudioClip

Clip made by composing several AudioClips.

An audio clip made by putting together several audio clips.

Parameters:

clips

List of audio clips, which may start playing at different times or together. If all have their duration attribute set, the duration of the composite clip is computed automatically.

copy()

Shallow copy of the clip.

Returns a shwallow copy of the clip whose mask and audio will be shallow copies of the clip’s mask and audio if they exist.

This method is intensively used to produce new clips every time there is an outplace transformation of the clip (clip.resize, clip.subclip, etc.)

cutout(ta, tb)

Returns a clip playing the content of the current clip but skips the extract between ta and tb, which can be expressed in seconds (15.35), in (min, sec), in (hour, min, sec), or as a string: ‘01:03:05.35’. If the original clip has a duration attribute set, the duration of the returned clip is automatically computed as `` duration - (tb - ta)``.

The resulting clip’s audio and mask will also be cutout if they exist.

fl(fun, apply_to=[], keep_duration=True)

General processing of a clip.

Returns a new Clip whose frames are a transformation (through function fun) of the frames of the current clip.

Parameters:

fun

A function with signature (gf,t -> frame) where gf will represent the current clip’s get_frame method, i.e. gf is a function (t->image). Parameter t is a time in seconds, frame is a picture (=Numpy array) which will be returned by the transformed clip (see examples below).

apply_to

Can be either 'mask', or 'audio', or ['mask','audio']. Specifies if the filter fl should also be applied to the audio or the mask of the clip, if any.

keep_duration

Set to True if the transformation does not change the duration of the clip.

Examples

In the following newclip a 100 pixels-high clip whose video content scrolls from the top to the bottom of the frames of clip.

>>> fl = lambda gf,t : gf(t)[int(t):int(t)+50, :]
>>> newclip = clip.fl(fl, apply_to='mask')
fl_time(t_func, apply_to=[], keep_duration=False)

Returns a Clip instance playing the content of the current clip but with a modified timeline, time t being replaced by another time t_func(t).

Parameters:

t_func:

A function t-> new_t

apply_to:

Can be either ‘mask’, or ‘audio’, or [‘mask’,’audio’]. Specifies if the filter fl should also be applied to the audio or the mask of the clip, if any.

keep_duration:

False (default) if the transformation modifies the duration of the clip.

Examples

>>> # plays the clip (and its mask and sound) twice faster
>>> newclip = clip.fl_time(lambda: 2*t, apply_to=['mask','audio'])
>>>
>>> # plays the clip starting at t=3, and backwards:
>>> newclip = clip.fl_time(lambda: 3-t)
fx(func, *args, **kwargs)

Returns the result of func(self, *args, **kwargs). for instance

>>> newclip = clip.fx(resize, 0.2, method='bilinear')

is equivalent to

>>> newclip = resize(clip, 0.2, method='bilinear')

The motivation of fx is to keep the name of the effect near its parameters, when the effects are chained:

>>> from moviepy.video.fx import volumex, resize, mirrorx
>>> clip.fx( volumex, 0.5).fx( resize, 0.3).fx( mirrorx )
>>> # Is equivalent, but clearer than
>>> resize( volumex( mirrorx( clip ), 0.5), 0.3)
get_frame(t)

Gets a numpy array representing the RGB picture of the clip at time t or (mono or stereo) value for a sound clip

is_playing(t)

If t is a time, returns true if t is between the start and the end of the clip. t can be expressed in seconds (15.35), in (min, sec), in (hour, min, sec), or as a string: ‘01:03:05.35’. If t is a numpy array, returns False if none of the t is in theclip, else returns a vector [b_1, b_2, b_3...] where b_i is true iff tti is in the clip.

iter_chunks(chunksize=None, chunk_duration=None, fps=None, quantize=False, nbytes=2, progress_bar=False)

Iterator that returns the whole sound array of the clip by chunks

iter_frames(fps=None, with_times=False, progress_bar=False, dtype=None)

Iterates over all the frames of the clip.

Returns each frame of the clip as a HxWxN np.array, where N=1 for mask clips and N=3 for RGB clips.

This function is not really meant for video editing. It provides an easy way to do frame-by-frame treatment of a video, for fields like science, computer vision...

The fps (frames per second) parameter is optional if the clip already has a fps attribute.

Use dtype=”uint8” when using the pictures to write video, images...

Examples

>>> # prints the maximum of red that is contained
>>> # on the first line of each frame of the clip.
>>> from moviepy.editor import VideoFileClip
>>> myclip = VideoFileClip('myvideo.mp4')
>>> print ( [frame[0,:,0].max()
             for frame in myclip.iter_frames()])
set_duration(t, change_end=True)

Returns a copy of the clip, with the duration attribute set to t, which can be expressed in seconds (15.35), in (min, sec), in (hour, min, sec), or as a string: ‘01:03:05.35’. Also sets the duration of the mask and audio, if any, of the returned clip. If change_end is False, the start attribute of the clip will be modified in function of the duration and the preset end of the clip.

set_end(t)

Returns a copy of the clip, with the end attribute set to t, which can be expressed in seconds (15.35), in (min, sec), in (hour, min, sec), or as a string: ‘01:03:05.35’. Also sets the duration of the mask and audio, if any, of the returned clip.

set_fps(fps)

Returns a copy of the clip with a new default fps for functions like write_videofile, iterframe, etc.

set_ismask(ismask)

Says wheter the clip is a mask or not (ismask is a boolean)

set_make_frame(make_frame)

Sets a make_frame attribute for the clip. Useful for setting arbitrary/complicated videoclips.

set_memoize(memoize)

Sets wheter the clip should keep the last frame read in memory

set_start(t, change_end=True)

Returns a copy of the clip, with the start attribute set to t, which can be expressed in seconds (15.35), in (min, sec), in (hour, min, sec), or as a string: ‘01:03:05.35’.

If change_end=True and the clip has a duration attribute, the end atrribute of the clip will be updated to start+duration.

If change_end=False and the clip has a end attribute, the duration attribute of the clip will be updated to end-start

These changes are also applied to the audio and mask clips of the current clip, if they exist.

subclip(t_start=0, t_end=None)

Returns a clip playing the content of the current clip between times t_start and t_end, which can be expressed in seconds (15.35), in (min, sec), in (hour, min, sec), or as a string: ‘01:03:05.35’. If t_end is not provided, it is assumed to be the duration of the clip (potentially infinite). If t_end is a negative value, it is reset to ``clip.duration + t_end. ``. For instance:

>>> # cut the last two seconds of the clip:
>>> newclip = clip.subclip(0,-2)

If t_end is provided or if the clip has a duration attribute, the duration of the returned clip is set automatically.

The mask and audio of the resulting subclip will be subclips of mask and audio the original clip, if they exist.

to_audiofile(*a, **kw)

The function to_audiofile is deprecated and is kept temporarily for backwards compatibility. Please use the new name, write_audiofile, instead.

to_soundarray(tt=None, fps=None, quantize=False, nbytes=2, buffersize=50000)

Transforms the sound into an array that can be played by pygame or written in a wav file. See AudioClip.preview.

Parameters:

fps

Frame rate of the sound for the conversion. 44100 for top quality.

nbytes

Number of bytes to encode the sound: 1 for 8bit sound, 2 for 16bit, 4 for 32bit sound.

write_audiofile(filename, fps=44100, nbytes=2, buffersize=2000, codec=None, bitrate=None, ffmpeg_params=None, write_logfile=False, verbose=True, progress_bar=True)

Writes an audio file from the AudioClip.

Parameters:

filename

Name of the output file

fps

Frames per second

nbyte

Sample width (set to 2 for 16-bit sound, 4 for 32-bit sound)

codec

Which audio codec should be used. If None provided, the codec is determined based on the extension of the filename. Choose ‘pcm_s16le’ for 16-bit wav and ‘pcm_s32le’ for 32-bit wav.

bitrate

Audio bitrate, given as a string like ‘50k’, ‘500k’, ‘3000k’. Will determine the size and quality of the output file. Note that it mainly an indicative goal, the bitrate won’t necessarily be the this in the output file.

ffmpeg_params

Any additional parameters you would like to pass, as a list of terms, like [‘-option1’, ‘value1’, ‘-option2’, ‘value2’]

write_logfile

If true, produces a detailed logfile named filename + ‘.log’ when writing the file

verbose

Boolean indicating whether to print infomation

progress_bar

Boolean indicating whether to show the progress bar.