![ffmpeg create silent audio file ffmpeg create silent audio file](https://user-images.githubusercontent.com/14976613/131338716-d90017d5-e2b7-4be7-a323-a8a61d88c94b.png)
Tada! You got a new version of the video with the silent parts removed! Last we write the remainder of the video to the last clip, use the concatenate_vidoeclips function from moviepy to pass in a list of clips and combine them into one video clip, and call the write_videofile method of VideoClip class to save the final output to the out path I passed into the script. Repeat until all sections of silence are exhausted Store the end of the next section of silence in a variable
![ffmpeg create silent audio file ffmpeg create silent audio file](https://i.ytimg.com/an/Opco-pSbF5g/19b83507-6319-4f85-a386-5756d2eec154_mq.jpg)
Write out a clip from the end of the last section of silence, until the start of the next section of silence, and store it in a list
![ffmpeg create silent audio file ffmpeg create silent audio file](https://cdn.ourcodeworld.com/public-media/articles/articleocw-5a81a729739ad.png)
The logic for writing out clips works like so: I track when the next clip to be written out should start in the last variable, to track when the last section of silence ended. There are a few sanity checks using that to determine if a clip should be extracted yet or not. You will see there is a minimum_duration, that is because I found in testing that moviepy will crash when trying to write out a clip that is less than a second. So I want to add about half a second of padding to when the next clip is suppose to start to make it less abrupt.
![ffmpeg create silent audio file ffmpeg create silent audio file](https://www.get-itsolutions.com/wp-content/uploads/2017/10/full-768x241.jpg)
I noticed the jumps between the clips is kinda sudden and too abrupt.
#Ffmpeg create silent audio file movie
Silence_file – the file path to the file generated by the silence detectionĮase_in – a work in progress concept. If you have a separate subtitle file called subtitle.srt, you can use following command to add subtitle to a movie file: ffmpeg -i video.mp4 -i subtitles.srt -map 0 -map 1 -c copy -c:v libx264 -crf 23 -preset veryfast video-output. Here I pass in 3 required and 1 optional argument:įile_in – the input file to work on, should be the same as the one passed into the silence detection scriptįile_out – the file path to save the final version to Processed_video = concatenate_videoclips(clips) Here is the script for generating the silence timestamp data: #!/usr/bin/env shįfmpeg -hide_banner -vn -i $IN -af "silencedetect=n=$)".format(count, last, 'EOF'))Ĭlips.append(video.subclip(float(last)-ease)) Now, with the process laid out, lets look at the scripts doing the heavy lifting.