antiboredom / videogrep

automatic video supercuts with python
https://antiboredom.github.io/videogrep
Other
3.33k stars 257 forks source link

Add fade option for audio (--fade, -f) #130

Open Dean-Corso opened 9 months ago

Dean-Corso commented 9 months ago

Hello @antiboredom.

just have another new question about the audio cut results in the video segments itself which you combine at the end to one file. So I did notice that some cuts videogrep is doing are not so good & clean in case of the audio track and then you can hear annoying crackle / crack when the new A/V segment starts to play. That's a bad issue I would like to fix. The only way how to fix it is by adding a fade-in fade-out at the start and end of the audio segment with an very little duration of 0.100 seconds or less. Just did test it in a tool where I could only enter 0.100 secs as minimum value but more less time should also work. Problem is I found not way to fix this in post operation with any tool (only manually but this is super bad and a waste of time doing it by hand). So I made a image to show you what I mean... Crackle_2023-11-15_225325 ...so in the image above you can see it. Left side is the pre-audio segment and on the right the next added audio segment and this one starts with an hear able crack / crackle sound etc. So to prevent those possible crackle sounds at the start and end of each audio segment you could add an audio Fade-In & Fade-Out automatically in Videogrep (maybe optimal with a new command line parameter --fade 0.1 / --fade 0.2 etc) each segment when you create it. So in case of using a super low duration time of 0.1 sec or less it does not really affect the hear able audio itself for us because its super low but the advantage is that you get a rid of those possible emerging crackle sounds at the start and end. What do you think? Would that be possible for videogrep to handle anyhow? Otherwise do you have some alternative ideas how to handle that problem? Maybe to keep all single A/V fragments in folder and doing some auto handling to add a fade-in fade-out on every single one (anyhow, maybe with ffmpeg too) and combine / concat them together etc. Thanks.

antiboredom commented 9 months ago

Hi - agreed that we should have an audio (and possibly video) fade as an option in the command line parameters. I'll look into a way of doing this but also if anyone else has time/energy to implement please do let me know.

Dean-Corso commented 9 months ago

Hi @antiboredom,

so I was tying to check out how this could be done using ffmpeg to fade in & out the sound with an specific mini duration time. Normally you could use the "afade" command for fade in & out but the problem is the fade out operation where you need to set the time in seconds where to start the fade out what is bad. After short search I found a trick without to set an time for fade out so that it works automatically by just adding the "areverse" ffmpeg command in the middle of fade in & out what looks like this. Audio_Fade_2023-11-16_185014 -filter_complex "afade=d=0.01, areverse, afade=d=0.03, areverse" -c:v copy

In this example command I just set the fade in duration time of 0.01 seconds then doing a audio reverse then again a fade of 0.03 secs and another reverse of the audio and at the end just a simple copy command for the video stream. In that case it works to set your fade in / out using ffmpeg. Something like that you could do in Videogrep when the user is setting the new --fade parameter when you add this later.

For the moment I could just keep all A/V exported fragments from Videogrep and find a way / batch script to handle all output files doing the fade in / out with ffmpeg + combine them at the end. Not sure how the script could look like that the moment and using it in the meantime so long you do update Videogrep with that feature. Do you know how a simple script could look like just to read all files in same folder | doing the ffmpeg operation | save as new file | combine all at the end. Just asking because otherwise I have to search again to find any possible method. Thanks.