Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Video Encoding > MPEG-4 AVC / H.264

Reply
 
Thread Tools Search this Thread Display Modes
Old 12th November 2018, 21:07   #1  |  Link
Blovesx
Registered User
 
Join Date: May 2015
Posts: 14
Encoding and deinterlacing DVDs using .avs

Hello,

Could someone help me with how to use .avs scripts properly? I have some ripped DVDs in which videos are interlaced in 30000/1001 NTSC format. I would like to encode the video using MediaCoder, ffmpeg, MeGUI or any other program with x264 codec and to use in the encode process my .avs script. I have never deinterlaced DVDs so I'd like to get some help from you.

I read trough a lot of threads and would like to deinterlace using YADIF + nnedi3 and FFT3DFilter. I have seen video sample using TempGaussMC but it's probably taking too long to deinterlace so I'm not thinking about this plugin anymore.

Code:
Load_Stdcall_Plugin("C:\Programs\MeGUI\tools\avs\plugins\yadif.dll")
LoadPlugin("C:\Programs\MeGUI\tools\avs\plugins\nnedi3.dll")
LoadPlugin("C:\Programs\MeGUI\tools\avs\plugins\fft3dfilter.dll")
Yadif(mode=0, order=-1, planar=false, opt=-1)
nnedi3(field=1)
FFT3DFilter(sigma=3)
Is there something wrong with this script?

I tried using MediaCoder x64 and load this script but nothing happened.
I tried using ffmpeg BUT I don't know how to write .avs script with plugins and x264 settings and what commands to use while typing in console ffmpeg .... ?
I tried using MeGUI but got error saying something about wrong version...

I have installed AviSynth 2.6.0 latest version from sourceforge, ffmpeg x64, plugins x64 and x32.

Should I install another version of AviSynth?
Could someone post how to write script that I can use with ffmpeg including x264 options?

... or maybe you guys recommend another way of encoding and deinterlacing video?

PS. I found in MediaCoder 2 options:
Motion Compensation?
IVTC?

Should these be used while deinterlacing? Also if the video is in NTSC format can I use -framerate 24000/1001 without destroying the flow of video without any stuttering?

Thanks a lot for any replies.
Blovesx is offline   Reply With Quote
Old 13th November 2018, 00:06   #2  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
It may seem a little obvious, but do you do not seem to have a Video Source in the script ?
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 13th November 2018, 17:20   #3  |  Link
Blovesx
Registered User
 
Join Date: May 2015
Posts: 14
I'm using directshow. Should I use maybe avisource or the other avi?
Either way what I'm most interested in right now is how do you write script for ffmpeg to use x264 encoder with settings inside the script? Someone can post an example?

And also how to avoid stuttering if I want to change ntsc framerate to film one 24000/1001?
Blovesx is offline   Reply With Quote
Old 13th November 2018, 21:36   #4  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Quote:
I have installed AviSynth 2.6.0 latest version from sourceforge
Use this one, Pinterf avs+, better than avs v2.6 standard:- https://github.com/pinterf/AviSynthPlus/releases
(Its a little difficult to find as Pinterf dont have his own thread and original avs+ thread points to a very old version, also Pinterf sig below his posts points to the source code and not the binary, so one has to do a little bit of investigating to find it).

Quote:
Should I use maybe avisource or the other avi?
Dont know, you did not post full script and so we dont know if source is avi or not, but if it is, then AviSource is almost certainly better than DirectShowSource.
(DirectShowSource should be last option where everything else fails).

Quote:
I have some ripped DVDs
In that case you would want to use DGIndex and MPeg2Source.
Post a sample on some file host (MediaFire often used [EDIT: zip it up first]),
In DGIndex, mark start ('[' symbol), and end (']') of a 10 second segment with motion, then on file Menu, "Save Project and Demux Video",
and post the "m2v" file. [EDIT: Dont bother with any other produced files]

The experts here will be able to tell you if your source is interlaced or film requiring Inverse Telecine rather than deinterlace.

To determine field order
Code:
... # source filter
AssumeTFF # or also try AssumeBFF
return SeparateFields
... #
And view in eg VDub2, if jumps backwards and forwards, then wrong field order, use the other one. [EDIT: Then remove SeparateFields]
[EDIT: Will be half height, resize in VDub2 to full size when viewing]

Quote:
I tried using MeGUI but got error saying something about wrong version...
Although the guys here like a good mystery, it is preferable that you actually say what the error message was.

Others here can probably help you better than I, I'm from PAL land and dont have to play with NTSC much (HeHeHe).
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 13th November 2018 at 22:10.
StainlessS is offline   Reply With Quote
Old 13th November 2018, 22:58   #5  |  Link
Blovesx
Registered User
 
Join Date: May 2015
Posts: 14
Okay, um I have ripped DVD and what I have are .VOB files.

This is it about the file from MediaInfo:
Code:
Complete name : C:\dvd\VTS_01_1.VOB 
Format : MPEG-PS 
File size : 1 024 MiB 
Duration : 16 min 52 s 
Overall bit rate mode : Variable 
Overall bit rate : 8 482 kb/s 
Writing library : encoded by TMPGEnc Video Mastering Works 5 Version. 5.3.0.82 

Video 
ID : 224 (0xE0) 
Format : MPEG Video 
Format version : Version 2 
Format profile : Main@Main 
Format settings : CustomMatrix / BVOP 
Format settings, BVOP : Yes 
Format settings, Matrix : Custom 
Format settings, GOP : M=3, N=16 
Format settings, picture structure : Frame 
Duration : 16 min 52 s 
Bit rate mode : Variable 
Bit rate : 8 121 kb/s 
Maximum bit rate : 9 400 kb/s 
Width : 720 pixels 
Height : 480 pixels 
Display aspect ratio : 16:9 
Frame rate : 29.970 (30000/1001) FPS 
Standard : NTSC 
Color space : YUV 
Chroma subsampling : 4:2:0 
Bit depth : 8 bits 
Scan type : Interlaced 
Scan order : Top Field First 
Compression mode : Lossy 
Bits/(Pixel*Frame) : 0.784 
Time code of first frame : 00:00:00:00 
Time code source : Group of pictures header 
GOP, Open/Closed : Closed 
Stream size : 980 MiB (96%) 
Writing library : TMPGEnc Video Mastering Works 5 Version. 5.3.0.82 
Color primaries : BT.601 NTSC 
Transfer characteristics : BT.601 
Matrix coefficients : BT.601 

Audio 
ID : 189 (0xBD)-128 (0x80) 
Format : AC-3 
Format/Info : Audio Coding 3 
Commercial name : Dolby Digital 
Muxing mode : DVD-Video 
Duration : 16 min 52 s 
Bit rate mode : Constant 
Bit rate : 192 kb/s 
Channel(s) : 2 channels 
Channel layout : L R 
Sampling rate : 48.0 kHz 
Frame rate : 31.250 FPS (1536 SPF) 
Bit depth : 16 bits 
Compression mode : Lossy 
Stream size : 23.2 MiB (2%) 
Service kind : Complete Main
I'm overwhelmed by all of the scripts, plugins, programs...

I have installed the AviSynth+ and this is my script:
Code:
LoadPlugin("C:\Programy\AviSynth+\plugins64+\DirectShowSource.dll")
DirectShowSource("C:\dvd\VTS_01_1.VOB", fps=23.97, convertfps=true, pixel_type="YV12")
Load_Stdcall_Plugin("C:\Programy\AviSynth+\plugins\yadif.dll")
Yadif(mode=0, order=-1, planar=false, opt=-1)
LoadPlugin("C:\Programy\AviSynth+\plugins64+\nnedi3.dll")
nnedi3(field=1)
LoadPlugin("C:\Programy\AviSynth+\plugins64+\fft3dfilter.dll")
FFT3DFilter(sigma=3)
Am I missing something? When I tried to encode it trough ffmpeg I got error: Cannot load a 32 bit DLL in 64 bit Avisynth: 'C:/Programy/AviSynth+/plugins/yadif.dll'

So I downloaded yadifmod2 and it works fine.

This is all too hard for me. Maybe I will tell what I'm trying to achieve.
My goal is to encode the .VOB file to .mp4 file using x264 plugin with my own settings, deinterlace it and if possible change fps to 23.97 or if it's better to leave as it is then it's fine then I would like to save image sequences and run batch file to resize it and encode it back into .mp4 resized version.

PS. I have installed AviSynth+ x64 and x86, aswell ffmpeg x64, mediacoder x64, megui. If I should use different programs to do so let me know.

PS2. I have also installed VapourSynth64Portable I found on this forum it's probably for resizing video but I'd better stick with resizing images since it won't be a piece of cake to use this program probably...

Oh well that's it.

EDIT.
What should I write in the script if I want to encode all the .VOB files 01, 02, 03, 04 and join them together into .mp4?

Last edited by Blovesx; 14th November 2018 at 00:06.
Blovesx is offline   Reply With Quote
Old 14th November 2018, 14:02   #6  |  Link
Sharc
Registered User
 
Join Date: May 2006
Posts: 3,997
Quote:
Originally Posted by Blovesx View Post
….I'm overwhelmed by all of the scripts, plugins, programs….. ….This is all too hard for me..... ….Oh well that's it.

EDIT.
What should I write in the script if I want to encode all the .VOB files 01, 02, 03, 04 and join them together into .mp4?
Hmmm….. much can go wrong. Maybe it's easier when you open the Video_ts folder which contains all your .VOBs in Handbrake and select .mp4 as output container. It will join the .VOBs and encode with x264.
I doubt that you should deinterlace. Your video is probably telecined film, but we would need a sample to be sure. So leave as is and don't resize it in a first attempt.

Edit: You could also import your DVD in BD-Rebuilder and select the .mp4 output container. You need to familiarize with BD-Rebuilder though and carefully follow its installation instructions.

Good luck.

Last edited by Sharc; 14th November 2018 at 15:05.
Sharc is offline   Reply With Quote
Old 15th November 2018, 09:21   #7  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Royal Borough of Kensington & Chelsea, UK
Posts: 2,869
If it's a VOB extracted from a DVD, don't use DirectShowSource, use DGIndex instead.
DGIndex it's gonna index your VOB and extract audio tracks.
Once you have done that, check whether it's truly interlaced or telecined.
If you are not sure whether it's interlaced or telecined, just try to deinterlace it first and go frame-by-frame; if it has dups, it probably means that it's telecined.

If interlaced:

Code:
#Indexing
video=DGDecode_MPEG2Source("video.d2v")
audio=WAVSource("audio.wav")
AudioDub(video, audio)

#Deinterlace to 29.970fps progressive
tdeint(mode=2, order=-1, field=-1, mthreshL=6, mthreshC=6, map=0, type=2, debug=false, mtnmode=1, sharp=true, cthresh=6, blockx=16, blocky=16, chroma=true, MI=64, tryWeave=true, link=1, denoise=true, slow=2, opt=4)

#Resize
Spline64Resize(848, 480)
if telecined:

Code:
#Indexing
video=DGDecode_MPEG2Source("video.d2v")
audio=WAVSource("audio.wav")
AudioDub(video, audio)

#IVTC to 23.976fps
tfm(mode=1,pp=5,slow=2,micmatching=2,clip2=tdeint(mode=2,type=3)) 
tdecimate(mode=2, rate=23.976)

#Resize
Spline64Resize(848, 480)
I hope it helps. ^_^
FranceBB is online now   Reply With Quote
Old 17th November 2018, 23:59   #8  |  Link
Blovesx
Registered User
 
Join Date: May 2015
Posts: 14
Why would I resize the original VOB to 848x480?

This is the information about my VOBs I have:
Code:
Stream Type: MPEG2 Program
Profile: main@main
Frame Size: 720x480
Display Size: 720x480
Aspect Ratio: 16:9 [3]
Frame Rate: 29.970030 fps
Video Type: NTSC
Frame Type: Interlaced
Coding Type: B
Colorimetry: SMPTE 170M
Frame Structure: Frame
Field Order: Top
It says also the pics/s are 29,97 also frames and fields 59940 (interlaced, tff) 3:2 sar, dar 16:9

What more... it is animation. So I believe I should save it as D2V project file using 'Honor Pulldown Flags' and use the IVTC one code you gave me? Should I also deinterlace it?

One more question I don't get about colours is which is the one people mostly use for PC? I'm always confused... but I'm sure in ffmpeg you can only choose yuv420p whatever it is meant to be. Also should I use yuv420p10 if I want to use x264 to encode to 10bit?

PS. Most important question I have 4 .VOB files from the DVD but I'd like to merge 2 of them only. Should I run it trough IVTC process then merge it using ffmpeg option? Then I can encode it for .mp4 format?

Maybe stupid question how do I use the script?

Code:
LoadPlugin("C:\Programy\AviSynth+\docs\dgmpgdec158\DGDecode.dll")
video=MPEG2Source("VTS_01_1.d2v")
audio=AC3Source("VTS_01_1 T80 2_0ch 192Kbps DELAY 0ms.ac3")
AudioDub(video, audio)

#IVTC to 23.976fps
tfm(mode=1,pp=5,slow=2,micmatching=2,clip2=tdeint(mode=2,type=3)) 
tdecimate(mode=2, rate=23.976)
Tried ffmpeg -i dvd.avs test.mp4 and nothing happened.

Last edited by Blovesx; 18th November 2018 at 00:45.
Blovesx is offline   Reply With Quote
Old 18th November 2018, 18:38   #9  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Royal Borough of Kensington & Chelsea, UK
Posts: 2,869
Quote:
Why would I resize the original VOB to 848x480?
Your source is 720x480 which is anamorphic flagged 16:9.
720x480 can be either flagged 4:3 or 16:9, it's up to the player to display the correct aspect ratio.
You could leave it as it is and just flag it, but if you are gonna watch it on a computer, I think it's better if you resize it yourself to 16:9.

Quote:
What more... it is animation. So I believe I should save it as D2V project file using 'Honor Pulldown Flags' and use the IVTC one code you gave me? Should I also deinterlace it?
Save it as it is, then use the IVTC code I gave you: TFM will use Tdeint to deinterlace and Tdecimate to detect dups and output 23.976fps.
This way, you'll have the original progressive framerate back.

Quote:
One more question I don't get about colours is which is the one people mostly use for PC? I'm always confused... but I'm sure in ffmpeg you can only choose yuv420p whatever it is meant to be. Also should I use yuv420p10 if I want to use x264 to encode to 10bit?
I'll try to explain, then. ^_^

Color Sampling:

4:2:0, 4:2:2, 4:4:4 are the chroma sampling.
4:2:0 is generally the standard as it's supported by a wide majority of devices.
4:2:2 is generally used by studios in order to make mezzanine files. (I use it on a daily basis).
4:4:4 is generally used for master files and it retains as many details as possible for chroma.

The reason why the standard chroma sampling is 4:2:0 is that luma samples are more important than chroma samples for our eyes due to rods and cones.

Color Matrices:

The most known color matrices are BT601 (for SD contents), BT709 (for HD and FULL HD contents) and BT2020 (for UHD contents).
In your case, the color matrix is BT601 and you should keep it that way, unless you wanna upscale. In that case, you would have to convert it.

Levels (TV and PC):

TV and PC is actually just a different name for "Limited" and "Full".
TV range is Limited range. PC range is Full range.
Because TVs can't display as many things as PCs, everything that goes on air must be in Limited range, otherwise it will be refused on QC.
Limited range is 16-235 (0.0 - 0.7V), while Full range is 0-255 for 8bit.
In your case it's limited range, with 16 as pure black and 235 as pure white and you should leave it as it is.

Bit depth:

The standard has always been 8bit, but nowadays, with HEVC, UHD contents are 10bit.
As a matter of fact, x264 has been able to encode in 10bit for many years, but unfortunately it has never been standard and it was possible to play such files on computers only (and a very limited number of devices).
Anyway, Avisynth has been supporting high bit depth for years and there's a reason: filtering.
In other words, I always suggest to encode to 10bit in H.264 if you don't care about playback compatibility for two reasons:

1) If you wanna filter out issues, index your 8bit source, bring everything to 16bit, filter out issues, then dither it down to either 10bit or 8bit.
2) If you wanna encode an 8bit source to 10bit, it would still make sense to encode it to 10bit 'cause x264 will use 10bit precision calculations internally and it will manage to save more space (at the same quality) than 8bit.

If you do wanna have playback compatibility, then you should encode to 8bit.

Quote:
Most important question I have 4 .VOB files from the DVD but I'd like to merge 2 of them only. Should I run it trough IVTC process then merge it using ffmpeg option?
You can do "append" with Avisynth

Code:
#Indexing
video=DGDecode_MPEG2Source("VTS_01_1.d2v")
audio=AC3Source("VTS_01_1.ac3")
AudioDub(video, audio)

#IVTC to 23.976fps
tfm(mode=1,pp=5,slow=2,micmatching=2,clip2=tdeint(mode=2,type=3)) 
tdecimate(mode=2, rate=23.976)

#Resize
Spline64Resize(848, 480)

part1=last


#Indexing
video=DGDecode_MPEG2Source("VTS_01_2.d2v")
audio=AC3Source("VTS_01_2.ac3")
AudioDub(video, audio)

#IVTC to 23.976fps
tfm(mode=1,pp=5,slow=2,micmatching=2,clip2=tdeint(mode=2,type=3)) 
tdecimate(mode=2, rate=23.976)

#Resize
Spline64Resize(848, 480)

parte2=last

#append
part1++part2
This way you'll have two videos, one after another, appended together.

By the way, may I suggest you to use x264, NeroAAC and Mp4box instead of ffmpeg?

Last edited by FranceBB; 18th November 2018 at 18:43.
FranceBB is online now   Reply With Quote
Old 19th November 2018, 20:59   #10  |  Link
Blovesx
Registered User
 
Join Date: May 2015
Posts: 14
One more thing is could you explain me how do I use the script and could you give me example scripts concerning the other programs and the commands to use them trough cmd aswell as the order in which I should use them? I have downloaded x264 10bit and 8bit version, NeroAAC and Mp4box now I need to know how to use them.

Another thing is I have installed AviSynth+ 64 bit should I use AviSynth+ x86 version instead? Do you recommend using x64 plugins or x86 plugins what's the difference?

Last one, you explained to me how the colors work but I'm still not sure is it i420 or yv12 I should use?
Code:
The reason why the standard chroma sampling is 4:2:0 is that luma samples are more important than chroma samples for our eyes due to rods and cones.
That would be it. Thank you for your interest in the topic.
Blovesx is offline   Reply With Quote
Old 20th November 2018, 10:18   #11  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,821
If you use MeGUI, it should take care of your concerns, and it comes with the programs you mentioned, except for NeroAAC (copy it to the "MeGUI\tools\eac3to" folder if it exists, and enable NeroAAC in MeGUI's options).

MeGUI comes with a portable version of Avisynth+ that it uses by default. I assume 32 bit MeGUI comes with 32 bit Avisynth+ and 64 bit MeGUI includes 64 bit Avisynth+.
You can't mix and match. If you installed 32 bit Avisynth then you need to use 32 bit Avisynth plugins with it. It's probably better for the "installed" Avisynth to be the same as MeGUI's portable version, as then scripts created by MeGUI will open in other programs (only MeGUI uses it's portable version). There used to be a shortage of 64 bit plugins, although I think it's getting better now, but installing 32 bit versions of everything is probably the safer bet.
hello_hello is offline   Reply With Quote
Old 20th November 2018, 20:23   #12  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Royal Borough of Kensington & Chelsea, UK
Posts: 2,869
You should install Avisynth+ (pinterf) x86, 'cause it's more stable and there are many filters for it.
You can get a list of plugins from me as I included "plugins" and "plugins+" in the rar I uploaded: Link

In the rar you'll find:
1) Plugins
2) Plugins+
3) encoder

In the "encoder" folder, you'll find avs4x264mod.exe, Bepipe.exe, NeroAAC.exe, MP4Box.exe, x264-10b.exe, Command Line H264 10bit.bat and AVS Script.avs.

Copy all my plugins in your plugins directory.
Make sure you have all the C++ Redistributable and .NET Framework installed.

Leave the AVS Script as it is, just make sure that the names and the path are correct.
Then, double click on the .bat and the encode should start.

The bat is pretty easy, it basically encode the video with x264 10bit in 4:2:0 High level 4.1 crf 19 and creates a ".h264" file.
Bepipe gets the audio from Avisynth and pipes the uncompressed audio stream to NeroAAC which encodes in AAC at 320kbit/s (bitrate should be enough, but you can change it).
NeroAAC creates a ".aac" audio.
Last but not least, MP4Box muxes video and audio and creates a ".mp4" file.

AVS Script:

Code:
#Indexing
video=DGDecode_MPEG2Source("VTS_01_1.d2v")
audio=AC3Source("VTS_01_1.ac3")
AudioDub(video, audio)

#IVTC to 23.976fps
tfm(mode=1,pp=5,slow=2,micmatching=2,clip2=tdeint(mode=2,type=3)) 
tdecimate(mode=2, rate=23.976)

#Resize
Spline64Resize(848, 480)

part1=last


#Indexing
video=DGDecode_MPEG2Source("VTS_01_2.d2v")
audio=AC3Source("VTS_01_2.ac3")
AudioDub(video, audio)

#IVTC to 23.976fps
tfm(mode=1,pp=5,slow=2,micmatching=2,clip2=tdeint(mode=2,type=3)) 
tdecimate(mode=2, rate=23.976)

#Resize
Spline64Resize(848, 480)

parte2=last

#append
part1++part2

#Color Matrix Conversion
ColorMatrix(mode="Rec.601->Rec.709", interlaced=false, threads=0, thrdmthd=0, opt=3)

#Clipping
Limiter(min_luma=16, max_luma=235, min_chroma=16, max_chroma=240)
Command Line H264 10bit.bat:

Code:
avs4x264mod.exe "AVS Script.avs" --x264-binary "x264-10b.exe" --preset medium --level 4.1 --profile High10 --crf 19.0 --vbv-maxrate 25000 --vbv-bufsize 25000 --deblock -1:-1 --overscan show --colormatrix bt709 --range tv --log-level info --thread-input --transfer bt709 --colorprim bt709 --videoformat component --nal-hrd vbr --output "raw_video.h264"

Bepipe.exe --script "Import(^AVS Script.avs^)" | neroAacEnc.exe -lc -br 320000 -if - -of "audio.aac"

mp4box.exe -add "raw_video.h264" -add "audio.aac" "final_output_10bit.mp4"

pause


Cheers
FranceBB is online now   Reply With Quote
Old 23rd November 2018, 04:23   #13  |  Link
Blovesx
Registered User
 
Join Date: May 2015
Posts: 14
Thank you for your help FranceBB. You helped me a lot and probably other people who were watching this thread.

Though, I had problems using the script you gave me but I found somehow the solution to it.

I had to use these plugins:
Code:
LoadPlugin("C:\Programs\AviSynth+\plugins\MPEG2DEC.dll")
LoadPlugin("C:\Programs\AviSynth+\plugins\DGDecode.dll")
LoadPlugin("C:\Programs\AviSynth+\plugins\NicAudio.dll")
and change:
Code:
video=DGDecode_MPEG2Source to video=MPEG2Source
as well as:
Code:
audio=AC3Source to audio=NicAC3Source
I don't know why but the script just wouldn't let me convert using the ac3audio.dll I had an error something with wrong argument or unable to find argument...

Since we're at it could you tell me how using this script I can encode part1 and part2 certain amount of time for ex. from 0 to 10 min. only not the whole file.

I'm not really sure what the rest of the script is doing:
Code:
#Color Matrix Conversion
ColorMatrix(mode="Rec.601->Rec.709", interlaced=false, threads=0, thrdmthd=0, opt=3)

#Clipping
Limiter(min_luma=16, max_luma=235, min_chroma=16, max_chroma=240)
but I left the color untouched so YUV 4:2:0 was being used.

Not really sure what's Limiter doing which plugin is responsible for this and ColorMatrix?

PS. Can I use NicAC3 to encode .ac3 format to also my chosen bitrate and bits, khz? It's said in documents only .raw file.
PS2. How should I approach the encoded file now if I want to save all the frames as image sequences so I can run batch file to resize it using another program? After that can I just use ffmpeg to connect image sequences into *.mp4 without encoding?

Last edited by Blovesx; 23rd November 2018 at 04:26.
Blovesx is offline   Reply With Quote
Old 23rd November 2018, 06:46   #14  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Royal Borough of Kensington & Chelsea, UK
Posts: 2,869
Quote:
I don't know why but the script just wouldn't let me convert using the ac3audio.dll I had an error something with wrong argument or unable to find argument...
You can use LWLibavAudioSource or FFAudioSource to index audio, it's not a big deal.

Quote:
Not really sure what's Limiter doing which plugin is responsible for this and ColorMatrix?
As to Colormatrix, it converts from BT601 to BT709, but you could just flag x264 to encode it as BT601 and remove that line.
As to Limiter, it just makes sure that Limited TV Range is respected and values don't exceed the range 16-235. (Ever since I started working in broadcast, I started to be extremely concerned about tv range).

Quote:
Can I use NicAC3 to encode .ac3 format to also my chosen bitrate and bits, khz? It's said in documents only .raw file.
As it is now, Avisynth just outputs an uncompressed audio and video stream which is encoded by x264 and NeroAAC, but if you wanna encode audio to AC3, you can just use ffmpeg to encode audio only.

You said that you wanted a specific frequency; in that case, you can either use ResampleAudio() or SSRC in Avisynth to feed the audio encoder (ffmpeg) with the desired sampling rate.

Like:

Code:
#Loudness Correction
ResampleAudio(48000)
Quote:
Since we're at it could you tell me how using this script I can encode part1 and part2 certain amount of time for ex. from 0 to 10 min. only not the whole file.
You can just use "trim" and trim files.
For instance:

Code:
#Indexing
video=DGDecode_MPEG2Source("VTS_01_1.d2v")
audio=AC3Source("VTS_01_1.ac3")
AudioDub(video, audio)

#IVTC to 23.976fps
tfm(mode=1,pp=5,slow=2,micmatching=2,clip2=tdeint(mode=2,type=3)) 
tdecimate(mode=2, rate=23.976)

#Resize
Spline64Resize(848, 480)

#Trimming the first 1000 frames
trim(0, 1000)

part1=last


#Indexing
video=DGDecode_MPEG2Source("VTS_01_2.d2v")
audio=AC3Source("VTS_01_2.ac3")
AudioDub(video, audio)

#IVTC to 23.976fps
tfm(mode=1,pp=5,slow=2,micmatching=2,clip2=tdeint(mode=2,type=3)) 
tdecimate(mode=2, rate=23.976)

#Resize
Spline64Resize(848, 480)

#Trimming 5000 frames randomly (from frame 2000 to frame 7000)
trim(2000, 7000)

parte2=last

#append the trimmed parts
part1++part2

#Color Matrix Conversion
ColorMatrix(mode="Rec.601->Rec.709", interlaced=false, threads=0, thrdmthd=0, opt=3)

#Clipping
Limiter(min_luma=16, max_luma=235, min_chroma=16, max_chroma=240)
In the script above I just trimmed the first 1000 frames for the first video and 5000 frames randomly for the second video.
AVSPmod will also help you edit and preview Avisynth scripts, so you can actually *see* what you are trimming.

Quote:
Thank you for your help FranceBB. You helped me a lot and probably other people who were watching this thread.
You're welcome.
Whenever I have a little bit of spare time at work, I always go to Doom9.
I took so much from this community, as Avisynth helped me so much back in 2004 and ever since 2013 I tried to give something back (that's why I love open source). ^^

Last edited by FranceBB; 23rd November 2018 at 06:51.
FranceBB is online now   Reply With Quote
Old 30th November 2018, 02:39   #15  |  Link
Blovesx
Registered User
 
Join Date: May 2015
Posts: 14
I'm back to ask for a few more things.

1. I have DVDs encoded as:
720x480 / 16:9
720x480 / 4:3

How should I do it to keep the 16:9 to be 16:9 and 4:3 to be 16:9? I will be encoding for PC usage.
So far I have tried the 16:9 video encoding using SAR 1:1 but then I got 3:2, SAR 16:9 got 2.667, SAR 40:33 got finally 16:9... but whatever I don't get it anyway.

If I use this 848x480 resize filter you told me to use I have from 720x480 / 16:9 again 16:9 somehow but this thing probably blurs the video because of resizing? I just love mathematics.
All I want to do is keep the video 720x480 / 16:9 so I can resize it to 1280x720p or 1080p. So probably I should tell x264 to use SAR 40:33 for 16:9 and for 4:3 SAR x ?

2. Do you know what's the difference here:
Code:
motion-adaptive cubic interpolation deinterlacing
motion-adaptive modified-ela deinterlacing
3. Can I move chapters from DVD to .mp4?

4. You've written few posts above about colours: is it i420 or yv12 I should use?

5. Could I ask you for PAL .avs settings if it's not top secret? Haha.

Thank you!

Last edited by Blovesx; 30th November 2018 at 04:44.
Blovesx is offline   Reply With Quote
Old 30th November 2018, 18:42   #16  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Royal Borough of Kensington & Chelsea, UK
Posts: 2,869
Quote:
1. I have DVDs encoded as:
720x480 / 16:9
720x480 / 4:3

All I want to do is keep the video 720x480 / 16:9 so I can resize it to 1280x720p or 1080p.
You are dealing with anamorphic contents, 720x480 flagged as 16:9 or 4:3.
If you wanna resize it to 16:9, just resize it to 848x480, if you wanna resize it to 4:3, just resize it to 640:480.

Quote:
If I use this 848x480 resize filter you told me to use I have from 720x480 / 16:9 again 16:9 somehow but this thing probably blurs the video because of resizing? I just love mathematics.
Yes, whenever you upscale a content, you introduce blur.
There are some upscaling kernels that are sharper than others, for instance Bilinear is kinda blurry, Bicubic is sharper than Bilinear but it's prone to introduce ringing, Lanczos is generally as sharp as Bicubic without introducing too much ringing.
What I generally use to upscale it's Spline, 'cause I find it very sharp and I like the idea behind it.
In order to get better results, you could also use NNEDI instead of a "simple" resizing kernel, but using NNEDI to do such a little upscale it's an overkill.

You said that you don't want to upscale and it's perfectly understandable if you don't wanna "waste" bitrate, however, you also said

Quote:
All I want to do is keep the video 720x480 / 16:9 so I can resize it to 1280x720p or 1080p
I don't get it.
If you leave the content as it is (720x480) and you just flag it as 16:9, then it's up to the player to upscale it to the full resolution of your monitor.
Because players have to render the result in real time, the vast majority of them use something simple like a "FastBilinear" which is very blurry or something crappy like PointResize (if you love mathematics, then you'll love the explanation behind the nearest neighbour and other resizing kernel and you'll probably understand why I prefer a Spline-based resizing kernel): http://avisynth.nl/index.php/Resampling
In other words, if you wanna deliver the content on PCs, then keep in mind that the majority of people will see it with a random player that will use a "simple" resizing algorithm, so you are better off upscaling it using NNEDI and Spline64 than to let them upscale it.

Anyway, if you wanna leave it as it is and just flag it to the correct aspect ratio:

NTSC 4:3 DAR = 8:9
NTSC 16:9 DAR = 32:27

Quote:
Could I ask you for PAL?
PAL 4:3 DAR = 16:15
PAL 16:9 DAR = 64:45

Quote:
Can I move chapters from DVD to .mp4?
I'm pretty sure that you can have chapters in mkv, but I'm not sure for mp4; perhaps there's a way to do it via MP4Box.

Quote:
You've written few posts above about colours: is it i420 or yv12 I should use?
yv12 is 4:2:0 planar in Avisynth.
i420 is the same but not in Avisynth.
Different terms, same meaning, I think.

Quote:
Could I ask you for PAL .avs settings?
It's pretty much the same, but without the "inverse telecine" part.
Just use Tdeint with the normal settings to deinterlace (it will produce a 25fps progressive file) and upscale to 1024x576.

Code:
tdeint(mode=2, order=-1, field=-1, mthreshL=6, mthreshC=6, map=0, type=2, debug=false, mtnmode=1, sharp=true, cthresh=6, blockx=16, blocky=16, chroma=true, MI=64, tryWeave=true, link=1, denoise=true, slow=2, opt=4)

Spline64Resize(1024, 576)
Cheers.

Last edited by FranceBB; 30th November 2018 at 18:44.
FranceBB is online now   Reply With Quote
Old 1st December 2018, 21:43   #17  |  Link
Blovesx
Registered User
 
Join Date: May 2015
Posts: 14
FranceBB, do you mean I should use the same TFM settings and these "tdeint" settings you gave me post above for PAL DVDs without this setting?
Code:
TDecimate(mode=2, rate=23.976)
Another question. I downloaded a file but with funny settings I think so, do you know what to do in case of this funny encoded .mp4 file with these framerate settings?
Code:
Frame rate mode : Variable 
Frame rate : 25.474 FPS 
Minimum frame rate : 14.985 FPS 
Maximum frame rate : 119.880 FPS 
Original frame rate : 29.970 (30000/1001) FPS
I don't know how to re-encode it to 23.996 properly without any stuttering and big damage to the encoding. I believe someone encoded NTSC DVD somehow that way but can something be done to fix it? Do you have special settings for these kind of encodes?

Another question for you or someone who's knowledgable with color format who can explain to me how is that and what color primaries were actually used in the attached photos? I don't really get it but when I play the one encoded by x264 (default settings) and with resizer (spline) in a VLC or any other player I can see the same colors but inside of Photoshop it's different? BT706 is just encoded as extra one. Is the one done by spline64 copying color primaries from original DVD keeping BT601 and ignoring x264 default color settings i420?

x264 (default settings)
http://oi66.tinypic.com/5k35ht.jpg

Spline64
http://oi66.tinypic.com/dotj09.jpg

BT706
http://oi63.tinypic.com/zmb67d.jpg

Last edited by Blovesx; 1st December 2018 at 22:19. Reason: Fixed link (spline64)
Blovesx is offline   Reply With Quote
Old 2nd December 2018, 07:09   #18  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 7,255
to put my two cents in,...

Quote:
Frame rate mode : Variable
Frame rate : 25.474 FPS
Minimum frame rate : 14.985 FPS
Maximum frame rate : 119.880 FPS
Original frame rate : 29.970 (30000/1001) FPS
So the container of the file reports that the input is vfr with a frame rate between 14.986 and 199.880, the stream itself is flagged as 29.97 and the average frame rate is 25.474 fps and you want to go to 23.976.
(Audio sync issues aside)
In case your source really in some parts requires 119.88 to appear fluid, you won't get to 23.976 without stuttering.
My first approach for this would be to try some things:
1. remux the content to mkv drop the time codes in the process wo see whether the content has just broken time codes or not. If the content really is cfr and not vfr things would be easier. (you might still not get to 23.976 without stuttering, in case you need the 29.97fps for fluidity)
2. look at the actual frame to see whether there a duplicates, ghosting etc. In case you got clean pictures and motion between each frame you probably won't get to 23.976 without suttering
3. play around with sRestore and similar filters to go for 23.976 and see how they handle the file
4. if none of the above provides a usable solution I would think about whether writing a full custom script is really worth the time and effort. (depending on the nature of the clip something like Yatta/Wobbly/... or a script like AnimeIVTC might also be helpful)

Quote:
copying color primaries from original DVD keeping BT601 and ignoring x264 default color settings i420?
Unless you got a RGB<>YUV conversion whether the content is BT/Rec.601 or BT/Rec.709 shouldn't matter, since the information isn't needed. (read: https://en.wikipedia.org/wiki/YUV)
So during normal DVD reeencoding where you stay the whole time in YUV 4:2:0 the only thing that is required is that the information is kept as a flag for the output (VUI) so the decoder of the player knows the right matrix when converting from YUV to RGB.
If the color between players/tools differ, it usually means that either the vui matrix information got dropped somewhere or simply got ignored.

Cu Selur
__________________
Hybrid here in the forum, homepage
Selur is offline   Reply With Quote
Old 2nd December 2018, 10:02   #19  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,821
Quote:
Originally Posted by Blovesx View Post
Another question for you or someone who's knowledgable with color format who can explain to me how is that and what color primaries were actually used in the attached photos? I don't really get it but when I play the one encoded by x264 (default settings) and with resizer (spline) in a VLC or any other player I can see the same colors but inside of Photoshop it's different? BT706 is just encoded as extra one. Is the one done by spline64 copying color primaries from original DVD keeping BT601 and ignoring x264 default color settings i420?
i420 and BT601/709 are different things. I420 is a pixel format. Often referred to as YV12, although they're slightly different. You almost never have to specify an input colorspace with x264 when encoding normal video such as DVDs.
http://avisynth.nl/index.php/I420

BT601/709 describes how the YUV colorspace is converted to RGB on playback. It has to be converted to RGB as all displays are RGB. Normally when you re-encode a video though, it's decoded as YUV, filtered as YUV and re-encoded as YUV (at least in Avisynth). There's no RGB conversion in the process.

BT601 is the method used for most standard definition to convert the YUV colorspace to RGB. BT709 is generally used for HD. They're slightly different and that's why you're sometimes seeing a slight color difference. Your x264 and Spline64 screenshots have slightly different colours, by the way.

As standard definition is normally BT601 (unless you're re-encoding a video someone else downscaled) you'd set the following for the x264 colour matrix option.

For PAL it's --colormatrix bt470bg
It's the same as BT601.

For NTSC it's --colormatrix smpte170m.

For HD it's --colormatrix bt709.

I think the -colormatrix option is the only one that really matters, but "colormatrix", "transfer characteristics" and "color primaries" have no effect on how the video is encoded. They only offer suggestions as to how it should be converted to RGB on playback.

When upscaling or downscaling, I try to stick with the same colorimetry rules (BT601 for SD and BT709 for HD). In order to do that, the colormatrix filter can be using to convert BT601 to BT709 when upscaling.

ColorMatrix(mode="Rec.601->Rec.709", clamp=0)

Then you'd specify --colormatrix bt709 for the x264 encoder.
When downscaling, you'd do it the other way around.

If you don't convert the colors when upscaling and downscaling, then you should specify the original colormatrix. Many players will read the info and display the video correctly. Some players might ignore it and just use BT601 for SD and BT709 for HD anyway, so personally I think converting the colors when upscaling/downscaling is a good idea.


For encoding VFR sources...
I'd try decoding while converting back to the original frame rate (I think the 119.880 FPS maximum rate is going to be some sort of anomaly in MediaInfo's interpretation of the frame rate). In theory, conversion to the original CFR while decoding will replace the duplicate frames that were dropped to make it variable, and from there you can often apply IVTC normally, as required.

FFVideoSource("D:/Video/mp4", fpsnum=3000, fpsden=1001)
TFM().TDecimate() # if required

LSmashVideoSource has the same options.

If that doesn't work and the output isn't smooth, you can extract the timecodes (or ffmpegsource has an option to write a timecodes file while while indexing) and you can give the timecodes to x264 and it'll encode in VFR mode (in which case you wouldn't convert to CFR while decoding). If x264 writes directly to MKV, the timecodes will be included in the output file and all you need to do is add the audio etc.
The x264 option is this (the timecodes file name can be anything):

--tcfile-in "D:\video timecodes.txt"

MeGUI's OneClick encoder does that sort of thing for you these days. I think it assumes MP4 and MKV sources will be VFR by default (although I don't actually use the OneClick encoder myself).

Last edited by hello_hello; 2nd December 2018 at 17:59.
hello_hello is offline   Reply With Quote
Old 3rd December 2018, 05:27   #20  |  Link
Blovesx
Registered User
 
Join Date: May 2015
Posts: 14
I'm back with some news (forgot to mention it was .mp4 file).

Here's what I did:
1. Since I had problems with opening the file in DGAVCIndex I demuxed the video out and I put .h264 inside of the program and run save project to take a look at the file.
Code:
Stream Type: AVC Elementary
Profile: High
Level: 4.1
Frame Size: 720x480
SAR: 32:27
Display Size: 853x480
Frame Rate: 29.970030 fps
Colorimetry: BT.601* [2]
Frame Structure: Frame
Frame Type: not yet
Coded Number: 22969
Playback Number: 22969
Frame Repeats: 0
Field Repeats: 0
Bitrate: 0.039
Bitrate (Avg): 1.520
Bitrate (Max): 5.110
Elapsed: 0:00:46
Remain: 0:00:00
FPS: 
Info: Finished!
Framerate looks exactly like the ones I have on my DVDs.
Not really sure how do you read this: BT.601* [2] but inside of MediaInfo all I see is info that the file is using YUV colorspace (nothing is mentioned that the color matrix is BT.601 or anything).

2. Encoded using .h264 from DGAVC (I don't know if you can use .dga to change framerate of file):
Code:
video = FFVideoSource("TRY_track1.h264", fpsnum=30000, fpsden=1001)
Only that. I'm very happy with the output. It's super fluid as it should be without ghosting, blending, banding, duplicates... now the most important question: How do I sync the audio now?

I tried converting using MediaCoder and ffms with set framerate to 29.97 and it worked like a charm. I have no idea what settings the program used so I hope you will tell me how to set .avs script and neroaac settings. I got only info in the log:
Code:
[12-03 02:59:16] Suspended for 1.3 secs to sync [AudioEncodeThread]
[12-03 02:59:18] Suspended for 1.8 secs to sync [AudioEncodeThread]
[12-03 02:59:19] Suspended for 1.8 secs to sync [AudioEncodeThread]
When I was looking into the log on google I found this thread where dev only said it's supposed to be like this: http://forum.mediacoderhq.com/viewtopic.php?t=13197


Okay, here's some replies to you Selur:
Code:
remux the content to mkv drop the time codes in the process wo see whether the content has just broken time codes or not
I don't know how you should read time codes so it's a black magic for me just a numbers (but I can see the video is going as it should every ~34 frames or whatever it is and the audio is also going in same numbers ~22).
Video: https://pastebin.com/A4SgJUMF
Audio: https://pastebin.com/qgiPEUuS (was too long, cut half of the file).

Code:
play around with sRestore and similar filters to go for 23.976 and see how they handle the file
Not tried yet but maybe I should just try the standard settings and see what happens now TFM().TDecimate() as hello_hello said or with different settings not defaults?

This is what I believe a video settings were before destroying the framerate (of course not same length):
Code:
Stream Type: MPEG2 Program
Profile: main@main
Frame Size: 720x480
Display Size: 720x480
Aspect Ratio: 16:9 [3]
Frame Rate: 29.970030 fps
Video Type: NTSC
Frame Type: Interlaced
Coding Type: P
Colorimetry: SMPTE 170M
Frame Structure: Frame
Field Order: Top
Coded Number: 30342
Playback Number: 2
Frame Repeats: 0
Field Repeats: 0
VOB ID: 1
Cell ID: 7
Bitrate: 
Bitrate (Avg): 
Bitrate (Max): 
Audio Stream: 80: AC3 2/0 192
Timestamp: 0:16:51
Elapsed: 0:00:16
Remain: FINISH
FPS: 
Info:
and last one considering colors:
Code:
If the color between players/tools differ, it usually means that either the vui matrix information got dropped somewhere or simply got ignored
~or I simply didn't encode with a code in .avs to say encoder about color matrix? I should add some line?


Some replies to hello_hello:
Code:
Your x264 and Spline64 screenshots have slightly different colours, by the way
Yeah, default x264 for x264 image and again default settings + resizing trough Spline64. That's it not sure why it's a bit different should I force some color matrix or something?

Code:
ColorMatrix(mode="Rec.601->Rec.709", clamp=0)
Then you'd specify --colormatrix bt709 for the x264 encoder
I got it. Just a personal question: do you prefer encoding DVDs with original color settings or full RGB is more popular for PC use? I'm not really using TV much or anything beside PC but does it matter nowadays what's the color primaries, is it TV range or PC or any x264 settings which won't allow to play encodes on TV? I know for sure I can't play High10 bit videos on my TV but everything else is playing fine. I wasn't even looking at if there is a difference in colors: DVD standards and RGB but everything is working.
Back to the topic FranceBB gave me this code I wasn't really looking into the plugins settings and what these means. How is it different from your simple Rec->Rec setting?
Code:
#ColorMatrix(mode="Rec.601->Rec.709", interlaced=false, threads=0, thrdmthd=0, opt=3)
and finally a last one:
Code:
If that doesn't work and the output isn't smooth, you can extract the timecodes (or ffmpegsource has an option to write a timecodes file while while indexing)
 and you can give the timecodes to x264 and it'll encode in VFR mode (in which case you wouldn't convert to CFR while decoding).
 If x264 writes directly to MKV, the timecodes will be included in the output file and all you need to do is add the audio etc.
That was just an option if the video settings wouldn't work and video wasn't smooth? I'm not really sure if I understand you. This --tcfile-in "x:\xxxx.txt" should be put in x264 encoder settings? What's the command to write in .avs script to get the file with timecodes trough ffms or can I aswell use timecodes taken from mkvtoolnix? Timecodes help with smoothing, settings the frames?

Phew, that's a lot of writing. Thanks for helping me out by the way guys!

Last edited by Blovesx; 3rd December 2018 at 05:37.
Blovesx is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:11.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.