Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENHANCEMENT] Add music to generated videos #3547

Open
flewid opened this issue Apr 2, 2024 · 4 comments
Open

[ENHANCEMENT] Add music to generated videos #3547

flewid opened this issue Apr 2, 2024 · 4 comments
Assignees

Comments

@flewid
Copy link

flewid commented Apr 2, 2024

I thought it'd be cool to have music over the generated videos to make them a bit more fun to watch, so I played around with this and came up with the following method.

I'm sure this isn't right, so I did not create a PR or anything, I think we'd in reality want something like this;

  • Config Option to 'enable music' or not (true/false)
  • Config Option to 'set the mp3 file name'
  • Addition of ${ALLSKY_HOME_MUSIC} variable to the timelapse script to the direct path
  • Video length option (for the -t option)
  • Possibly an option for 'fade in' and 'out' duration?

Anyway, here's what's working for me;

First, copy your mp3 to your allsky box as 'music.mp3' then, ssh to your allsky box and do the following

cd ~/allsky
mkdir music 
mv ~/music.mp3 ~/allsky/music/

then edit the timelapse script

nano ~/allsky/scripts/timelapse.sh

at line 249, which looks like
-i "${SEQUENCE_DIR}/%04d.${EXTENSION}" \

add this following it on the next line
-i "${ALLSKY_HOME}/music/music.mp3" -af "afade=in:st=0:d=5,afade=out:st=57:d=5" -t 63 \

now just wait until the next morning and check out your video, with sound!

What this does is;

  • My timelapse video files are all 1:02 (62 seconds) @ 15fps
  • Fades the audio in over 5 seconds to full volume at the beginning
  • Then at 57 seconds, it fades the audio down for 5 seconds to 0
  • The "-t" tells it to cut the video at 63 seconds, so it doesn't keep playing the length of your mp3 file.
@EricClaeys EricClaeys added this to the post v2024.xx.xx milestone Apr 4, 2024
@EricClaeys EricClaeys self-assigned this Apr 4, 2024
@EricClaeys
Copy link
Collaborator

@flewid, you should be able to add that line to the KEOGRAM_EXTRA_PARAMETERS setting so you don't have to change the timelapse.sh file.

If I understand this correctly, the user needs to provide 3 pieces of info:

  1. Name of music file.
  2. Length of fade in time in seconds or 0 to have no fade in. This number must be less than the length of the video and ideally less than half the video length.
  3. Length of fade out. Same comments as above.

The 57 and 63 in your example could be automatically determined based on the length of the video. Do you know what happens if the audio is shorter than the video? Does it loop?

We probably won't add this to the WebUI but could add it to the documentation, possibly as a FAQ item, and include the code to determine the video length.

Do you know how to add audio AFTER the video is created? If that's possible then a module could be written to do that. We are eventually going to turn all the post capture work (e.g., stretching, cropping, timelapse, keogram, etc into modules.

@flewid
Copy link
Author

flewid commented Apr 12, 2024

@EricClaeys Thanks for checking it out!

I do not think adding to the keogram would work? I experimented a bunch and it seems the 'order matters' in terms of the ffmpeg command. The command must be BEFORE the video generation stuff on that line in timelapse.sh. But I could be wrong?

For your questions

  1. yes this sounds right, however, I now have thought about this some more, and it might be cool to pick from a 'pool' of mp3's so each video gets a random song attached to it, if the directory only has one mp3, they all get the same, if it has 5 then it randomly chooses one to use.

  2. yes, this sounds right to me. I think most people would want music the whole way through, but, you're right, some people might want to start it 'at night time only' or even have different music for day and night (but now i'm just getting crazy).

  3. correct

  4. if the audio is shorter than the video, there is a looping parameter for ffmpeg, but the way this is setup it will just stop. I have not tried the looping as the MP3's i'm using are minutes long.

Makes sense about a FAQ entry for sure!

Yes, you can add audio AFTER the video's been created, however, this would be processing twice so I figured this was kind of redundant, and also causes more strain on the box but I see where you're going with the module inclusion for sure.

I'm not much of a programmer, but I can help with whatever's needed on this for testing etc.

Thanks!

@EricClaeys
Copy link
Collaborator

@flewid, you are probably right that the music parameters need to go earlier on the command line than ${TIMELAPSE_EXTRA_PARAMETERS} which is at the end.

Thinking out loud...
If there was a new setting for Music Parameters Script that pointed to a user-supplied script that output the parameters, that script could be run prior to ffmpeg, and its output put on the ffmpeg command line in the correct place. Some information would be passed to the script such as the length of the video in seconds and whether or not it was a mini or daily timelapse.
The script could output the same parameters every time, or use different music files everytime, or anything the user wanted.

Do you think that would work?

@flewid
Copy link
Author

flewid commented Apr 14, 2024

Yep, I tried various spots in the command and definitely has to be either the first command, or the second position where I have it.

I like that idea for a checkbox + form field for 'user script' for this - that could be used for many other things as well too eh?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants