lagmoellertim / unsilence

Console Interface and Library to remove silent parts of a media file 🔈
https://unsilence.readthedocs.io/
MIT License
551 stars 44 forks source link

Video renders silent #44

Closed Marstead closed 3 years ago

Marstead commented 3 years ago

Describe the bug I have a specific 7-hour 15-minute video which analyzes and renders successfully, but after rendering the completed video is completely silent. It fast forwards at the appropriate points where the original video is audible and silent, but there is no sound. When loaded into video editing software like Vegas Pro the rendered *.mp4 does not seem to include an audio track.

The original video does have audio which plays appropriately both in its native .flv format and after remuxing to .mp4 in the same players in which I am testing the rendered video.

I've tried using Unsilence on the original .flv & remuxed .mp4, and I've tried adjusting the parameters, but the rendered video always has no audio.

To Reproduce This appears to only impact one video of mine; I can share the source and final files but as the source file is 7 hours long and 19GB I wanted to see if this was a known issue with larger files. If this isn't a known issue I can try to load the source and rendered files and provide more detail.

Parameters I'm using:

-as 1 -ss 64 -t 11 -stt 1 -sl -30

I have a different 7-hour 10-minute VOD that I was able to render successfully using multiple parameters, so I am not sure what is causing this video to lose audio in the rendering process.

Marstead commented 3 years ago

Update: In lieu of attaching the full files, in case this helps to troubleshoot, here is a copy of the media info for both the input and output files. I've now tried rendering this 4 times and get a rendered file with no audio every time. Inputfile.mp4.txt outputfile.mp4.txt

I also tried using ffmpeg to split the video into a 3-hour video and a 3.5-hour video, to try to test if this was a length issue. The 3-hour split video has the proper audio, but after rendering it using the same settings through unsilence, the audio is lost. I could keep trying this on the same file until I can get it small enough to upload here as a sample -- I may work on this tomorrow.

lagmoellertim commented 3 years ago

Hey, could you try extracting a small segment (e.g. 30 seconds) from the video and try if it works with ffmpeg. If it does not work, you could send me the segment.

Please try creating a segment using both of these commands: ffmpeg -ss <starttime_in_seconds> -to <endtime_in_seconds> -i <input_file> <output_file> ffmpeg -i <input_file> -ss <starttime_in_seconds> -to <endtime_in_seconds> <output_file>

Since ffmpeg doesn't reencode using these scripts, the problem should still exist in these smaller videos

Marstead commented 3 years ago

Thanks for your help again -- extracting a 30-second video on the impacted file fixes the issue -- if I run unsilence on the 30-second extracted version of the video, the audio is properly preserved. I've been having this problem on multiple videos now, although it seems to more likely impact longer videos. Fast forward works, but the audio track is lost in the rendering process. I have a smaller impacted video (~3 hours) that I could try to share to test, though it is still 8GB.

My only guess is this might be related to stretch-time or the default stretch time? On my videos I can't really fuss with the stretch-time setting as I will get a "Stretch time too high" error if I go above the default. Maybe on very long videos it's possible for the default stretch time of 0.25 to be too high, but no error is thrown during analysis when no argument is specified?

lagmoellertim commented 3 years ago

Hey, this is the code for stretch time error:

        if stretch_time >= self.duration: # The duration of the silent interval before the audible interval
            raise Exception("Stretch time to large, please choose smaller size")

This should not be the cause of the issue, since it only checks if the previous silent interval is big enough to include two audible buffers (the stretch time). This should be the same for short/long videos as it only interacts with single intervals, not the whole video file.

I actually have no idea why this happens, if you could share the 8GB file (maybe on Google Drive), I would investigate that further.

Marstead commented 3 years ago

Thanks! Let me work on getting it uploaded and I'll post a drive link shortly. I am currently testing the boundaries for when the video becomes too long, starting by chopping the 3h video into a 1h 30m video. If the issue is still present on the rendered 90min video I will upload that for you to take a look.

lagmoellertim commented 3 years ago

Maybe you could add the parameters described here: https://stackoverflow.com/a/38381173/10666894

I don't fully know that my command doesn't re-encode the video, so maybe give this a try

Marstead commented 3 years ago

Here is a zip of the files.

https://drive.google.com/file/d/18VLma28vdOiMHf2_PI-WR1995ZBEuD8K/view?usp=sharing

This is my recording of a grindy video game, I talk when interesting things are happening and mute when doing repetitive tasks, the idea is for the repetitive tasks to get fastforwarded.

trails4-1split1.mp4 is the ffmpeg-split first 90 minutes of the full VOD. trails4-1rendersplit1 is the rendered video from unsilence using the following parameters:

unsilence trails4-1split1.mp4 trails4-1rendersplit1.mp4 -ss 64 -t 2 -stt 1 -sl -30 -y -st 0.30

You'll notice the rendered video is still correctly fast forwarded around points where I mute in the original video, but the audio track is gone. Let me know if there's anything else I can do to test, I have several videos impacted by the issue. Thanks!

lagmoellertim commented 3 years ago

I've figured out what the problem is: If an interval is very short, ffmpeg does not create an audio track. When the first interval is silent, the settings from this short and silent interval are applied to all other intervals, so there is no audio track at all. I'm going to fix this problem now

Marstead commented 3 years ago

Awesome thank you! Maybe as a stopgap I can just start yelling when I start recording to make sure the first interval doesn't register as silent 😂 Thanks so much for this tool, and for your help troubleshooting it. I have thousands of video to edit and it will save me hundreds of hours.

lagmoellertim commented 3 years ago

It would be great if you could test this PR with your remaining video files. If it works, I'm going to merge it in.

On an unrelated note, thank you very much for your donation! It really means the world to me, I'm a student and develop this tool when I have free time from studying, and that this tool is actively used by other people is awesome!

Marstead commented 3 years ago

Sounds good, I have a handful of impacted files and am recording new content daily that I can run through it to help troubleshoot. I'll start by using it on my existing files; I hope to have some feedback over the weekend.

This tool is incredible, I will be sharing it with other content creators! Thank you again for putting out here.

Marstead commented 3 years ago

I've tested this with my old videos as well as a new 10-hour video and it looks like it worked! I'll keep testing over this week and let you know if any additional issues pop up. Thanks so much for your help.

lagmoellertim commented 3 years ago

Alright, I'm going to merge it in then. Thanks for your support!