Spaces:
Runtime error
Runtime error
Commit
·
871bdbb
1
Parent(s):
6932abb
add extract audio
Browse files- README.md +18 -0
- ai_video_cli/main.py +33 -0
README.md
CHANGED
@@ -159,3 +159,21 @@ ai-segment input_video.mp4 segmented_output.mp4
|
|
159 |
This command will process `input_video.mp4` using YOLO for person detection and SAM2 for segmentation. It will create a new video `segmented_output.mp4` where all detected people are segmented, and the background is replaced with green.
|
160 |
|
161 |
Note: This command requires additional AI models (YOLO and SAM2) which will be downloaded automatically on first use. The process may take some time depending on the length of the video and your hardware capabilities.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
This command will process `input_video.mp4` using YOLO for person detection and SAM2 for segmentation. It will create a new video `segmented_output.mp4` where all detected people are segmented, and the background is replaced with green.
|
160 |
|
161 |
Note: This command requires additional AI models (YOLO and SAM2) which will be downloaded automatically on first use. The process may take some time depending on the length of the video and your hardware capabilities.
|
162 |
+
|
163 |
+
### 7. Extract Audio
|
164 |
+
|
165 |
+
Extracts the audio from a video file.
|
166 |
+
|
167 |
+
```
|
168 |
+
ai-video extract_audio <input_file> [output_file]
|
169 |
+
```
|
170 |
+
|
171 |
+
- `<input_file>`: Path to the input video file
|
172 |
+
- `[output_file]`: Optional path for the output audio file (default: <input_file>_audio.mp3)
|
173 |
+
|
174 |
+
Example:
|
175 |
+
```
|
176 |
+
ai-video extract_audio my_video.mp4
|
177 |
+
```
|
178 |
+
|
179 |
+
This command will extract the audio from `my_video.mp4` and save it as `my_video_audio.mp3`. If you don't specify an output file, the tool will automatically generate one with the suffix "_audio.mp3" added to the input filename.
|
ai_video_cli/main.py
CHANGED
@@ -160,6 +160,26 @@ def convert_video(
|
|
160 |
print(f"Error: {e}")
|
161 |
|
162 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
def main():
|
164 |
parser = argparse.ArgumentParser(description="AI Video Editor CLI Tool")
|
165 |
subparsers = parser.add_subparsers(dest="command", help="Commands")
|
@@ -249,6 +269,17 @@ def main():
|
|
249 |
help="Height to crop the video (default: 768)",
|
250 |
)
|
251 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
252 |
args = parser.parse_args()
|
253 |
|
254 |
if args.command == "split":
|
@@ -268,6 +299,8 @@ def main():
|
|
268 |
args.crop_width,
|
269 |
args.crop_height,
|
270 |
)
|
|
|
|
|
271 |
else:
|
272 |
parser.print_help()
|
273 |
|
|
|
160 |
print(f"Error: {e}")
|
161 |
|
162 |
|
163 |
+
def extract_audio(input_file, output_file=None):
|
164 |
+
try:
|
165 |
+
if output_file is None:
|
166 |
+
base_filename, _ = os.path.splitext(input_file)
|
167 |
+
output_file = f"{base_filename}_audio.mp3"
|
168 |
+
|
169 |
+
video = VideoFileClip(input_file)
|
170 |
+
audio = video.audio
|
171 |
+
|
172 |
+
# Extract audio
|
173 |
+
audio.write_audiofile(output_file)
|
174 |
+
|
175 |
+
video.close()
|
176 |
+
audio.close()
|
177 |
+
|
178 |
+
print(f"Audio extracted and saved as: {output_file}")
|
179 |
+
except Exception as e:
|
180 |
+
print(f"Error: {e}")
|
181 |
+
|
182 |
+
|
183 |
def main():
|
184 |
parser = argparse.ArgumentParser(description="AI Video Editor CLI Tool")
|
185 |
subparsers = parser.add_subparsers(dest="command", help="Commands")
|
|
|
269 |
help="Height to crop the video (default: 768)",
|
270 |
)
|
271 |
|
272 |
+
# Extract audio command
|
273 |
+
extract_audio_parser = subparsers.add_parser(
|
274 |
+
"extract_audio", help="Extract audio from a video file"
|
275 |
+
)
|
276 |
+
extract_audio_parser.add_argument("input_file", help="Input video file")
|
277 |
+
extract_audio_parser.add_argument(
|
278 |
+
"output_file",
|
279 |
+
nargs="?",
|
280 |
+
help="Output audio file (optional, default: <input_file>_audio.mp3)",
|
281 |
+
)
|
282 |
+
|
283 |
args = parser.parse_args()
|
284 |
|
285 |
if args.command == "split":
|
|
|
299 |
args.crop_width,
|
300 |
args.crop_height,
|
301 |
)
|
302 |
+
elif args.command == "extract_audio":
|
303 |
+
extract_audio(args.input_file, args.output_file)
|
304 |
else:
|
305 |
parser.print_help()
|
306 |
|