python-reddit-youtube-bot icon indicating copy to clipboard operation
python-reddit-youtube-bot copied to clipboard

How can I add background music to a video?

Open alexdo83 opened this issue 2 years ago • 5 comments

How can I add background music to a video?

alexdo83 avatar Nov 03 '23 12:11 alexdo83

On my end, I have a "post-treatment" script that I use on every video generated, that adds copyright free music in the background.

sebbourgeois avatar Nov 07 '23 18:11 sebbourgeois

Have pushed some updates, pull the latest code and try these out :

Enable background music that will be randomly selected from the assets/music folder :

python app.py --enable-background-music

or specify a file to use as the background music

python app.py --background-music-path "E:\Music\Colter Wall - Cowpoke.mp3"

alexlaverty avatar Nov 09 '23 11:11 alexlaverty

@alexlaverty I started today trying that new feature. First video generated, got an error :

Creating background music audio
2023-11-19 12:08:46 INFO     Randomly Selected Background Music : assets/music/Across the Savannah - Aaron Kenny.mp3
Traceback (most recent call last):
  File "/home/sb/videos-creation/python-reddit-youtube-bot/app.py", line 440, in <module>
    process_submissions(submissions)
  File "/home/sb/videos-creation/python-reddit-youtube-bot/app.py", line 64, in process_submissions
    process_submission(submission)
  File "/home/sb/videos-creation/python-reddit-youtube-bot/app.py", line 118, in process_submission
    vid.create(
  File "/home/sb/videos-creation/python-reddit-youtube-bot/video_generation/video.py", line 779, in create
    background_music_audio = background_music_audio.volumex(0).loop(-1, duration=v.duration)
AttributeError: 'AudioFileClip' object has no attribute 'loop'

sebbourgeois avatar Nov 19 '23 11:11 sebbourgeois

@sebbourgeois can you share the reddit url and the command you used to generate, will try to reproduce

alexlaverty avatar Nov 29 '23 08:11 alexlaverty

@alexlaverty python app.py --url https://www.reddit.com/r/AskReddit/comments/188rpps/what_is_the_grossest_hygiene_issue_you_overlooked/

In the settings,py :

...
enable_background_music = True
background_music_path = ""
background_music_volume = 0.1
music_directory = str(Path(assets_directory, "music"))
...

Just tried with this recent subreddit, same error :

...
2023-12-02 23:40:40 INFO     Created Audio File : assets/work_dir/188rpps/kbnzvzb.mp3
2023-12-02 23:40:40 INFO     Reached Maximum Video Length : 900
2023-12-02 23:40:40 INFO     Used 74/99 comments
2023-12-02 23:40:40 INFO     === Finished Processing Comments ===
2023-12-02 23:40:40 INFO     ===== Adding Background Clip =====
2023-12-02 23:40:40 INFO     Background : assets/backgrounds/NO COPYRIGHT MOTION GRAPHICS_ssfuvE-8dRk.mp4
Creating background music audio
2023-12-02 23:40:40 INFO     Randomly Selected Background Music : assets/music/Outlaw's Farewell (part I) - Reed Mathis.mp3
Traceback (most recent call last):
  File "/home/sb/videos-creation/python-reddit-youtube-bot/app.py", line 440, in <module>
    process_submissions(submissions)
  File "/home/sb/videos-creation/python-reddit-youtube-bot/app.py", line 64, in process_submissions
    process_submission(submission)
  File "/home/sb/videos-creation/python-reddit-youtube-bot/app.py", line 118, in process_submission
    vid.create(
  File "/home/sb/videos-creation/python-reddit-youtube-bot/video_generation/video.py", line 779, in create
    background_music_audio = background_music_audio.volumex(0).loop(-1, duration=v.duration)
AttributeError: 'AudioFileClip' object has no attribute 'loop'

For the sake of testing, I've switched enable_background_music to False in the settings,py file and did a python app.py --enable-background-music --url https://www.reddit.com/r/AskReddit/comments/188rpps/what_is_the_grossest_hygiene_issue_you_overlooked/

Same result.

sebbourgeois avatar Dec 02 '23 22:12 sebbourgeois