sync_rifftrax

Notes on synchronising RiffTrax Just the Jokes with a movie.

View the Project on GitHub widdowquinn/sync_rifftrax

Syncing RiffTrax to Ripped Video (Mac)

Table of Contents

Requirements

Notes on installation

I’ll be using the movie Gravity as an example, but you should change filenames, accordingly.

As the focus of RiffTrax is really the jokes, we take some liberties with the movie audio - compressing the loud and quiet sections, and mixing down from surround/5.1 to stereo.

ffmpeg

For these instructions, ffmpeg needs to be built with the Fraunhofer AAC codec libfdk_aac. Since version 2.0, homebrew no longer allows installation/compilation options for core packages, so this needs to be installed from a third-party tap. On the Mac, this can be done in homebrew using

brew tap homebrew-ffmpeg/ffmpeg
brew install homebrew-ffmpeg/ffmpeg/ffmpeg --with-fdk-aac

Instructions

1. rip the video to .m4v

If you need to do this, HandBrake may be useful.

2. convert container to .mkv

ffmpeg -i Gravity.m4v -codec:v copy -codec:a copy Gravity.mkv

3. identify and extract audio track from the video

Use mkvinfo to identify the relevant track. You are looking for a track with Codec ID of A_AAC. It may have 2 tracks (stereo) or 6 (5.1). We want to identify the track ID for mkvmerge & mkvextract track number.

$ mkvinfo Gravity.mkv
+ EBML head
|+ EBML version: 1
|+ EBML read version: 1
|+ EBML maximum ID length: 4
|+ EBML maximum size length: 8
|+ Doc type: matroska
|+ Doc type version: 4
|+ Doc type read version: 2
[...]
| + A track
|  + Track number: 2 (track ID for mkvmerge & mkvextract: 1)
|  + Track UID: 2
|  + Lacing flag: 0
|  + Language: eng
|  + Default flag: 0
|  + Codec ID: A_AAC
|  + Track type: audio
|  + Audio track
|   + Channels: 6
|   + Sampling frequency: 48000
|   + Bit depth: 16
|  + CodecPrivate, length 2
[...]

Here, we have identified track 1, and can extract it to the file audio.ac3 with mkvextract:

You can get straight to the track info with the following command:

mkvinfo Gravity.mkv | grep -A 6 mkvextract
mkvextract tracks Gravity.mkv 1:audio.ac3

4. convert movie audio to .wav (and 5.1 sound to stereo)

For import into the Audacity audio file editor, convert the movie audio to .wav with ffmpeg:

ffmpeg ‐i audio.ac3 ‐ac 2 audio.wav

The command above also converts the input audio to two channels (stereo).

5. create new Audacity project with movie audio

6. compress movie audio

To even up the loud and quiet parts of the movie track, we use compression.

7. import RiffTrax audio to the Audacity project

8. trim RiffTrax intro

9. initial RiffTrax sync

10. silence Disembaudio

11. balance riff and movie volume

12. auto-duck the movie

13. merge the audio and export to .mp3

14. multiplex (mux) the movie and audio

Use ffmpeg to take the original movie video stream, and your new mixed audio, and combine them in a new .mp4 movie

ffmpeg -i Gravity.mkv -i RiffTrax_Gravity.mp3 \
       -map 0:v:0 -map 1:a:0 \
       -c:v copy -c:a libfdk_aac \
       -metadata title="RiffTrax: Gravity" -y \
       RiffTrax_Gravity.mp4

The settings above do the following:

15. check the final output

### Summary

ffmpeg -i <movie>.m4v -c:v copy -c:a copy <movie>.mkv
mkvinfo <movie>.mkv | grep -A 6 mkvextract
mkvextract tracks <movie>.mkv 1:audio.ac3
ffmpeg -i audio.ac3 -ac 2 audio.wav
ffmpeg -i <movie>.mkv -i audio.mp3 -map 0:v:0 -map 1:a:0 -c:v copy -c:a libfdk_aac \
  -metadata title="RiffTrax: <Movie>" -y "RiffTrax - S01E0?? - <Movie>.mp4"

Extras

NTSC to PAL audio tempo change

In some cases, there is no PAL audio available for a RiffTrax commentary (e.g. single-disc Lord of the Rings, Part One). In these cases, it is possible to use the NTSC-synced audio, and speed it up in order to match PAL framerates.

Correcting RiffTrax PAL speed

Some RiffTrax PAL audio (e.g. Return of the King) is not quite synced with PAL DVDs. These often need a small speed-up, with a tempo change of ≈0.125 as above.