View Full Version : Any way to improve footage deinterlaced using a "blend" deinterlacer?
LilWiz
16th February 2016, 11:33
Hey all, I'm a beginner with avisynth who recently posted to the forum to figure out how to use QTGMC. It was extremely helpful so I might try again.
I have a clip here that seems to have been deinterlaced by blending fields.
https://mega.nz/#!OQdFlZjR!rEsxxWPSTm8W-I5w6aNPE5mrWE5ETGidu0Scc9CzNM0
Is there any way I can make the footage more sharp? Or is it pretty much unrecoverable? I tried searching around for "unblenders", but I think all I can see is that used for interlaced footage. Not sure though.
---------------------------------------------------------
Furthermore, is this footage (from a different source) completely jerky and unwatchable? Or is there some way I can make it smooth 50fps using QTGMC like I feel it should be? To be honest I think the original file is ruined, but I'm not completely sure. Here it is:
https://mega.nz/#!TR9jWCYB!rbyVD_dmF-921xqpJyayRksoAtCgAcGzEkGnnyc4N5I
Thanks for any help that you can give!
Sharc
16th February 2016, 12:10
Your first file can't be fixed, I think. All frames and fields are blended.
Your second file is perfect it seems, just interlaced, tff.
Deinterlace it, e.g.:
yadif(mode=1,order=1) #or a bobber of your choice
When it played jerky it is probably because you reversed the field order (bottom field first instead of top field first)
LilWiz
17th February 2016, 00:09
Thanks for the reply Sharc. When saving as an avi through VirtualDub, I'm getting a shaky result. I've uploaded it here:
https://mega.nz/#!HINSiA5R!L7zQGXFVqx0yZNcsnb7LOHRrP6_qY6vN1lrEf9bjbGY
Here's my source code:
LWLibavVideoSource("x:\Cracovia - Górnik Z 2-0.mkv")
a = LWLibavAudioSource("x:\Cracovia - Górnik Z 2-0.mkv")
AssumeTFF()
QTGMC(Preset="Slow")
AudioDub(last, a)
I'm thinking that my decoder is the problem. Normally I deinterlace ts files with this code, and it works perfectly. mkv files might be an issue. Am I correct in my thinking?
LilWiz
17th February 2016, 00:09
Thanks for the info about the first clip guys. I'll forget about that if I can get the second clip smooth.
LilWiz
17th February 2016, 02:52
Sorry rean, I'm not sure if I'm following you. What changes to I need to make to my code? Am I changing the position of the AudioDub line in the code?
StainlessS
17th February 2016, 03:10
LilWiz, Yes, I think he means place it (AudioDub) somewhere between LWLibavAudioSource and QTGMC.
LilWiz
17th February 2016, 03:28
Thanks for the confirmation. Unfortunately, this hasn't changed anything, the footage continues to jerk around between frames.
I still believe the problem is the video decoder I'm using, because playback in vlc is decent. I tried FfmpegSource but it wasn't working for me.
StainlessS
17th February 2016, 03:40
I rarely use anything other than DGIndex(Mpeg2Source) or AviSource, any other clips I usually convert to AVI with this.
Whatever.bat
setlocal
REM Where to Find ffmpeg
set FFMPEG="C:\BIN\ffmpeg.exe"
REM Where to get input file, No terminating Backslash, "." = current directory (ie same as dir .bat file)
set INDIR="."
REM Where to place output file, No terminating Backslash. "." would be same as .bat file
set OUTDIR="D:
FOR %%A IN (*.264 *.vob *.wmv *.mpg *.m2v *.avi *.flv *.mov *.mp4 *.m4v *.RAM *.RM *.mkv *.TS *.y4m *.yuv *.webm) DO (
%FFMPEG% -i "%INDIR%\%%A" -vcodec utvideo -acodec pcm_s16le "%OUTDIR%\%%~nxA.AVI"
)
Pause
Never failed yet.
EDIT: As supplied above, needs Ut_Video codec.
LilWiz
17th February 2016, 07:33
I think converting to an avi seems like a good option, thanks StainlesS. Unfortunately I'm not following how to effectively use the bat file. How do I choose which clip to convert (do I just put the name at the end of the clip directory? doesn't seem to be working)? Am I supposed to do something in the terminal? I've changed the directories to what I want but I'm not really sure what I'm doing.
Sorry for being so clueless, I've never worked with .bat files
Sharc
17th February 2016, 09:09
LilWiz
Your uploaded .avi is definitely crap. Apparently it has been encoded with XviD or DivX, and the field order got completely messed up. I don't recommend to stick to these outdated encoders, unless you have a very specific reason.
Why don't you use a proven GUI for your encode to start with? For example, I threw your source to HandBrake (there are other fine GUIs of course), set the deinterlacer in the filter tab to "Bob" and got a perfect 50fps .mkv or .mp4 output file with audio and video in sync.
Once you are more familiar with scripts you could still take the "manual" route. Just a suggestion.
LilWiz
17th February 2016, 13:08
I do use DivX, but when viewing the mkv file in VirtualDub and going through the output file frame by frame, the video is still jerky... this is before I've selected DivX as my chosen encoder in the 'Compression...' menu or anything. This is why I thought the problem was the decoder I'm using.
Handbrake gives a good result, so I'm going to stick with that if I can't get this Avisynth script working. Thanks for the suggestion.
I tried using the FFmpegSource decoder. I think there's a slight improvement? But still jerky.
Edit: Handbrake also drops 1/4 of frames, unless this was inherent in the source file
Sharc
17th February 2016, 15:51
Ok. So let's follow the "manual" route with a script.
I'll post what worked well here. I got a 50fps bobbed deinterlaced file (even with QTGMC) which plays smooth and has no missing frames. Stay tuned ....
..... Here we go:
1. Rename your .mkv file, avoiding any special characters (e.g. name it cracovia.mkv). This is just a precaution.
2. Download and install MKVToolNix
3. Demux the cracovia.mkv using for example MKVExtractGUI2.exe (you can download it from the internet and put it into the MKVToolNix folder).
You should now get 2 files: cracovia_track1_und.h264 (the video) and cracovia_track2_pol.mp3 (the audio)
4. Copy following into a text editor and save it as cracovia.avs (the script):
DirectShowSource("C:\....path.....\cracovia.mkv",audio=false)
AssumeFrameBased()
ConvertToYV12(interlaced=true)
AssumeTFF()
QTGMC(preset="fast") #try another bobber if QTGMC should fail, e.g. tdeint(mode=1,order=1)
Spline16Resize(1280,720) #for standards compliance; you may want to skip this downscaling, but you don't loose anything by downscaling from TV capture quality
AssumeFPS(50)
5. Copy following into a text editor and save it as cracovia.bat
"C:\ ...path to ...\x264.exe" --crf 20 --preset medium --bluray-compat --vbv-maxrate 40000 --vbv-bufsize 30000 --open-gop --sar 1:1 --output "cracovia.264" "cracovia.avs"
6. Start the encoding by selecting the cracovia.bat file and pressing the Enter key on the keyboard. Your encoding should start. Be patient .....
7. After the encoding is done, remux the encoded cracovia.264 with the cracovia_track2_pol.mp3 using mkvtoolnix-gui.exe which is in the MKVToolNix folder.
(You may convert the .mp3 audi to AAC or .ac3 before muxing, if you like)
Good luck! It reads more complicated than it is.
Edit:
You can download the encoded file from here and check if it plays correctly on your infrastructure:
http://www.mediafire.com/watch/v6o1ml9ogoea92i/cracovia_x264_%281%29.mkv
StainlessS
17th February 2016, 17:39
How do I choose which clip to convert
The bat file will process all files in INDIR that match the file extensions, as supplied, this lot
*.264 *.vob *.wmv *.mpg *.m2v *.avi *.flv *.mov *.mp4 *.m4v *.RAM *.RM *.mkv *.TS *.y4m *.yuv *.webm
You could remove whatever extensions you dont use or probably add others (if supported by ffmpeg, ie most).
EDIT: Bat will not drill down into deeper INDIR directories.
Audio produced in AVI will be 16 bit PCM.
Sharc
18th February 2016, 11:34
Interestingly and surprisingly I found DirectShowSource to be the only source filter which read this file sequentially correct. FFMpegSource and LSMASHVideoSource both failed (jerky sequence) or even crashed for some reason.
Inspecting the stream I found some unusual parameters, like:
- Resolution: 1920x1084
(I would have expected 1920x1080 or 1920x1088)
- Aspect Ratio: 480x271 (1:1)
(I would have expected 16x9 (1:1))
- There seem to be some inconsistencies with the frame rate as well, like 25.000 (declared) vs. 25.038 (real) or 30fps (file info, header?).
Perhaps this irritates the decoders/encoders trying to apply some smart frame rate conversion or whatever. :confused:
Anyway, the method / script which I posted earlier produced a perfect stream ......
(I didn't try StainlessS .avi conversion script though)
poisondeathray
18th February 2016, 16:18
Yes, ffms2 and lsmash seem to have problems as a source filter, but it just seems like a bad mux . If you re-wrap it with ffmpeg into a .ts or use tsmuxer to re-wrap all the frames are there, in proper order when you compare to something like dgsource on the elementary stream . (using tsmuxer gives the correct framerate, but you might have to use assumefps() when using lsmash on a ffmpeg re-wrapped file . lsmash /ffms2 occasionally interpret the wrong fps which you can use assumefps to "fix" - as long as the correct frames are there)
LilWiz
19th February 2016, 00:26
Ok. So let's follow the "manual" route with a script.
I'll post what worked well here. I got a 50fps bobbed deinterlaced file (even with QTGMC) which plays smooth and has no missing frames. Stay tuned ....
..... Here we go:
1. Rename your .mkv file, avoiding any special characters (e.g. name it cracovia.mkv). This is just a precaution.
2. Download and install MKVToolNix
3. Demux the cracovia.mkv using for example MKVExtractGUI2.exe (you can download it from the internet and put it into the MKVToolNix folder).
You should now get 2 files: cracovia_track1_und.h264 (the video) and cracovia_track2_pol.mp3 (the audio)
4. Copy following into a text editor and save it as cracovia.avs (the script):
DirectShowSource("C:\....path.....\cracovia.mkv",audio=false)
AssumeFrameBased()
ConvertToYV12(interlaced=true)
AssumeTFF()
QTGMC(preset="fast") #try another bobber if QTGMC should fail, e.g. tdeint(mode=1,order=1)
Spline16Resize(1280,720) #for standards compliance; you may want to skip this downscaling, but you don't loose anything by downscaling from TV capture quality
AssumeFPS(50)
5. Copy following into a text editor and save it as cracovia.bat
"C:\ ...path to ...\x264.exe" --crf 20 --preset medium --bluray-compat --vbv-maxrate 40000 --vbv-bufsize 30000 --open-gop --sar 1:1 --output "cracovia.264" "cracovia.avs"
6. Start the encoding by selecting the cracovia.bat file and pressing the Enter key on the keyboard. Your encoding should start. Be patient .....
7. After the encoding is done, remux the encoded cracovia.264 with the cracovia_track2_pol.mp3 using mkvtoolnix-gui.exe which is in the MKVToolNix folder.
(You may convert the .mp3 audi to AAC or .ac3 before muxing, if you like)
Good luck! It reads more complicated than it is.
Edit:
You can download the encoded file from here and check if it plays correctly on your infrastructure:
http://www.mediafire.com/watch/v6o1ml9ogoea92i/cracovia_x264_%281%29.mkv
Thanks for the step by step instructions, Sharc. Unfortunately, all it managed was "cracovia.264" to be created in the .bat file directory, and it is an empty file (0Kb). No error messages or anything else that I can report.
I'm currently downloading your version of the file, thanks for uploading that. I'm really annoyed with myself that I haven' tbeen able to figure this out, even with all the help. Not sure what to do now.
Why do I need a .bat file? Why can't I just use an .avs file and VirtualDub? And why isn't DirectShowSource working if I try to load the .mkv file with it? VirtualDub tells me it could not open as video or audio. Is this because the audio is included?
DirectShowSource("C:\Users\Lachlan\Documents\Goals\2016\Original\Cracovia.mkv")
AssumeTFF()
QTGMC(preset="fast")
AssumeFPS(50)
EDIT: Your file looks nice. Thanks for uploading that. I'll use that if I can't manage to get this done myself.
LilWiz
19th February 2016, 00:28
The bat file will process all files in INDIR that match the file extensions, as supplied, this lot
*.264 *.vob *.wmv *.mpg *.m2v *.avi *.flv *.mov *.mp4 *.m4v *.RAM *.RM *.mkv *.TS *.y4m *.yuv *.webm
You could remove whatever extensions you dont use or probably add others (if supported by ffmpeg, ie most).
EDIT: Bat will not drill down into deeper INDIR directories.
Audio produced in AVI will be 16 bit PCM.
I attempted to do this yesterday.. nothing happened, so I feel like I formatted the .bat file incorrectly or something. Just was not working for me.
StainlessS
19th February 2016, 00:34
Post what you edited to.
Mobile:
Edit: you have to point it at ffmpeg.exe on your system, perhaps as part of megui
Or separate install.
Edit, on second thoughts, tell me where ffmpeg is and where in and out dirs should be, and I'll post mod
LilWiz
19th February 2016, 00:51
Post what you edited to.
Mobile:
setlocal
REM Where to Find ffmpeg
set FFMPEG="C:\Program Files\...\ffmpeg.exe"
REM Where to get input file, No terminating Backslash, "." = current directory (ie same as dir .bat file)
set INDIR="C:\Users\...\Original\New folder"
REM Where to place output file, No terminating Backslash. "." would be same as .bat file
set OUTDIR="C:\Users\...\Original"
FOR %%A IN (*.264 *.vob *.wmv *.mpg *.m2v *.avi *.flv *.mov *.mp4 *.m4v *.RAM *.RM *.mkv *.TS *.y4m *.yuv *.webm) DO (
%FFMPEG% -i "%INDIR%\%%A" -vcodec utvideo -acodec pcm_s16le "%OUTDIR%\%%~nxA.AVI"
)
Pause
Gives me this in cmd
C:\Users\...>setlocal
C:\Users\...>REM Where to Find ffmpeg
C:\Users\...>set FFMPEG="C:\Program Files\...\ffmpeg.exe"
C:\Users\...>REM Where to get input file, No termina
ting Backslash, "." = current directory (ie same as dir .bat file)
C:\Users\...>set INDIR="C:\Users\...\Original\New folder"
C:\Users\...>REM Where to place output file, No term
inating Backslash. "." would be same as .bat file
C:\Users\...>set OUTDIR="C:\Users\...\Original"
C:\Users\...>FOR %A IN (*.264 *.vob *.wmv *.mpg *.m2
v *.avi *.flv *.mov *.mp4 *.m4v *.RAM *.RM *.mkv *.TS *.y4m *.yuv *.webm) DO ("C
:\Program Files\...\ffmpeg.exe" -i ""C:\Users\...\Original\New folder"\%A" -vcodec utvideo -acodec pcm_s16le ""C:\Users
\...\Original"\%~nxA.AVI" )
C:\Users\...>Pause
Press any key to continue . . .
And nothing happens after I press a key. Periods in file directories are inserted by me.
StainlessS
19th February 2016, 01:09
"...* don't do it, you need to give FULL path.
LilWiz
19th February 2016, 01:59
I didn't really want to give out the internals of my computer, but whatever
setlocal
REM Where to Find ffmpeg
set FFMPEG="C:\Program Files\MediaCoder\codecs64\ffmpeg.exe"
REM Where to get input file, No terminating Backslash, "." = current directory (ie same as dir .bat file)
set INDIR="C:\Users\Lachlan\Documents\Goals\2016\Original\New folder"
REM Where to place output file, No terminating Backslash. "." would be same as .bat file
set OUTDIR="C:\Users\Lachlan\Documents\Goals\2016\Original"
FOR %%A IN (*.264 *.vob *.wmv *.mpg *.m2v *.avi *.flv *.mov *.mp4 *.m4v *.RAM *.RM *.mkv *.TS *.y4m *.yuv *.webm) DO (
%FFMPEG% -i "%INDIR%\%%A" -vcodec utvideo -acodec pcm_s16le "%OUTDIR%\%%~nxA.AVI"
)
Pause
C:\Users\Lachlan\Documents\Editing stuff>setlocal
C:\Users\Lachlan\Documents\Editing stuff>REM Where to Find ffmpeg
C:\Users\Lachlan\Documents\Editing stuff>set FFMPEG="C:\Program Files\MediaCoder
\codecs64\ffmpeg.exe"
C:\Users\Lachlan\Documents\Editing stuff>REM Where to get input file, No termina
ting Backslash, "." = current directory (ie same as dir .bat file)
C:\Users\Lachlan\Documents\Editing stuff>set INDIR="C:\Users\Lachlan\Documents\G
oals\2016\Original\New folder"
C:\Users\Lachlan\Documents\Editing stuff>REM Where to place output file, No term
inating Backslash. "." would be same as .bat file
C:\Users\Lachlan\Documents\Editing stuff>set OUTDIR="C:\Users\Lachlan\Documents\
Goals\2016\Original"
C:\Users\Lachlan\Documents\Editing stuff>FOR %A IN (*.264 *.vob *.wmv *.mpg *.m2
v *.avi *.flv *.mov *.mp4 *.m4v *.RAM *.RM *.mkv *.TS *.y4m *.yuv *.webm) DO ("C
:\Program Files\MediaCoder\codecs64\ffmpeg.exe" -i ""C:\Users\Lachlan\Documents\
Goals\2016\Original\New folder"\%A" -vcodec utvideo -acodec pcm_s16le ""C:\Users
\Lachlan\Documents\Goals\2016\Original"\%~nxA.AVI" )
C:\Users\Lachlan\Documents\Editing stuff>Pause
Press any key to continue . . .
StainlessS
19th February 2016, 02:02
Do you do got, or dont got, input and output directories back to front, ie
C:\Users\...>set INDIR="C:\Users\...\Original\New folder"
C:\Users\...>set OUTDIR="C:\Users\...\Original"
ie, your indir is newfolder and your outdir is original folder, ?
EDIT: INDIR is where your input files should live, that is existing files, OUTDIR is where converted files will be sent.
If wrong way around, then you will be trying to convert an empty directory of source files.
LilWiz
19th February 2016, 03:00
Nope, the .mkv file ready to be converted is in "New Folder", the 'INDIR'.
StainlessS
19th February 2016, 03:13
I got no idea what is wrong, and about to go to bed.
Suggest copy bat file somewhere, use "." as INDIR with source files in same dir as bat, and set OUTDIR wherever you wish,
and retry, good night, good luck. (after thought, stick a few small video files in with your mkv, just to see what happens, AVI MPG or whatever).
EDIT: Try output to a drive root eg "D:" if you have access.
LilWiz
19th February 2016, 03:48
Thanks for all the help to this point. I moved the .bat file to the source file location, changed the .bat file accordingly. It worked, so I got a video file, but when deinterlacing through avisynth, I noticed it skipped a frame in around 1/8, and also went back a frame 1/8 frames.
I can't tell if the problem is with my Avisynth script or occurs before, during conversion, because I'm struggling to view the converted file in vlc. It plays slowly and vlc can't deinterlace it properly.
However, in VirtualDub, when inspecting frame by frame, the footage looks better than how it did on my first attempt, clear frames, but just those skipping issues.
Avisynth script for converted avi file is below.
AviSource("C:\Users\Lachlan\Documents\Goals\2016\Original\abc.mkv.avi")
AssumeTFF()
QTGMC(preset="slow")
AssumeFPS(50)
poisondeathray
19th February 2016, 05:06
I don't know if you missed my post but you can't use ffmpeg to decode as-is , it will have the same problems as ffms2 and lsmash - they all use the same code base with libav. It appears to be a problem with muxing in the original sample and misordered timestamps. The solution is to re-wrap it. Easy way with a GUI is tsmuxer to put it into a transport stream, but you can even use ffmpeg. Then use lsmash on that transport stream as you normally do. This procedure matches the output from dgsource on the elementary stream which has no issues. Directshow does work for me too, but it is inconsistent and might not work on your setup (it depends on which directshow splitter and decoder has higher merit on your system), and temporal filters like QTGMC can sometimes have issues with DSS
LilWiz
19th February 2016, 05:55
I don't know if you missed my post but you can't use ffmpeg to decode as-is , it will have the same problems as ffms2 and lsmash - they all use the same code base with libav. It appears to be a problem with muxing in the original sample and misordered timestamps. The solution is to re-wrap it. Easy way with a GUI is tsmuxer to put it into a transport stream, but you can even use ffmpeg. Then use lsmash on that transport stream as you normally do. This procedure matches the output from dgsource on the elementary stream which has no issues. Directshow does work for me too, but it is inconsistent and might not work on your setup (it depends on which directshow splitter and decoder has higher merit on your system), and temporal filters like QTGMC can sometimes have issues with DSS
Whoops, I did miss your post, apologies.
VirtualDub is currently processing the video, but WOW, this definitely seems like it's going to work. Extremely simple too. From my initial frame by frame check in VirtualDub, it looks perfect. Thank you very much poisondeathray, and also to all others that helped! This forum is fantastic.
I'll reply again in this thread if any more problems regarding this arise.
Sharc
19th February 2016, 09:11
......Why do I need a .bat file? Why can't I just use an .avs file and VirtualDub?....
You can load and play the .avs script (including the audio) in VirtualDub (1.10.4). But keep in mind that the playback will be terribly slow and choppy due to QTGMC using a lot of CPU power. You will never get a real-time playback.
Also try to load the script in any other media player like MPC-HC. It should work as well, but also choppy. It's useful for testing the script, but not for real-time playback.
Why the .bat file?
It re-encodes your source video (cracovia.mkv) based on the instructions in the .avs script and produces a new video file (cracovia.264) which can finally be re-muxed with the original audio. The result is a file (same which I uploaded) which plays real-time and smooth on almost any HW or SW player.
Sharc
19th February 2016, 10:21
Yes, ffms2 and lsmash seem to have problems as a source filter, but it just seems like a bad mux . If you re-wrap it with ffmpeg into a .ts or use tsmuxer to re-wrap all the frames are there, in proper order when you compare to something like dgsource on the elementary stream . (using tsmuxer gives the correct framerate, but you might have to use assumefps() when using lsmash on a ffmpeg re-wrapped file . lsmash /ffms2 occasionally interpret the wrong fps which you can use assumefps to "fix" - as long as the correct frames are there)
Hmmm.... I tried your proposal of demuxing+remuxing with tsMuxeR and mkvmerge, but still no luck with ffms2 when separating fields. Fields are still out of order or otherwise messy. "Best" result is with seekmode=1: 3 pictures forward, 1 picture backward, 3 pictures forward, 1 picture backward .....
The only source filter which works here with this file is .... ugghhh ... DirectShowSource :eek:
StainlessS
19th February 2016, 13:31
Whoops, I did miss your post, apologies.
+1 for that, guess I missed it too, Cheers PDR. :)
poisondeathray
19th February 2016, 16:37
Hmmm.... I tried your proposal of demuxing+remuxing with tsMuxeR and mkvmerge, but still no luck with ffms2 when separating fields. Fields are still out of order or otherwise messy. "Best" result is with seekmode=1: 3 pictures forward, 1 picture backward, 3 pictures forward, 1 picture backward .....
The only source filter which works here with this file is .... ugghhh ... DirectShowSource :eek:
lsmash
certain ffms2 builds have bugs with transport streams (still)
Sharc
19th February 2016, 18:40
LSMASHVideoSource [Fatal]: Failed to read an input file
LWLibavVideoSource: ok
:confused:
Anyway, let it be good as long as DirectShowSource works here .....
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.