alexlaverty / python-reddit-youtube-bot

Automated Reddit Youtube Video Bot
https://www.youtube.com/channel/UCzIwW92D_rM5_yvWBsquSbw
89 stars 20 forks source link

How can I add background music to a video? #94

Open alexdo83 opened 1 year ago

alexdo83 commented 1 year ago

How can I add background music to a video?

sebbourgeois commented 1 year ago

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

alexlaverty commented 1 year ago

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"
sebbourgeois commented 1 year ago

@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'
alexlaverty commented 1 year ago

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

sebbourgeois commented 1 year ago

@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.