• Most new users don't bother reading our rules. Here's the one that is ignored almost immediately upon signup: DO NOT ASK FOR FANEDIT LINKS PUBLICLY. First, read the FAQ. Seriously. What you want is there. You can also send a message to the editor. If that doesn't work THEN post in the Trade & Request forum. Anywhere else and it will be deleted and an infraction will be issued.
  • If this is your first time here please read our FAQ and Rules pages. They have some useful information that will get us all off on the right foot. More details on our policies, especially our Own the Source rule are available here. If you do not understand any of these rules send a private message to one of our staff for further details.
  • Favorite Edit of the Year (FEOTY) Nominations for 2020 are now open! Submit your entries here.

Captain Khajiit's Basic Guide to Decoding Video and Audio

Captain Khajiit

Well-known member
Donor
Messages
2,681
Reaction score
3
Trophy Points
48
1) Introduction

This guide will tell you what you need to know (and only what you need to know) about decoding video and audio; it will tell you nothing whatsoever about processing them.  It was written for faneditors; consequently, much that other videophiles might wish to know has been purposely omitted.  

N.B.  The guide will assume that you know the difference between progressive and interlaced video.  If you do not know, search the forums or google it.  It will also assume that you have ripped your disc successfully with DVDFab or AnyDVD.


Tools

Videohelp.com hosts many tools.  It is a safe place from which to download and always keeps its links up to date, so it should be your first port of call.

AviSynth
AviSynth+ on POSIX systems
BeHappy
DGAVCDecDI
DGIndex
DGIndexNV
eac3to
updated libdcadec for eac3to
FFMS2
GraphStudio
HaaliMediaSplitter
LavFilters
Mediainfo
VirtualDub
VirtualDub-FilterMod

I always use a 32-bit workflow because the 32-bit versions of tools are usually more up to date, but you can use a 64-bit workflow if you like.  N.B.  You must use like with like i.e. you cannot use the 32-bit version of AviSynth with the 64-bit of DGIndexNV (and vice versa).  If in doubt, keep everything 32-bit and you will not go wrong.

Before you start, you need to learn how to make a basic AviSynth script.  Install the latest version of AviSynth.  Open Notepad. File→Save As... MyScript.avs – do not forget to add .avs to the end.  

Then type your script.

Example
Code:
AviSource("C:\Wherever\Whatever.avi")

N.B. Remember to use both inverted commas and brackets whatever your source. ("")
 

Captain Khajiit

Well-known member
Donor
Messages
2,681
Reaction score
3
Trophy Points
48
2) Demuxing

To demux is to separate video and audio.  You need only two tools to demux: PGCDemux for DVDs and eac3to for BDs and HD DVDs.

PGCDemux

Start the program. Click Browse next to Input IFO and try opening each IFO of your ripped DVD in turn until you find the one that gives a runtime that matches your movie.

pgc.png


Settings
Mode: by PGC
Domain: Titles
Demux video stream: checked
Demux audio streams: checked

Check anything else you want. Fill out your output folder. Process. The result will be an .m2v video file and at least one audio track.

Eac3to

N.B. Make sure that you have the Haali Media Splitter installed first.

I suggest you use the HD DVD/Blu-Ray Stream Extractor GUI, which should have been included in your eac3to download.  If not, you can find it here.  Run it.

eac3to.png


  1. Browse for your input folder.
  2. Click Features.
  3. Double-click on the playlist that matches the runtime of your movie.
  4. Check the streams that you want to demux, and choose the output format for each stream.  (The picture above is just an example.  Advice on what to choose follows.)
  5. Fill out your output folder.
  6. Hit Extract.

N.B. With eac3to, you can probably demux and decode your audio in one step.  See section 4.
 

Captain Khajiit

Well-known member
Donor
Messages
2,681
Reaction score
3
Trophy Points
48
3) Video

There are three main video codecs that the faneditor might encounter: AVC, VC-1 and MPEG-2. All three are found on Blu-rays and HD DVDs. Detailed information about them is beyond the scope of this guide, but a very brief introduction to each follows.

AVC is also called h.264. The popular encoder x264 uses this codec, so you have probably used it already.

VC-1 was developed by Microsoft. It is part of the WMV family of codecs that are commonly used online.

MPEG-2 needs little introduction because it is the oldest of the three. It is used for DVDs and sometimes for HD content.
 

Captain Khajiit

Well-known member
Donor
Messages
2,681
Reaction score
3
Trophy Points
48
3a)  DGIndexNV

The best tool for decoding is DGIndexNV because it can decode all three formats well.  It uses CUDA, so you need an NVIDIA card.  If you have one, you should seriously consider purchasing it.  Please note that you can occasionally encounter glitches with all decoders, no matter how good, but DGIndexNV rarely goes wrong because it is updated regularly.  Good support is available from its author, Donald Graft, aka neuron2, via his forum.

Installation instructions are available on neuron2's website, and the tool comes with a detailed user manual, which you are advised to read; but here are brief notes on how to get started.


  1. Install the program.
  2. Make a “donation” via the website.
  3. Find your machine ID by running the program, going to Help → About DGIndexNV and looking under Donald Graft's name.
  4. Plug your login (user) and machine ID into the license generator to receive a license.
  5. Open Notepad, copy your license in, and save as license.txt in your DGIndexNV project folder.  N.B.  You must use the American spelling of license and not the British/Commonwealth spelling.

You can demux your video to MKV or an elementary stream because DGIndexNV handles both.

File→Open
File→Save project as...
Input a filename.
Save as type:  DGIndexNV project file (*.dgi)
Hit Save.

Make an AviSynth script.

Code:
LoadPlugin("...\DGDecodeNV.dll")
DGSource("wherever\whatever.dgi")

Open your script in VirtualDub to preview it.  Job done!

If you do not have an NVIDIA card, there are other ways to decode video, but they are not quite as simple.
 

Captain Khajiit

Well-known member
Donor
Messages
2,681
Reaction score
3
Trophy Points
48
3b) Decoding AVC with DGAVCDecDI

If you do not have an NVIDIA card, consider investing in DGAVCDecDI, which is also by neuron2. The procedure for installing it is very similar to the one outlined above for DGIndexNV. In fact, you can use the same license. DGAVCDecDI uses DiAVC, so you will need to purchase a separate license for that from schweinsz. Follow the installation instructions for DiAVC very closely.

The good thing is that DGAVCDecDI will decode both progressive and interlaced AVC. You can demux your video to MKV or an elementary stream because DGAVCDecDI handles both. Once it is installed, you follow the same procedure as for DGIndexNV, but your script looks like this.

Code:
LoadPlugin("...\DGAVCDecodeDI.dll ")
DGSource("wherever\whatever .dgi")
Open your script in VirtualDub to preview it.
 

Captain Khajiit

Well-known member
Donor
Messages
2,681
Reaction score
3
Trophy Points
48
3c) Decoding progressive AVC with FFMpegSource2()

N.B.  L-SMASH-Works is more reliable than FFMS2() when it comes to frame-accuracy, but the latter sometimes has more recent builds, so I'm leaving this section of the guide here as a fall-back.  Unless you have a particular reason for favoring FFMS2() , proceed to section 3d.

Make sure that you have demuxed your video to MKV (not an elementary stream) with eac3to.  Download the latest version of ffms2.  Inside the folder, you find will find the ffms2.dll and FFMS2.avsi.  Copy both to your AviSynth plugins directory.  Make sure that you have the Haali Media Splitter installed.  Use the following script, adjusting it to fit your directory structure.
Code:
Loadplugin("C:\Program Files (x86)\Haali\MatroskaSplitter\avss.dll")
FFmpegSource2(wherever\whatever.mkv", threads=1, seekmode=0)
Assumefps(24000,1001)# assumes a 23.976fps source

FFMS2() should be frame-accurate, but it occasionally gets the frame-rate wrong.  The last line corrects it.  It assumes a 23.976fps source, which your source probably is if it is progressive AVC.  You might have a rare, pure-24fps BD, in which case use Assumefps(24,1).

Open your script in VirtualDub2 to preview it.

N.B.  FFMS2() works by making an index.  Sometimes this takes a while, so be patient.
 

Captain Khajiit

Well-known member
Donor
Messages
2,681
Reaction score
3
Trophy Points
48
3d) Decoding progressive and interlaced AVC with L-SMASH-Works

L-SMASH-Works can be used to decode progressive AVC and is semi-consistent for interlaced AVC (for which there is no reliable free solution).  Go to the last page of this Doom9 thread, and work your way back until you find the latest buiid by HolyWu, which should be the most reliable.  As usual, I recommend that you stick to a 32-bit workflow.

N.B. Previous versions used FFMS2() for decoding.  This appears no longer to be the case, so I have left the lines to load FFMS2() in the script but uncommented them.  Uncomment them if necessary (by deleting the hashes)  You should not need Haali.  See section 3c for details on how to obtain FFMS2().  You might need to install Visual C++ Runtime Libraries 2015 (and possibly 2013 too).

LSMASHVideoSource()

LSMASHVideoSource() is for formats such as mp4, mov and 3GGP. I recommend that you load the plugin manually rather than relying on it to auto-load.  Then load the video as normal.
Code:
#Import("Wherever\FFMS2.avsi")
#LoadPlugin("Wherever\ffms2.dll")
LoadPlugin("C:\Program Files (x86)\AviSynth\plugins\LSMASHSource.dll")
LSMASHVideoSource("Wherever\Whatever.mp4", threads=1)

LWLibavVideoSource()

LWLibavVideoSource() supports other containers e.g. MKV.
Code:
#Import("Wherever\FFMS2.avsi")
#LoadPlugin("Wherever\ffms2.dll")
LoadPlugin("C:\Program Files (x86)\AviSynth\plugins\LSMASHSource.dll")
LWLibavVideoSource("Wherever\Whatever.mkv", threads=1)

N.B.  L-SMASH works by making an index.  Sometimes this takes a while, so be patient.  It's not unusual for VirtualDub to throw a Not Responding error for a while during the creation of the index. Navigate away from it, give it some time, and check back after a few minutes. You should find your video ready and waiting when you do.
 

Captain Khajiit

Well-known member
Donor
Messages
2,681
Reaction score
3
Trophy Points
48
3e) Decoding VC-1 with the MS WMV DMO Decoder

The MS WMV DMO decoder handles both progressive and interlaced VC-1.

Demux your video to MKV with eac3to.  Install LAV Filters.  Install GraphStudio and run it.

1.(a) Go to Graph → Insert Filter...  (b) Make sure DirectShow Filters are selected, scroll down to Lav Splitter Source and press Insert.  A new menu will pop up.  (c) Hit Browse and find and select your MKV.  Hit Open and then OK.

9lg8rk.png


2. (a)  Use the drop-down menu in the top-left to change DirectShow Filters to DMO Video Decoder.  (b)  Select WMVideo Decoder DMO and hit Insert.  Close the menu.

2d2eqkg.png


3.  You will see that two boxes have appeared.  

2sb4vpc.png


Move the cursor to the first box, left-click on it, drag the green arrow that appears onto the second box, and release it.  The green arrow should remain to indicate a connection, and the boxes should change color.

2j0mi5g.png


Go to File → Save as Graph (.GRF)...  Choose your file-name.  Save as type:  GraphEdit Files.  Hit Save.

Make an AviSynth script pointing to your graph.  The one below assumes a 23.976fps source.

Code:
DirectShowSource("wherever\whatever.grf", fps=23.976, audio=false)
Assumefps(24000,1001)

The last line is present only because I do not like the value that DirectShow gives to 23.976fps: 2500000/104271.  I correct it to 24000/1001.

Open your script in VirtualDub to preview it.
 

Captain Khajiit

Well-known member
Donor
Messages
2,681
Reaction score
3
Trophy Points
48
3f)  Decoding MPEG-2 with DGIndex

MPEG-2 is old technology.  DGIndex does a good job with SD and HD MPEG-2.

Install DGIndex. Look in your DGIndex directory, find DGDecode.dll, and copy it to your AviSynth plugins directory.

Open your file in DGIndex. File→Open
Video→Field Operation→Honor Pulldown Flags
File→Save Project→Save as Type: DGIndex Project File (*.d2v)

Type the following, adjusting it to fit your directory structure.

Code:
 Mpeg2Source("C:\Wherever\Whatever.d2v")

Open your script in VirtualDub to preview it.  See the FAQ of my HCenc guide to know where to go from here.
 

Captain Khajiit

Well-known member
Donor
Messages
2,681
Reaction score
3
Trophy Points
48
4) Audio

There are three main types of audio that the faneditor might encounter:  linear PCM, Dolby Digital, and DTS.  There are various types of Dolby Digital and DTS, including HD audio.  Eac3to can decode them all; the guide also presents BeHappy as an alternative.  You should decode audio to mono WAVs for editing.  Vegas users might choose to decode to W64 instead.  Multi-channel linear PCM does not require decoding, but you might want to split it into mono WAVs.
 

Captain Khajiit

Well-known member
Donor
Messages
2,681
Reaction score
3
Trophy Points
48
4a)  Decoding with eac3to

Eac3to decodes Dolby Digital and DTS formats (including TrueHD and DTS-HD MA) using free software, so if you are dealing with those formats on a BD or HD DVD, you can demux and decode your audio in one step; in fact, I strongly recommend that you do so.  If you are demuxing a TrueHD stream on a seamless-branching disc, you must decode your audio at this point, or you will experience sync problems.  In the picture below, the audio stream being decoded is DTS-HD MA, but the same principle applies to all audio tracks.

fomzvm.png


Once you have selected WAVs or W64, continue the demuxing process that is outlined in section 2.

If you have demuxed a DVD with PGCDemux and want to use eac3to to decode an AC-3 file and split it into mono wavs, I suggest that you use the command line.  This command line gives you the pattern to follow.  You have to change it to fit your directory structure.

eac3to input.ac3 output.wavs

The first part is the location of eac3to on your hard drive.  (You will find the .exe inside your eac3to folder.)
The second part is the location of the source file on your hard drive.
The third part is where you want your output to be and what you want it to be called.

For example,

“"C:\eac3to\eac3to.exe" “C:\Wherever\whatever.ac3” “C:\Wherever\whatever.wavs”

You input this at the command prompt.  (If you do not how to find this,  click on the Start button in the  bottom left, and type Run into the  start box to bring it up.   Alternatively, on Vista and above, you can  copy and paste your command  line into the search box and hit enter and  it should work.)
 

Captain Khajiit

Well-known member
Donor
Messages
2,681
Reaction score
3
Trophy Points
48
4b) Decoding with BeHappy

N.B. Originally, this section was here because eac3to could not, at the time, decode DTS-HD MA, so it was necessary to extract the core.  This is no longer true; however, BeHappy is still a useful program, so I have decided to leave the decoding instructions here (for now) to show how it works.

Install BeHappy and look in the installation directory.  You should see a folder labelled plugins.  Open it and copy the contents to your AvSiynth plugins directory.  Run the program.  

16lkwur.png


  1. In the top-left, you will see long white box labelled [1] Source.  Beneath it is a drop-down menu, the first item in which is the word AviSynth. Click the small, downward-facing arrow and select NicDTSSource.
  2. You will see two buttons with three dots in them […].  Click the one on top and select your DTS file.
  3. In the middle is a section labelled [3] Digital Signal Processing. Highlight Convert Sample To 8 Bit Int and hit Configure.  Select 16-bit int.  Make sure the box next to it is checked.
  4. Now look at the long white box at the bottom labelled [4] Destination and locate another drop-down menu beneath it.  Select “Wavsplit @ Mono wav's” (sic).
  5. Fill out your destination folder and output file-name.
  6. Hit Enqueue.
  7. Click on the Queue tab.  Then hit Start.
 

Captain Khajiit

Well-known member
Donor
Messages
2,681
Reaction score
3
Trophy Points
48
5) FAQ

How do I convert to RGB?

Strictly speaking, this question concerns processing rather than decoding; nevertheless, instructions are given below.

If your source is SD, add this line to your script.
Code:
ConverttoRGB()

If your source is HD, add this line to your script.
Code:
ConverttoRGB(matrix="Rec709")

Both of the above expand the luma range i.e. convert to what Sony calls computer RGB.

You can then make a lossless AVI by doing the following.

Open the script in VirtualDub.

File→Open video file...
Video→Compression→Lagarith (or whatever)
Video→Fast Recompress
File→Save as AVI

N.B. After editing in RGB in an NLE, export a lossless AVI in the same color-space (RGB), and then convert back to YV12 in Rec601/Rec709-aware way.  In other words, for SD output, use ConvertToYV12(), and for HD output, use ConvertToYV12(matrix="Rec709").

How do I resample CD/LD audio to 48kHz?

I recommend sox.
Code:
sox input.wav -b 16 output.wav  rate -h -L -a 48000 dither

Thanks
jagabo
KobaKommander
neuron2
poisondeathray
tebasuna51
TV's Frink
 

TV's Frink

You Catch On Pretty Quick
Staff member
Donor
Faneditor
Messages
23,455
Reaction score
38
Trophy Points
158
Awesome thread. Stuck.
 

TV's Frink

You Catch On Pretty Quick
Staff member
Donor
Faneditor
Messages
23,455
Reaction score
38
Trophy Points
158
e3xz.png


When I decoded both audio streams, the wavs for the AC3 EX were larger than TrueHD/AC3 wavs. Did something go wrong? I would have expected the HD audio to be larger.
 

Captain Khajiit

Well-known member
Donor
Messages
2,681
Reaction score
3
Trophy Points
48
I'm not sure, Frink. Are the smaller WAVs truncated? Is one set 16-bit and the other 24? Look at the log and see what it says.

EDIT: By the way, I might not be able to reply for a long while, as I'm on vacation and rarely have internet access. Moreover, I am not at my computer at the moment, so I don't have access to the program.
 

TV's Frink

You Catch On Pretty Quick
Staff member
Donor
Faneditor
Messages
23,455
Reaction score
38
Trophy Points
158
Log:

eac3to v3.26
command line: "C:\Editing Tools\eac3to\eac3to.exe" "C:\MainMovie\AP_SPY_WHO_SHAGGED_BD01\BDMV\STREAM\00000.m2ts" 3:"C:\MainMovie\AP_SPY_WHO_SHAGGED_BD01\BDMV\STREAM\1_3_audio.wavs" 4:"C:\MainMovie\AP_SPY_WHO_SHAGGED_BD01\BDMV\STREAM\1_4_audio.wavs" -progressnumbers
------------------------------------------------------------------------------
M2TS, 1 video track, 2 audio tracks, 1:35:03, 24p /1.001
1: Chapters, 30 chapters
2: VC-1, 1080p24 /1.001 (16:9)
3: AC3 EX, English, 5.1 channels, 640kbps, 48kHz, dialnorm: -27dB
4: TrueHD/AC3, English, 5.1 channels, 48kHz, dialnorm: -27dB
(embedded: AC3 EX, 5.1 channels, 640kbps, 48kHz, dialnorm: -27dB)
[a03] Extracting audio track number 3...
[a04] Extracting audio track number 4...
[a04] Extracting TrueHD stream...
[a04] Removing TrueHD dialog normalization...
[a04] Decoding with libav/ffmpeg...
[a04] Writing WAVs...
[a03] Removing AC3 dialog normalization...
[a03] Decoding with libav/ffmpeg...
[a03] Reducing depth from 64 to 24 bits...
[a03] Writing WAVs...
[a04] Creating file "C:\MainMovie\AP_SPY_WHO_SHAGGED_BD01\BDMV\STREAM\1_4_audio.R.wav"...
[a03] Creating file "C:\MainMovie\AP_SPY_WHO_SHAGGED_BD01\BDMV\STREAM\1_3_audio.LFE.wav"...
[a03] Creating file "C:\MainMovie\AP_SPY_WHO_SHAGGED_BD01\BDMV\STREAM\1_3_audio.R.wav"...
[a04] Creating file "C:\MainMovie\AP_SPY_WHO_SHAGGED_BD01\BDMV\STREAM\1_4_audio.SR.wav"...
[a04] Creating file "C:\MainMovie\AP_SPY_WHO_SHAGGED_BD01\BDMV\STREAM\1_4_audio.LFE.wav"...
[a04] Creating file "C:\MainMovie\AP_SPY_WHO_SHAGGED_BD01\BDMV\STREAM\1_4_audio.C.wav"...
[a04] Creating file "C:\MainMovie\AP_SPY_WHO_SHAGGED_BD01\BDMV\STREAM\1_4_audio.L.wav"...
[a03] Creating file "C:\MainMovie\AP_SPY_WHO_SHAGGED_BD01\BDMV\STREAM\1_3_audio.C.wav"...
[a03] Creating file "C:\MainMovie\AP_SPY_WHO_SHAGGED_BD01\BDMV\STREAM\1_3_audio.SR.wav"...
[a03] Creating file "C:\MainMovie\AP_SPY_WHO_SHAGGED_BD01\BDMV\STREAM\1_3_audio.SL.wav"...
[a03] Creating file "C:\MainMovie\AP_SPY_WHO_SHAGGED_BD01\BDMV\STREAM\1_3_audio.L.wav"...
[a04] Creating file "C:\MainMovie\AP_SPY_WHO_SHAGGED_BD01\BDMV\STREAM\1_4_audio.SL.wav"...
[a04] The original audio track has a constant bit depth of 16 bits.
[a04] Superfluous zero bytes detected, will be stripped in 2nd pass.
[a04] Starting 2nd pass...
[a04] Extracting audio track number 4...
[a04] Extracting TrueHD stream...
[a04] Removing TrueHD dialog normalization...
[a04] Decoding with libav/ffmpeg...
[a04] Reducing depth from 24 to 16 bits...
[a04] Writing WAVs...
[a04] Creating file "C:\MainMovie\AP_SPY_WHO_SHAGGED_BD01\BDMV\STREAM\1_4_audio.SR.wav"...
[a04] Creating file "C:\MainMovie\AP_SPY_WHO_SHAGGED_BD01\BDMV\STREAM\1_4_audio.L.wav"...
[a04] Creating file "C:\MainMovie\AP_SPY_WHO_SHAGGED_BD01\BDMV\STREAM\1_4_audio.C.wav"...
[a04] Creating file "C:\MainMovie\AP_SPY_WHO_SHAGGED_BD01\BDMV\STREAM\1_4_audio.R.wav"...
[a04] Creating file "C:\MainMovie\AP_SPY_WHO_SHAGGED_BD01\BDMV\STREAM\1_4_audio.SL.wav"...
[a04] Creating file "C:\MainMovie\AP_SPY_WHO_SHAGGED_BD01\BDMV\STREAM\1_4_audio.LFE.wav"...
[a04] The processed audio track has a constant bit depth of 16 bits.
Video track 2 contains 136729 frames.
eac3to processing took 12 minutes, 12 seconds.
Done.]

If I'm reading this right, the ac3 is 24 bits and the truehd is 16 bits?
 

Captain Khajiit

Well-known member
Donor
Messages
2,681
Reaction score
3
Trophy Points
48
TV's Frink said:
If I'm reading this right, the ac3 is 24 bits and the truehd is 16 bits?

You are reading it right. That explains the difference.

EDIT: I would use the WAVs from the TrueHD and not worry about it. Besides, I'm not sure Vegas Movie Studio can do 24-bit audio.

I have to go now. If for some reason you do need to use the AC-3 EX track and want 16-bit WAVs, you can add -down16 to the + Options box to reduce the bit-depth. Good luck, Frink!
 

TV's Frink

You Catch On Pretty Quick
Staff member
Donor
Faneditor
Messages
23,455
Reaction score
38
Trophy Points
158
Captain Khajiit said:
3e) Decoding VC-1

Coming soon!

I anxiously await the good Captain's return and completion of this section :)
 
Top Bottom