DarkTrick / python-video-silence-cutter

Python script, that uses ffmpeg and ffprobe to cut silences away from videos
Creative Commons Zero v1.0 Universal
43 stars 16 forks source link

Pad cutoff time by 0.025s #4

Open Incognito opened 2 years ago

Incognito commented 2 years ago

Great script, thanks for publishing this. I had a small issue where the cutoff times were a bit too accurate leading to the audio sounding like it was a "skipping cd track", so I just made a small tweak:

  for line in lines:
    if ("silencedetect" in line):
        words = line.split(" ")
        for i in range (len(words)):
            if ("silence_start" in words[i]):
              time_list.append (float(words[i+1]) + 0.025)  # changed here
            if "silence_end" in words[i]:
              time_list.append (float (words[i+1]) - 0.025)   # changed here
  silence_section_list = list (zip(*[iter(time_list)]*2))

It lead to an overall smoother listening experience. I think it could become a proper feature with an argument if you find this kind of feature interesting.

In my code I do not handle an edge case where the silence cut is less than 0.05s.

I'm using this to cut silence out while reading from a teleprompter (taking a break to breathe, drink water, etc).

DarkTrick commented 2 years ago

Thank you very much for looking into this!

What I understand If I understand your intention correctly, you needed a minimum amount of length to not be cut away between two different points - in your specific case: 0.05s.

Good idea, unusable code I really like the idea, but I can't use the code you posted because - as you already figured I do not handle an edge case where the silence cut is less than 0.05s..

Could you generalize the code?

  1. Could you generalize the code, so
    1.1 your 0.05s become a parameter 1.2 the edge case is covered
  2. Can you provide a sample file for testing? (can be a simple artificial noise file created in audacity)

Background: I would love to do it myself, but I won't find the time in the near future. I could, however, review a pull request with a test file.

Incognito commented 2 years ago

If I understand your intention correctly, you needed a minimum amount of length to not be cut away between two different points - in your specific case: 0.05s.

Basically the situation is that if speaking begins at 1s the track will cut 0s-1s, but those few milliseconds before the cut are needed to have a pleasant listening experience.

Good idea, unusable code

This is clear, I just wanted to know if you saw this as a useful change or not. Not all projects accept changes or it might be decided as "not something we want".

Incognito commented 2 years ago

I am playing a bit with some editing techniques, if I use this more frequently I will submit a MR.

DarkTrick commented 2 years ago

Not all projects accept changes or it might be decided as "not something we want". Indeed. Very familiar with that, too. Your idea is very welcome here!

I am playing a bit with some editing techniques, if I use this more frequently I will submit a MR. I'm looking forward to receiving a MR! :+1: