Skip to content

Instantly share code, notes, and snippets.

@YukinoAi
Last active February 15, 2024 03:24
Show Gist options
  • Save YukinoAi/548b886f5c5d2ec8493c454b7ae28343 to your computer and use it in GitHub Desktop.
Save YukinoAi/548b886f5c5d2ec8493c454b7ae28343 to your computer and use it in GitHub Desktop.

The following is a small guide on decoding RF laserdisc captures (.lds/.ldf) with ld-decode.

Part A - Determining Decode Settings

  • The following information needs to be known.
  1. PAL or NTSC?
  2. If NTSC, is it NTSCJ?
  3. CAV or CLV?
  4. Analog or Digital Audio?
  5. If Digital Audio, is it AC3?
  6. Are there any chapters?
  7. Are there any subtitles?
  8. White threshold at 75% or 100%?
  9. Amount of frames to skip.
  10. Reverse Field order?
  • Some of it can be determined out by looking at the cover of the LD and from LDDB.com. The rest can be figured out by decoding a small part of the .lds/.ldf file.

1) Decode a small part of the raw RF capture.

ld-decode --ntsc --length 1000 --seek 0 --start 500 inputFile.ldf outputFile

  • The previous command is for an NTSC disc. For PAL use --pal instead.
  • --length 1000 means decode only the first 1000 frames.
  • --seek 0 seeks to the first frame on CLV discs. For CAV discs, use --seek 1. This seems pretty reliable lately, but sometimes instead of using --seek, manually adjusting --start, possibly using decimals, may be necessary to start at the first frame. Starting at exactly the first frame is especially important for stacking purposes.
  • --start skips ahead past the spin-up of the disc.
  • Do not use an extension on the outputFile. It will have .tbc appended automatically.
  • For japanese discs use --NTSCJ in addition to --ntsc.

2) Update the vdi data.

ld-process-vbi output.tbc ld-process-vbi --input-json "outputFile.tbc.json" "outputFile.tbc"

  • This should help determine the field order and add in VBI data.

3) Next, run ld-analyze to look at the decode and check for problems.

ld-analyse & then File -> Open TBC File... ld-analyse "outputFile.tbc" &

  • Click on the buttons at the bottom right to add color, change the DAR, highlight any dropouts and reverse the field order.
  • To specify a different comb filter and experiment with different settings: Window-> Chroma decoder configuration.
  • For NTSC, if you notice substantial distortion in solid reds similar to this example, this is known as "wibble". Try starting ld-decode again with --WibbleRemover, or, if it is only minor distortion, ignore it as the --WibbleRemover option has some drawbacks. Minor wibble filters out well in vapoursynth.
  • For PAL, --WibbleRemover ...[does this, something about audio]

Part B - Decoding Option 1 - Manual:

  • Now it is time to further process the raw snippet.tbc output from ld-decode.
  • Manually processing the snippet can help debug issues with the local environment and ensure the highest quality output at every stage in the workflow. It will also make sure the workflow and settings needed for a particular .lds/.ldf is clear enough so the workflow can be modified as needed.
1 - Update VBI data
  • The ld-decode toolset perform dropout detection/correction, comb filtering and needs to know the field order [?]. Updating the VBI information aids in this process.
  • For NTSC, ld-process-vbi also processes items from the IEC NTSC specification that are specific to NTSC LaserDiscs such as 40-bit FM codes, white flags, and other things.
2 - Export chapters, If any[?]

[To check if the LD has chapters [don't they all?], in ld-analyse, go to [] and check [].]

ld-export-metadata output.tbc.json --ffmetadata outputFile.chapters.txt

3 - Dropout correction and color family conversion.

Option 1) Dropout correction (creates a new .tbc) Syntax: ld-dropout-correct [options] input.tbc output.tbc Example: ld-dropout-correct --intra --overcorrect --input-json "outputFile.tbc.json" --output-json /dev/null --quiet testVideo.tbc testVideo.dropoutCorrected.tbc Example2: ld-dropout-correct -ioq --input-json file2_CAV.tbc.json --output-json file2.dropoutfixed.tbc.json file2_CAV.tbc file2_CAV.dropoutfixed.tbc

  • The dropout.corrected.tbc.json file to the corresponding tbc file MUST have the same name and end in "tbc.json" in order to be read by ld-analyze automatically [double check this].

Syntax: ld-chroma-decoder testVideo.tbc testVideo.rgb Example: ld-chroma-decoder -f ntsc3d --luma-nr 0.0 --input-json output.tbc.json -q input.tbc output.rgb

Option 2) Dropout correction + Decoding of YIQ to RGB-16-16-16 raw frames (creates rawVideo.rgb) Syntax: ld-chroma-decoder [options] input.tbc output.rgb Example:

ld-dropout-correct -ioq output.tbc - --output-json /dev/null | \
ld-chroma-decoder -f ntsc2d --luma-nr 0 --input-json output.tbc.json -q - output.rgb

Option 3) Dropout correction + Decoding of YIQ to RGB + Converting to YUV (creates output.lossless.mkv without audio)

ld-dropout-correct -ioq output.tbc - --output-json /dev/null | \
ld-chroma-decoder -f ntsc2d --luma-nr 0 --input-json output.tbc.json -q - - | \
ffmpeg -f rawvideo -pix_fmt rgb48 -s 760x488 -r 30000/1001 -i - -i output.chapters.txt -vcodec ffv1 -pix_fmt yuv444 -aspect 4:3 output.mkv
5 - Dealing with Audio
  • Digital: For digital audio discs, ld-decode will output normalized audio filtered.efm.pcm file (signed 16-bit little endian stereo). It is also possible to use ld-process-efm on the .efm file to output unfiltered.efm.pcm. So, using "ld-process-efm" is optional and only needed to obtain the unprocessed audio.
  • Raw workflow: (.efm->digitalAudio.pcm->flac)
ld-process-efm output.efm output.unfiltered.efm.pcm
ffmpeg -f s16le -ac 2 -r 44.k -i output.unfiltered.efm.pcm
  • Alternative: efm->flac: (output.unfiltered.efm.flac
ld-process-efm output.efm - | ffmpeg -f s16le -ac 2 -r 44.k -i -output.unfiltered.efm.flac
  • Analog: For analog audio, CX decoding is still in the early stages. Currently, if possible, it is better to capture analog out from the player and sync it manually instead.
  • For analog audio only (CX) discs:
cat output.pcm | cx-expander | ffmpeg -f s16le -ac 2 -r 44.k -i - output.flac
6 - Putting everything together. [combined examples go here]

Dropout correction + Decoding of YIQ to RGB + Converting to YUV (creates output.lossless.mkv with Audio)

ld-dropout-correct -ioq output.tbc - --output-json /dev/null | \
ld-chroma-decoder -f ntsc2d --luma-nr 0.0 --input-json output.tbc.json -q - - | \
ffmpeg -f rawvideo -pix_fmt rgb48 -s 760x488 -r 30000/1001 -i - -f s16le -ac 2 -r 44.1k -i output.efm.pcm -c:a flac -i output.chapters.txt -i  -c:v ffv1 -pix_fmt yuv444 -aspect 4:3 output.mkv
  • Note that the above is for an NTSC with digital audio.
  • For analog audio convert it to flac first using cx-expander/ffmpeg and then mux directly:
ld-dropout-correct -ioq output.tbc - --output-json /dev/null | \
ld-chroma-decoder -f ntsc2d --luma-nr 0.0 --input-json output.tbc.json -q - - | \
ffmpeg -f rawvideo -pix_fmt rgb48 -s 760x488 -r 30000/1001 -i - -i output.flac -c:a copy -i output.chapters.txt -c:v ffv1 -pix_fmt yuv444 -aspect 4:3 output.mkv

Part B - Decoding Option 2 - Automatic:

  • Use ld-process.sh which is a wrapper script for ld-decode. For available options type ld-process.sh --help or open it with a text editor: nano ld-process.sh.
  • It supports some of the more common options and it is possible to change the options either staticly or dynamically during runtime.
  • Enter "" to say "use the default value." Syntax: ldprocess.sh inputFile.ldf cavOrClv ntscOrPal combFilter digitalOrAnalogAudio length startAt white ntscj
  • Examples (old): ldprocess.sh "Example2_CLV_side1_JVLA.ldf" clv ntsc ntsc3d digital 0 500 true true ldprocess.sh "Example2_CLV_side1_JVLA.ldf" clv ntsc ntsc3d digital 1000 500 "" false

Part C - Video Filtering and Audio Syncing:

  1. Use vapoursynth via vs-editor to deinterlance or IVTC and then filter the source as needed.
  2. Use Audacity to trim the audio at any cuts done in vapoursynth for syncing purposes.
    • If the display is set to NTSC frame numbers, audacity matches with vapoursynth's pre-ivtc video frames.
  3. Audio can be merged now or later on in the encoding stage.

Part D - Encoding

Encoding Option 1 - Lossless:

vspipe filter.vpy -y - | ffmpeg -i - -i audacityOutput.wav -c:v ffv1 -c:a flac -compression_level 11 output.filtered.mkv or

vspipe filter.vpy -y - | ffmpeg -i - -c:v ffv1 output.filtered.mkv
ffmpeg -i audacityOutput.wav -c:a flac -compression_level 11 audacityOutput.flac
mkvmerge -o output.filtered.merged.mkv output.filtered.mkv audacityOutput.flac
  • The point of encoding it losslessly after filtering is to be able to differentiate between filtering artifacts and encoding artifacts.
  • Encoding the audio seperately allows use of ffmpeg's "-ss" "-t" and "-to" "-c copy" commands for syncing as well if that has not been done already.

Encoding Option 2 - Lossy:

vspipe filter.vpy -y - | ffmpeg -i - -c:v libx264.... [] or ffmpeg -i output.filtered.mkv -c:v libx264 -preset veryslow -tune animation -crf 15 -x264-params ref=16:bframes=12:me=umh:merange=24:aw-mode=2:deblock=-3,-3 -profile:v high10 -c:a flac output.encoded.mkv or ffmpeg -i output.filtered.mkv | x264-10b..... []

  • Play with -crf, raising it or lowering it between 14 to 16 in increments of .5 until there is minimal compression artifacts in the black areas.
  • Adjusting aq-mode may also help.
Other Notes:
  • Keep in mind that x265 does not work well on media with a lot of noise/camera jitter as is typical of older work on LDs.
  • The audio can be syncronized at any stage, including not until the very end, but it is a good idea to check if it can be syncronized after IVTC or deinterlacing to double-check for errors.
@putnam
Copy link

putnam commented Mar 5, 2021

Digital: For digital audio discs, ld-decode will output normalized audio filtered.efm.pcm file (signed 16-bit little endian stereo).

Is this still correct? I can't find any evidence of a code path in ld-decode where this happens. It seems ld-decode only outputs the efm data and that must be independently processed by ld-process-efm. Maybe on an older version?

@Josalo-III
Copy link

Digital: For digital audio discs, ld-decode will output normalized audio filtered.efm.pcm file (signed 16-bit little endian stereo).

Is this still correct? I can't find any evidence of a code path in ld-decode where this happens. It seems ld-decode only outputs the efm data and that must be independently processed by ld-process-efm. Maybe on an older version?

This is my understanding as well.

@YukinoAi
Copy link
Author

When I was working on this, it did output in that format with the discs I was using using the latest version of ld-decode (at the time), so that is what I wrote down. However that might be unique to the discs I was using, some older code (as of today) that is no longer in ld-decode, or perhaps ld-decode calls some external source to handle converting the output somehow.

Just keep in mind that this has not been touched in a while and refer to the updated UI when actually using it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment