Notes on synchronising RiffTrax Just the Jokes with a movie.
.m4v
.mkv
.wav
(and 5.1 sound to stereo)Audacity
project with movie audioAudacity
project.mp3
Audacity
- for audio editingffmpeg
- for audio extraction and final construction of the video (installable with brew
)Handbrake
- to rip the video from the original media source (if necessary)Homebrew
- to install packages on the Macmkvtoolnix
- for inspection of media files (installable with brew
)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
.m4v
If you need to do this, HandBrake may be useful.
.mkv
ffmpeg -i Gravity.m4v -codec:v copy -codec:a copy Gravity.mkv
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
.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).
Audacity
project with movie audioAudacity
(this will create a new project)To even up the loud and quiet parts of the movie track, we use compression.
Effects->Compressor...
to compress the movie audio
Audacity
project.mp3
file. I’ve found that the US .mp3
s work best for blu-ray, and the PAL .mp3
s for DVD.
README
file for the movie is very useful, and it’s handy to have it open in a text editor windowsolo
the RiffTrax audio for this stage
Selection Start
manually to zero and cut the section
Tracks->Add New->Mono Track
) and paste in the audio you cut, then export the selected audio to a new file (e.g. rifftrax_intro.wav
), if you want to preserve it. Then delete that track.Using the RiffTrax README
(here Gravity_RiffTraxReadme.txt
) locate the first Disembaudio line
Here, this is at 1:56.042 (after trimming, it tends to be slightly earlier than the movie time)
Solo the movie audio, and identify the line in the movie - here it is at 2:05.125
Select the zero point at the start of the Rifftrax
Add 9.083s of silence at the beginning of the RiffTrax audio using Generate->Silence
README
file, locate and select each Disembaudio line
Generate->Silence
while the line is selected
Effect->Amplify
to add or remove gain.
Effects->Auto-duck...
to quieten the movie track whenever the RiffTrax commentary audio is playing. For this to work, have the movie audio positioned above the RiffTrax audio in the Audacity
window.
Effects->Auto-duck...
and set the ducking parameters
.mp3
Tracks->Mix and Render
.mp3
file
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:
Gravity.mkv
with the audio file RiffTrax_Gravity.mp3
RiffTrax_Gravity.mp4
map
the video from input stream 0 (Gravity.mkv
) to output stream 0 (RiffTrax_Gravity.mp4
): -map 0:v:0
map
the audio from input stream 1 (RiffTrax_Gravity.mp3
) to output stream 0 (RiffTrax_Gravity.mp4
): -map 1:a:0
-c:v copy
-c:a libfdk_aac
-metadata title="RiffTrax: Gravity"
### 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"
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.
.mp3
trackAudacity
, use Effects -> Change Tempo
and set the percentage change to 4.271
(if you want to convert PAL to NTSC, the change is -4.096
)OK
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.