Feb-12-2025, 09:03 PM
(This post was last modified: Feb-12-2025, 09:03 PM by Leondagreatest.)
I'm making a program in python that takes an MP4 video, extracts the audio and compresses it, and then takes that compressed audio and takes 0.1 second slices and will process them when I get to coding that, but for now, I'm just making the system for getting the slices. But for some reason, the to part of this defaults to the end of the audio instead of where it's meant to go.
leon@chickenwing:~/Documents/Ambitious Project$ python3 main.py
Type path to video:
video.mp4
MoviePy - Writing audio in tempUncompressed.mp3
MoviePy - Done.
Creating video... 100.00%
Done!
leon@chickenwing:~/Documents/Ambitious Project$
ffmpeg.input("temp.mp3", ss=audioTime).output("slice.mp3", to=audioTime+0.1, acodec="copy").run(quiet=True, overwrite_output=True)Whole Script:
import moviepy.editor as mp import ffmpeg import os def main(): wordList = [] running = True percentage = 0 print("Type ath to video:") path = input() video = mp.VideoFileClip(path) duration = video.duration audioTime = 0 audio = video.audio audio.write_audiofile("tempUncompressed.mp3") probeBitrate = ffmpeg.probe("tempUncompressed.mp3", v='error', select_streams='a', show_entries='stream=bit_rate') probeSampleRate = ffmpeg.probe("tempUncompressed.mp3", v='error', select_streams='a', show_entries='stream=sample_rate') bitrate = probeBitrate["streams"][0]['bit_rate'] sampleRate = probeSampleRate["streams"][0]["sample_rate"] bitrate = int(bitrate) sampleRate = int(sampleRate) bitrate /= 1000 if bitrate < 100: print("The video's audio bitrate is too low! Aborted.") running = False if sampleRate < 32000: print("The video's audio sample rate is too low! Aborted.") running = False ffmpeg.input("tempUncompressed.mp3").output("temp.mp3", audio_bitrate="100k", ar=32000, y=None).run(quiet=True) os.remove("tempUncompressed.mp3") duration = round(duration) while running: ffmpeg.input("temp.mp3", ss=audioTime).output("slice.mp3", to=audioTime+0.1, acodec="copy").run(quiet=True, overwrite_output=True) audioTime += 1 percentage = audioTime/duration*100 print(f"\rCreating video... {percentage:.2f}% ", end="", flush=True) if audioTime >= duration: print("\nDone!") running = False main()Output:
leon@chickenwing:~/Documents/Ambitious Project$ python3 main.py
Type path to video:
video.mp4
MoviePy - Writing audio in tempUncompressed.mp3
MoviePy - Done.
Creating video... 100.00%
Done!
leon@chickenwing:~/Documents/Ambitious Project$
Gribouillis write Feb-12-2025, 06:06 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.