EmacsConf: Resynchronizing audio and video using Emacs and subed-record
| emacs, subedPedro Aranda and Roger Schurch used our instance of BigBlueButton to record their upcoming presentation about accessible PDFs with ltx-talk for EmacsConf 2026. I had configured it to export a single-file .webm for easier downloading and playback. After their video finished processing, I downloaded it and I ran WhisperX with diarization on the video file. I trimed the beginning and the ending to remove some extra bits.
While reviewing the transcript and adding chapter markers (using sacha-subed-mpv-ocr-and-select-line-as-comment), I noticed that the audio and video tracks from BigBlueButton kept drifting apart throughout the video. I'm not entirely sure why. Even the original had these synchronization issues.
The desync bothered me enough that I wanted to sort it out. I could get the separate .webms for the audio, screenshare, and webcams, but their durations differed too, so I'd probably still need to figure out the offsets. I decided to work with the combined webm instead. I just needed to figure out the delays to add to the audio file to get it to match up. I'm not used to staring at people's faces trying to read their lips, but I'd had some practice when I corrected the offsets for the Emacs community panel. That one is public. Now my process is:
- Jump to a speaker change, since that's usually when the timestamps drift.
- In MPV, use
C-+orC--somewhat randomly until I happen across a setting that lined it up. I think it's + to add a delay to the audio, which is needed when the audio says the words first and then the video follows.-is for when the video is ahead of the audio. MPV displays the offset when I change it, and I can also useIto display the stats. - Once I've gotten things mostly synced, skim backwards until I find the end of the previous segment where the offset needs to be different.
Add the value as
#+AV_OFFSET:directive in a comment in my VTT file. Ex:00:05:08.004 --> 00:05:11.531 our teaching materials. NOTE #+AV_OFFSET: 600 00:05:11.532 --> 00:05:14.353 [Pedro]: And here in Europe we do have a
- Test it by selecting a region with a few subtitles and using
subed-record-compile-videoto check it. I used ormpv --loop-file=infto loop over the full clip. - Test the audio file for the whole video without regenerating the video part:
mpv video-file.webm --audio-file=test.webm - Combine the new audio track with the video using ffmpeg, or regenerate the whole video with
subed-record-compile-video.
Here are the offsets I came up with:
| Offset | Start time | End time |
|---|---|---|
| -200 | 00:00:14.560 | 00:02:18.840 |
| 300 | 00:02:18.841 | 00:05:11.531 |
| 600 | 00:05:11.532 | 00:06:05.532 |
| 500 | 00:06:05.533 | 00:10:11.660 |
| 800 | 00:10:11.661 | 00:11:00.559 |
| 1000 | 00:11:00.560 | 00:13:17.451 |
| 1800 | 00:13:17.452 | 00:16:06.940 |
| 2500 | 00:16:06.941 | 00:18:16.704 |
| 3000 | 00:18:16.705 | 00:22:12.559 |
| 3600 | 00:22:12.560 | 00:26:31.406 |
| 3900 | 00:26:31.407 | end |
I'm not entirely sure that I've gotten the offsets nailed down yet, but they're better than the original. Once the talk airs on Dec 12, you'll get to see the results at https://emacsconf.org/2026/talks/ltx-talk/ .
So now I have a workflow for resynchronizing audio and video using Emacs. I really liked being able to navigate the video by using the transcript. It was easy to find the next speaker change to examine closely. I liked not having to do lots of fiddly little splits on my clips, particularly since I often found myself needing to move the offset a little earlier or later.
My next steps are probably:
- modify
compile-media.elto handle:av-offsetfor both open and closed captions - modify subed-mpv to handle jumping to the right place
- modify
subed-waveformto take the offset into account when displaying the waveform
Yay editing videos by using plain text!