Extract and trim audio from videos or trim audios.
Project description
Audio Extract
audio-extract is a Python library that allows you to extract audio from video files and trim the audio according to your needs
Description
audio-extract is a Python library that allows you to extract audio from video files and trim the audio according to your needs. You can use it to create audio clips from movies, podcasts, or any other video source. It supports various audio and video formats, such as MP3, WAV, OGG, MP4, AVI, and MKV.
Installing
- Install from Pypi:
pip install audio-extract
- Install from GitHub:
pip install git+https://github.com/riad-azz/audio-extract.git
Getting Started
AudioExtract - Info
The application is pretty straightforward all you need is to import the extract_audio function. The function args:
-
input_path: The path to the input (Video/Audio) file. -
output_path: The path to the extracted audio file. The default value is./audio.mp3. -
output_format: The format of the extracted audio. The default value ismp3. -
start_time: The start time of the output inHH:MM:SSorMM:SSformat. The default value is00:00:00. -
duration: The duration of the extracted audio in seconds (float). The default value isNonewhich means full audio will be extracted ifstart_timeis set to00:00:00. -
overwrite: Whether to overwrite the output file if it already exists or not. The default value isFalse.
The supported file formats:
-
Supported audio formats :
WAV, OGG, MP3, AAC, FLAC, M4A, OGA, OPUS -
Supported video formats :
MP4, MKV, WEBM, FLV, AVI, MOV, WMV, M4V
Executing the program
Extract full audio:
from audio_extract import extract_audio
extract_audio(input_path="./video.mp4", output_path="./audio.mp3")
This will create a mp3 file called audio.mp3 that contains the full audio of the video file video.mp4.
Extract sub clip audio:
from audio_extract import extract_audio
extract_audio(input_path="./video.mp4",
output_path="./audio.mp3",
start_time="00:30",
overwrite=True)
This will create a mp3 file called audio.mp3 that starts after the first 30 seconds of the video file video.mp4
and will overwrite audio.mp3 file if it already exists.
Extract sub clip audio with custom duration
from audio_extract import extract_audio
extract_audio(input_path="./video.mp4",
output_path="./audio.mp3",
start_time="00:25",
duration=15.0)
This will convert video file video.mp4 to a mp3 file starting from 00:25 to 00:40
called audio.mp3 that will have a duration of 00:15.
Trim audio:
from audio_extract import extract_audio
extract_audio(input_path="./audio.mp3",
output_path="./new_audio.mp3",
start_time="00:05",
duration=20.0)
This will trim the audio.mp3 file starting from 00:05 to 00:25 to a mp3 file called new_audio.mp3 that will
have a duration of 00:20.
Running Command-Line-Interface
CLI Arguments
The following cli arguments are supported:
-
--inputor-i: The path to the input (Video/Audio) file. -
--outputor-o: The path to the extracted audio file. The default value is./audio.mp3. -
--formator-f: The format of the extracted audio. The default value ismp3. -
--start-timeor-st: The start time of the output inHH:MM:SSorMM:SSformat. The default value is00:00:00. -
--durationor-d: The duration of the extracted audio in seconds (float), The default value isNonewhich means full audio will be extracted ifstart_timeis set to00:00:00. -
--overwriteor-ow: Whether to overwrite the output file if it already exists or not. The default value isFalse.
CLI Usage Example:
Here is an example of using the CLI to extract audio:
audio-extract --input="./video.mp4" --output="./audios/extracted_audio.wav" --format="wav"
This command will extract the full audio starting from video.mp4 to a wav file called extracted_audio.wav and will
be saved to the folder ./audios/. The folder will be automatically created if it doesn't exist.
Authors
Riadh Azzoun - @riad-azz
License
This project is licensed under the [MIT] License - see the LICENSE.md file for details
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file audio_extract-0.7.0.tar.gz.
File metadata
- Download URL: audio_extract-0.7.0.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf8d5f48146e2d4d15778a26cede57b303f465f299621539118448bc22100dbb
|
|
| MD5 |
8a6049a037e3bcdf196f6c9ca36d2fe9
|
|
| BLAKE2b-256 |
767be2d7b3bb9005efe3c1307f512c0f37572c067187c6690080b1ae9b2c9ac5
|
File details
Details for the file audio_extract-0.7.0-py3-none-any.whl.
File metadata
- Download URL: audio_extract-0.7.0-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44495569a86e46a94d1606214d39abebc30db59ed207b8b900787c2e844a887d
|
|
| MD5 |
74a488824466c7e45945c703dba8ecad
|
|
| BLAKE2b-256 |
b2855433110bf0eb71151782694098b818b4f0b26fd2992623881694fd8a6a09
|