moviepy.audio.io.readers.FFMPEG_AudioReader#
- class moviepy.audio.io.readers.FFMPEG_AudioReader(filename, buffersize, decode_file=False, print_infos=False, fps=44100, nbytes=2, nchannels=2)[source]#
A class to read the audio in either video files or audio files using ffmpeg. ffmpeg will read any audio and transform them into raw data.
- Parameters:
filename -- Name of any video or audio file, like
video.mp4orsound.wavetc.buffersize -- The size of the buffer to use. Should be bigger than the buffer used by
write_audiofileprint_infos -- Print the ffmpeg infos on the file being read (for debugging)
fps -- Desired frames per second in the decoded signal that will be received from ffmpeg
nbytes -- Desired number of bytes (1,2,4) in the signal that will be received from ffmpeg
- buffer_around(frame_number)[source]#
Fill the buffer with frames, centered on frame_number if possible.
- get_frame(tt)[source]#
Retrieve the audio frame(s) corresponding to the given timestamp(s).
- Parameters:
numpy.ndarray) (tt (float or) -- The timestamp(s) at which to retrieve the audio frame(s). If tt is a single float value, the frame corresponding to that timestamp is returned. If tt is a NumPy array of timestamps, an array of frames corresponding to each timestamp is returned.
- read_chunk(chunksize)[source]#
Read a chunk of audio data from the audio stream.
This method reads a chunk of audio data from the audio stream. The specified number of frames, given by chunksize, is read from the proc stdout. The audio data is returned as a NumPy array, where each row corresponds to a frame and each column corresponds to a channel. If there is not enough audio left to read, the remaining portion is padded with zeros, ensuring that the returned array has the desired length. The pos attribute is updated accordingly.
- Parameters:
(float) (chunksize) -- The desired number of audio frames to read.
- seek(pos)[source]#
Read a frame at time t. Note for coders: getting an arbitrary frame in the video with ffmpeg can be painfully slow if some decoding has to be done. This function tries to avoid fectching arbitrary frames whenever possible, by moving between adjacent frames.
- skip_chunk(chunksize)[source]#
Skip a chunk of audio data by reading and discarding the specified number of frames from the audio stream. The audio stream is read from the proc stdout. After skipping the chunk, the pos attribute is updated accordingly.
- Parameters:
(int) (chunksize) -- The number of audio frames to skip.