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

Questions about compression and formats #4

Open
rexelbartolome opened this issue Dec 5, 2021 · 22 comments
Open

Questions about compression and formats #4

rexelbartolome opened this issue Dec 5, 2021 · 22 comments
Labels
good first issue Good for newcomers

Comments

@rexelbartolome
Copy link

Hello, I'm a teacher and I really like using this tool, helps a lot with the editing. I'm just curious on how this handles compression. As from what I've seen, My 300mb OBS mkv videos will turn into 75mb with only 20% detected as silence. I'm assuming it's because of the compression and sometimes transcoding it (while keeping the same container, in this case MKV).

What's exactly being lost here? Is it mainly audio quality? both video and audio? bitrate? And is there a way for me to keep the quality the same on the exported file?

I'm not familiar with ffmpeg too so I also want to ask if you've done any benchmarks regarding the performance between file formats etc.

Is keeping the file format i.e., MKV to MKV slower or faster than using other formats?

Also one last thing, when I export this to MP4, the codecs that comes with that has some problems with Davinci Resolve (sometimes audio is lost entirely, or the audio gets a bigger delay on later parts of the video). So my workaround is to use this on the raw clips, MKV to MKV, then use Handbrake to transcode it to MP4 with more compatible codecs.

Is there a better way for me to tell Silence-Speedup to simply use specific codecs instead of the default ones so that I don't have to transcode it twice? I'm not used to using command-line interfaces but I'm willing to learn if I need to.

Again, thanks very much for this tool! 😊

@padvincenzo
Copy link
Owner

Hi @rexelbartolome,
Thank you very much for your feedback.

Actually, and unfortunately, I do not know exactly what is being lost, ffmpeg does the hard work with some sort of default settings (audio and video codecs too). And it doesn't depend on the program: I also use OBS and then ffmpeg directly to just convert videos to mp4 (because I need to upload to web and mkv is not accepted), and they loose very much of their original size (about 75%), but I do not know why.

I've just added a new branch where you can set the audio and video codecs manually. It works, but I didn't do benchmarks to check the best configuration possible. You can see the changes here. To apply these changes, you can overwrite the old assets/classes/speedup.js with the new one. From the extracted zip, you'll find this file in:

  • resources/app/ in Windows and Linux;
  • Silence SpeedUp.app/Contents/Resources/app/ in Mac OS.

Lines that you may want to edit are 55 and 68 for the audio codec (replace aac with whatever), and 56 and 69 for the video codec (replace h264 with whatever). You can see the full list of codecs at https://ffmpeg.org/ffmpeg-codecs.html (Audio/Video encoders). But unfortunately, again, I cannot be of much help for which codecs are best. I've put aac and h264 as I know them only.

If you are interested, any help with this part of the program is very appreciated. I sometimes too had videos exported with strange errors like no audio anymore or very long duration, so this feature will sure be implemented in newer versions if that solve the problem.

Thank you again for this hint and feedback, and ask freely if something isn't clear enough.

👋🏼 😃 ,
Vincenzo

@padvincenzo padvincenzo added the good first issue Good for newcomers label Dec 10, 2021
@rexelbartolome
Copy link
Author

Awesome! I think we can use aac and h264 for now, since that would the most widely used. And thanks telling me how to replace the js file, I'm not used to having custom builds and navigating through Github 😅

So I used a video of mine, removed the silence, and put the output clip in Resolve. Fortunately, both the audio and video is read correctly by Resolve but the audio and video gets out of sync as time goes on. Though playing the output clip in VLC runs it perfectly with no audio sync issues. My understanding is NLE's like Premiere Pro and Resolve really don't like variable framerate as mentioned here:

https://www.reddit.com/r/blackmagicdesign/comments/6gjzqn/help_audio_and_video_get_gradually_out_of_sync_in/

So we would need to change the framerate of the original MKV file to a constant framerate or CFR (and I'm guessing it would standard as well, since OBS usually records at a variable framerate, not constant) I found the documentation for changing the framerate here but I'm not really sure how to implement it 😅

https://trac.ffmpeg.org/wiki/ChangingFrameRate

Might be useful for this to have field input or maybe dropdown/combo box so you can select you want the video to have an FPS of 24, 30, or 60 or so. Either way we can just start with 30 since that's what I use to export and upload my videos to Youtube.

Next up would be understanding how the other settings of the encoders affect the quality.

https://trac.ffmpeg.org/wiki/Encode/H.264

Honestly, I can't really tell the difference in video quality after FFmpeg/Handbrake "compresses" it with default values. I've looked into it comparing my source clip and the reencoded clip and I can't tell noticeable differences. Maybe for the types of videos that I do, it's alright, but for others maybe not so. Though if one really wants to preserve video quality, we can utilize using a CRF of 18 (any lower than that is said to be indiscernable), the default CRF is 23 which I think is alright for our purposes. The default preset is medium too which I think is okay. Another interesting setting is tune because it might be better for live IRL lectures to use film but use stillimage for presentations using a slideshow.

Don't know much about audio settings and codecs to tell if we need to change the values for that too.

So for a standard silence-speedup, maybe we could use fps=30 -crf 23 -preset medium
but for a more high quality output we could use fps=30 -crf 18 -preset slow

Or possibly give the user these settings to play with much like in Handbrake

FejaEA6rYj.mp4

But again I'm not really sure how this works nor if I wrote down the syntax correctly so I'll leave it up to you how you'll implement it 😅

Another thing I tested out is if you use ffmpeg to convert an MKV file to MP4 with the default values and only afterwards you remove the silence and export that, the output file has a more noticeable difference in quality. Which I guess makes sense since you're compressing it twice. So I guess this just reinforces the fact that we need to be able to finetune the settings inside silence-speedup directly so we only need to reencode and compress the source video once and preserve the most quality.

Let me know what you think!

@padvincenzo
Copy link
Owner

Hi @rexelbartolome,
Thank you for all these information! I've just edited that same file speedup.js again to include fps, crf and preset, but I didn't test it yet.

To change config, again, you have to edit the file manually. I wrote these values and also the codecs as constants, at lines 22 to 30. So they are more visible now.

Can you try again with these changes?

About the graphical settings, I won't upload a new version soon, but when the time will come, I will add these new variables too.

Thank you again, and good holidays,
Vincenzo

@rexelbartolome
Copy link
Author

rexelbartolome commented Dec 18, 2021

I definitely understand, I think having the values editable in a js file for now is manageable enough for me :D

I've tried it now but I keep getting an error. My source file is an OBS recording, originally an MKV that's been remuxed to an MP4. If I use x8 playback speed for the silence and choose keep as my video format, this shows up:

Started working on 2021-12-14 20-21-24.mp4.
Detecting silences...
34.81 % of the video detected as silence.
Exporting...
[AVFilterGraph @ 0000024f5a8dff40] No such filter: '' Error initializing complex filters. Invalid argument
Fragment [0.000 - 4.593 got filtering error.
All done.

If I use silence speed remove I get this instead

Started working on 2021-12-14 20-21-24.mp4.
Detecting silences...
34.81 % of the video detected as silence.
Exporting...
[AVFilterGraph @ 000001f0b016e500] No such filter: 'undefined' Error initializing complex filters. Invalid argument
Fragment [4.593 - 12.167 got filtering error.
All done.

I think it has something to do with fps?

Also you're very much welcome and good holidays to you too!

padvincenzo added a commit that referenced this issue Dec 18, 2021
* Constant audio (`aac`) and video (`h264`) codex (editable if needed from `speedup.js`)
* New video options: fps, crf and preset

Thanks a lot to @rexelbartolome for [his contribution](#4)
@padvincenzo
Copy link
Owner

Hi @rexelbartolome,
I've done some tests, fixed the problems (adding fps, crf and preset all at once was a bit more difficult than I expected), changed the GUI adding those 3 new variables and published the new version 1.2.2.

This is a screenshot of the new Export settings box. Hope you'll like it.

Schermata da 2021-12-19 01-27-10

I've added the most common values, tell me if you need some more options. I still haven't added the possibility of setting the value for tune, because that won't help with this bug, it's just an improvement (I'll add it in the next release).

Please try this new version and tell me if the bug has been solved. And if your videos are exported with your desired quality.

Thanks again for your feedback (it encouraged me to publish a new version) and best wishes,
Vincenzo

@rexelbartolome
Copy link
Author

rexelbartolome commented Dec 19, 2021

That's amazing! I think the CRF and Preset works flawlessly now. But the exported video still has variable framerate for some reason :( I just checked using FFmpeg too. And I've also checked it with Resolve and the audio still desyncs for longer videos.

C:\Users\Rexel Bartolome\Documents\ShareX\Tools>ffmpeg -i "2021-12-14 19-54-49.mp4" -vf vfrdet -f null -
ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 10.2.1 (GCC) 20200726
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libgsm --enable-librav1e --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '2021-12-14 19-54-49.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.45.100
  Duration: 00:04:31.86, start: 0.000000, bitrate: 6499 kb/s
    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 6363 kb/s, 29.94 fps, 29.97 tbr, 11988 tbn, 59.94 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> wrapped_avframe (native))
  Stream #0:1 -> #0:1 (aac (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Output #0, null, to 'pipe:':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.45.100
    Stream #0:0(und): Video: wrapped_avframe, yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 29.97 fps, 29.97 tbn, 29.97 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc58.91.100 wrapped_avframe
    Stream #0:1(und): Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      encoder         : Lavc58.91.100 pcm_s16le
frame= 8140 fps=2214 q=-0.0 Lsize=N/A time=00:04:31.87 bitrate=N/A speed=  74x
video:4261kB audio:50908kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[Parsed_vfrdet_0 @ 00000269281bdd40] VFR:0.019658 (160/7979) min: 400 max: 668 avg: 417

But basically we would want this VFR value to be 0.000000

[Parsed_vfrdet_0 @ 00000269281bdd40] VFR:0.019658 (160/7979) min: 400 max: 668 avg: 417

Also I'm not sure if this is an error too but when I test for VFR with the file that used x8 speed instead of remove, I get a bunch of lines saying that it's invalid.

    Stream #0:1(und): Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      encoder         : Lavc58.91.100 pcm_s16le
[null @ 000002df5b736200] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 211 >= 211
[null @ 000002df5b736200] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 2611 >= 2611
[null @ 000002df5b736200] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 2932 >= 2932
[null @ 000002df5b736200] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 3160 >= 3160
[null @ 000002df5b736200] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 3740 >= 3740
[null @ 000002df5b736200] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 3771 >= 3771
[null @ 000002df5b736200] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 6281 >= 6281
[null @ 000002df5b736200] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 6441 >= 6441
[null @ 000002df5b736200] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 7080 >= 7080
[null @ 000002df5b736200] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 7701 >= 7701
[null @ 000002df5b736200] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 8410 >= 8410
frame= 8763 fps=2202 q=-0.0 Lsize=N/A time=00:04:52.45 bitrate=N/A speed=73.5x
video:4587kB audio:53704kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[Parsed_vfrdet_0 @ 000002df5b7ecf80] VFR:0.027619 (242/8520) min: 512 max: 860 avg: 532

But regardless it's in a much more workable state, so thank you for that 😊 The workaround I'm thinking is I make the source footage have CFR first and then put it in Speedup, or use Speedup first (since it can now export better video quality!) and then change the fps to CFR again in FFmpeg/Handbrake.

Though apparently upon testing, if I change the framerate to CFR in FFmpeg/Handbrake first, then put that inside Speedup, I get Error during concatenation. I've only tested MP4 and MKV inputs though, both have the same error. I even used an MKV with VFR (transcoded in Handbrake, not the OBS source vid) and it still popped up. So I'm guessing I can only do the other way around: Speedup first before changing to CFR.

I've only just realized that it's actually kind of amazing that you got this to work with OBS's variable frame rates, because I'm assuming time codes etc are less reliable in VFR which is why NLE's have such a hard time with them.

Edit: I also tried changing the framerate using FFmpeg with this command after the file being sped-up

ffmpeg -i <input> -filter:v fps=fps=30 <output>

found in this post: https://stackoverflow.com/questions/45462731/using-ffmpeg-to-change-framerate

It ran fine on VLC, I also tested it out with
ffmpeg -i <input> -vf vfrdet -f null -
and it showed 0.000000 variance on the frame rate

But when I go and put it on Resolve, it still has a weird delay that becomes worse over time. And the video went longer than the audio, which you can see here, I had to speed up the entire vid to 102% so that the video and audio syncs up.
image
This is really weird 😅 this issue doesn't show up when I use Handbrake to change it to CFR though, though that must've been because of re-encoding, which I think fps=30 doesn't really do? 😵

@padvincenzo
Copy link
Owner

Hi @rexelbartolome,
I've run the tool on a obs registered conference call of 50 minutes, and the result is very good, audio and video were in sync.
But, I opened the same exported video with an editing tool (Shotcut) and I've noticed that audio and video were not in perfect sync (audio was a few miliseconds longer than the video). This tiny difference is not human detectable, so I find hard to solve this problem.

Then I thought about the version of ffmpeg that I bundled with Silence SpeedUp, and actually there are updates available. So I downloaded the latest version (4.4.1) and replaced the old one (4.3.1). I run again the tool with the same video and opened the exported file with Shotcut. Audio and video are in perfect sync. Can you try to use the latest ffmpeg version too? Once downloaded the static build (it is a zip or 7z archive file that need to be extracted) for your operative system, open the preferences of Silence SpeedUp and change the FFmpeg path with the path of the executable of ffmpeg.

If this won't work, I don't know what to do, because I cannot reproduce this error anymore... In this case, could you send me a video that gives you the error?

@rexelbartolome
Copy link
Author

Okay I'm actually losing my mind... But apparently the same file I have a problem with works completely well with Shotcut too, no audio desyncing. I think it's because Shotcut is also based on FFmpeg so it can easily read what it just exported. And Resolve is just really picky when it comes to handling video formats and framerates.

When I use the Speedup-exported file, with Silence speed: remove, and I put that in resolve. It's STILL trying to play all the "removed frames" which I think is causing the desyncing issue?

QWLphkjHx4.mp4

I then put that exported vid in Handbrake with the shown settings and after putting that in Resolve, it now works flawlessly

K4b7AftvrM.mp4

So this leads me to believe it's because the video Speedup is exporting is still VFR and not CFR.

If you want to test it yourself, Resolve has a free version and you can download it yourself. Or you can just use the

ffmpeg -i "2021-12-14 19-54-49.mp4" -vf vfrdet -f null -

command to check for variance.

I guess a hacky way of solving this would be automatically using this command on the exported video. This pretty much solved my audio desync and fps problem. The process even took less than a second because there's no reencoding, only remuxing.

# Extract video stream
ffmpeg -y -i input_video.mp4 -c copy -f h264 output_raw_bitstream.h264
# Extract audio stream
ffmpeg -y -i input_video.mp4 -vn -acodec copy output_audio.aac
# Remux with new FPS 
ffmpeg -y -r 30 -i output_raw_bitstream.h264 -i output_audio.aac -c copy output.mp4

I then used the output.mp4 and it works flawlessy both in Resolve and VLC.
But this would pretty much make the filter:v fps=30 obsolete? Since it doesn't really help with changing the framerate? Or maybe, correct me if I'm wrong, the fps=30 is applied to each individual segment, and it's not applied AFTER concatenating all the segments together, which would make the exported video still have variable framerate?

I also experimented with using the remuxing command on videos exported using old Speedup, the version before you added the codecs options. But some errors came out

Here's the input video codec info:

image

And here's what happened in FFmpeg

[aac @ 000001425aaa54c0] Estimating duration from bitrate, this may be inaccurate
Input #1, aac, from 'output_audio.aac':
  Duration: 00:21:10.75, bitrate: 128 kb/s
  Stream #1:0: Audio: aac (LC), 48000 Hz, stereo, fltp, 128 kb/s
Output #0, mp4, to 'output.mp4':
  Metadata:
    encoder         : Lavf58.76.100
  Stream #0:0: Video: h264 (High) (avc1 / 0x31637661), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 30 fps, 30 tbr, 12288 tbn, 24 tbc
  Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #1:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
[mp4 @ 000001425a452780] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
[mp4 @ 000001425a452780] pts has no valueB time=00:00:00.00 bitrate=N/A speed=   0x
    Last message repeated 384 times
[mp4 @ 000001425a452780] pts has no valueB time=00:00:15.95 bitrate= 788.5kbits/s speed=31.9x
    Last message repeated 437 times
[mp4 @ 000001425a452780] pts has no valueB time=00:00:34.20 bitrate= 735.7kbits/s speed=34.2x
    Last message repeated 416 times
[mp4 @ 000001425a452780] pts has no valueB time=00:00:51.58 bitrate= 853.8kbits/s speed=34.4x
    Last message repeated 428 times
[mp4 @ 000001425a452780] pts has no valueB time=00:01:09.45 bitrate= 936.0kbits/s speed=34.7x
    Last message repeated 435 times
[mp4 @ 000001425a452780] pts has no valueB time=00:01:27.62 bitrate= 957.3kbits/s speed=  35x
    Last message repeated 437 times
[mp4 @ 000001425a452780] pts has no valueB time=00:01:45.87 bitrate= 950.8kbits/s speed=35.3x
    Last message repeated 436 times
[mp4 @ 000001425a452780] pts has no valueB time=00:02:04.08 bitrate= 912.7kbits/s speed=35.4x
    Last message repeated 454 times
[mp4 @ 000001425a452780] pts has no valueB time=00:02:23.04 bitrate= 879.7kbits/s speed=35.7x
    Last message repeated 439 times
[mp4 @ 000001425a452780] pts has no valueB time=00:02:41.37 bitrate= 870.7kbits/s speed=35.8x

So I just stopped it. So it might not be as simple as remuxing everything 😅

I feel like we're so close to solving this too! I feel like so many teachers can benefit from this. Maybe even other content creators who do commentary over playthroughs too, as well as people who are into editing podcasts. I really appreciate you developing this, and even making it open source!

I guess one last thing, could you add an audio notification or something when Speed up already finished exporting all the items in queue? I don't see the green bar thing on the task bar anymore and I don't usually use the pop up version since I like to browse while it's going through the process. Thanks so much!

@rexelbartolome
Copy link
Author

Also found this neat little tool: https://sourceforge.net/projects/videoconvertertranscoder/

And how it batch remuxes stuff is much more simple, instead of

# Extract video stream
ffmpeg -y -i input_video.mp4 -c copy -f h264 output_raw_bitstream.h264
# Extract audio stream
ffmpeg -y -i input_video.mp4 -vn -acodec copy output_audio.aac
# Remux with new FPS 
ffmpeg -y -r 30 -i output_raw_bitstream.h264 -i output_audio.aac -c copy output.mp4

I think it only uses a single line per input video so for example this is the command when I used a sample video

ffmpeg -y -i "" -map 0:0 -map 0:1? -c:v copy  -c:a copy -r 30 "E:\_Work\Edits\2021\12Dec\ppink\trimmed\remuxed\2021-12-14 20-08-24.1.mp4"

Not sure how it works but I think -c:v copy and -c:a copy removes the other two lines I've mentioned previously. Also Happy New Year!

@padvincenzo
Copy link
Owner

Hi @rexelbartolome
Happy New Year to you too!
I've found that the problem is in the concatenation of the videos: when ffmpeg concatenates videos copying the codecs (-c copy) it ends up messing up timestamps and/or dts, and the final video do not respect the needed constant frame rate.
The solution is simple: do not specify -c copy and let ffmpeg re-encode all fragments. But doing so is not what I would like to do... it is a waste of time, in my opinion (I do recognize it is necessary, I only wonder why it has to be like this).

With this in mind, what do you think about a new checkbox that gives the user the possibility to choose if the concatenation should or shouldn't be re-encoded?

@rexelbartolome
Copy link
Author

Yeah I wouldn't want it that way either :( . We've already reencoded the video once so I don't think we should add another reencoding. Then how about adding a way to automatically remux the output video to the proper framerate? Since it's just remuxing, it would be instantaneous. And remuxing seemed to have worked well for me even with the videos made on the older versions of Speedup, the pts and timestamps errors only seem to happen when I use this:

# Extract video stream
ffmpeg -y -i input_video.mp4 -c copy -f h264 output_raw_bitstream.h264
# Extract audio stream
ffmpeg -y -i input_video.mp4 -vn -acodec copy output_audio.aac
# Remux with new FPS 
ffmpeg -y -r 30 -i output_raw_bitstream.h264 -i output_audio.aac -c copy output.mp4

But no errors come up if I use this instead:

ffmpeg -y -i "concantenated_video.mp4" -map 0:0 -map 0:1? -c:v copy  -c:a copy -r 30 "remuxed_video.mp4"

Though now that I think about it, I think we should still keep filter:v fps=30 since it would likely be doing the heavy lifting in making the framerate consistent, and the remuxing is just there to iron out the issues that come up after concatenating.

@padvincenzo
Copy link
Owner

Hi @rexelbartolome
I've just uploaded a new version, but this problem is still there...

One thing came to my mind these days: what if the problem is about the -ss and -to options? To be more precise: what if the first and the last frames of each fragment are taken during the encoding, and then the concatenation mess up the timestamps for every duplicate frame (the last of a fragment is equal to the first of the next one)?

As soon as I have time, I'll delve into the matter.

@rexelbartolome
Copy link
Author

Which problem are you talking about? That the audio and video are still desynced once remuxed? :o

I can't really tell right now with the latest release (thanks btw! 😊) Here's a comparison between the 1.2.2 output vs 1.2.3 output (watch with audio), same settings and source obs remuxed mkv-to-mp4 video: 30fps, Fast, Keep Format(mp4), Silence Speed 20x

Resolve_v6EMTwwB7f.mp4

Resolve only has trouble playing the frames if the Silence Speed is anything but removed. If it's removed, I don't see much desyncing. If it's 20x, it much more apparent that they are desynced, as you can tell from the waveform below compared to the actual length of the video

@padvincenzo
Copy link
Owner

Wait, do you mean that audio and video are now correctly synced?

@rexelbartolome
Copy link
Author

Yeah, as far as I can tell, there's no desyncing going on the speededup outputs of version 1.2.3 😄
For version 1.2.2, desyncing is still noticeable (in editing software at least) and you would need to remux or reencode it to the proper framerate again to fix the desyncing. But since you added an auto-remuxer on 1.2.3, desyncing has been fixed, is that right?

@padvincenzo
Copy link
Owner

The only thing that I added is the option - fflags +genpts in the encoding of the fragments, and I split the -c copy in -c:a copy -c:v copy in the concatenation, that's all.

I thought that the de-sync error was still there because the filter vfrdet never returned a value of 0. But if now it works for you I think vfrdet is not a problem anymore, right?

@rexelbartolome
Copy link
Author

rexelbartolome commented Jan 19, 2022

Yeah I guess so. I didn't understand a whole lot on what you said about the encoding changed and splitting regarding concatenation 😅. Might still be the case that there's desyncing going on but I would only notice it on videos way longer like 30mins? Before it was noticeable on videos around 5 mins (like my recent example) but now that doesn't seem to be the case. But yea ideally it should return a value of 0.

After doing some tests I, it actually returned that the VFR was slightly higher on 1.2.3's output

1.2.2's output

[Parsed_vfrdet_0 @ 000001fd2dd5db80] VFR:0.025608 (218/8295) min: 512 max: 861 avg: 534

1.2.3's output

[Parsed_vfrdet_0 @ 0000019cef72d940] VFR:0.027043 (225/8095) min: 512 max: 983 avg: 525 

But it might just be a small discrepancy since they don't have the same Tune and CRF when I processed them

After some reading, Resolve is somewhat capable of reading VFR but there's countless threads about the issues that come up when using VFR clips into NLE's so reencoding those clips to a CFR is the go to answer I've seen. But perhaps something else (like the concatenation part) resulted in desyncing? I'll be processing a video soon that's around 28 mins of footage and if that doesn't desync then I guess this issue can be considered fixed 😆

@rexelbartolome
Copy link
Author

I bring bad news :( It still has a delay on longer videos. I've tried the 28 min video now (removed silence, not sped up) and the same thing happens: it works fine in VLC, but has a delay in Resolve once you look into the later parts of the video. Fortunately the delay is less drastic compared to older versions.

This is what it what the output looks like in Resolve, this is around 24:50 from the source video(which is 28 mins long).

Resolve_CARF2ijQMY.mp4

Remuxing it doesn't really help now either, the delay is still apparent after remuxing, not sure if anything else changed. I guess the only workaround would be to preemptively split longer recordings into shorter clips (i.e., split into 10 min long clips ) using another program (like MKVToolNixGUI) so the delay doesn't get progressively more noticeable the longer it goes. This also leads me to believe that you might be right about the start and end frames of each fragment messing up the audio

@rexelbartolome
Copy link
Author

Heya! Just wanted to follow up on this, if you need help with testing let me know :) If you're still busy, I completely understand so no pressure

Also planning on sharing this with the teachers from my school too but they work with longer videos ~1 hr. Not sure if this VFR thing going to be a problem when it's going to be played through an online video player or Youtube. AFAIK Youtube reencodes the video anyway so desync might not be a problem. I assume you've used this in your university and no problem has come up? 😮

@padvincenzo
Copy link
Owner

Hi @rexelbartolome, I'm still busy these days, but I didn't forget about this issue.

I developed this tool mainly to speedup my university's lessons (1.5 - 3h of videos), and - for almost all - I haven't noticed any delay. But I should also say that I used the "remove" option only for a few videos.. and - most important - these lessons were not of high quality, so if were any desync I wouldn't had noticed it at all.

@padvincenzo
Copy link
Owner

I looked at some Reddit posts about Resolve, and this tool appears in the comments (I guess I have to thank you 😄). Those comments got me think: would it be a good feature to interrupt the tool after detecting silences, then have a new window where you can watch, edit and optionally export all the silences? And only after, continue speeding up the videos?

@rexelbartolome
Copy link
Author

rexelbartolome commented Mar 26, 2022

Hmmm I've tried another program like that here in github, it was built in python I think but the workflow wasn't really great. It spits out all the silence time stamps then when you click on one, it would play it back to you. It needed to open and close VLC when looking through the silences and overall I think it's not really the best way to handle it.

I think a better way is for Speedup to export an XML file that Resolve could read as a clip that's been pre-cut so the user just needs to delete the sections they don't need or an EDL file of some sort that Resolve could read as Markers/Chapters so the user can just use those markers as a guide on where the silences starts and stops. So playback and selection of silences is all done inside Resolve and not in Speedup or VLC or any other media player

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants