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 Encoder GUIs

Reply
 
Thread Tools Search this Thread Display Modes
Old 29th December 2005, 01:13   #1  |  Link
berrinam
Registered User
 
berrinam's Avatar
 
Join Date: Apr 2005
Posts: 1,740
Automatic interlace detection

EDIT: Another new version (10th Jan) here

While this isn't actually relevant to MPEG-4 AVC, I'm posting this here because it seems relevant to some of the programs which reside in this subforum, like MeGUI, RealAnime and staxrip. If a mod thinks that this is the wrong forum, then please move it.

This post is to share my results with detection of content type (ie progressive, interlaced, film, or a hybrid of those). I would be pleased if you could test the program I've uploaded, and give feedback. I haven't been able to test much, as I have very few sources to work with.

Algorithm
The algorithm I'm using is a combination of what I could pick up of the AGK algorithm and what I worked out by myself. Given an avs script, my program does a selectrangeevery on it, so it doesn't have to analyse the whole video, and then adds code which is copied straight from AGK's avs scripts, which checks whether the frames are (a) moving; and (b) combed (using Decomb's IsCombed function). These results are written to a file called interlace.log, in the directory of the avs script.

My program analyses this file in 5-frame chunks (as len0x said he did. Five is chosen, because telecining is most commonly in a 5-frame cycle). It ignores the chunks in which not every frame is moving, and then declares the chunks in which there is no combing as progressive, and declares the chunks in which there are exactly two consecutive combed frames as telecined, and declares everything else as interlaced. At the end, it counts the number of each type of chunk, and compares the most common one with the second-most-common one. If
Code:
mostcommon > hybridthreshold * secondmostcommon
then the source is declared as wholly of the type of mostcommon. Otherwise, it is declared as a hybrid of the two more common ones.

GUI parameters
My program comes with two things that can be tweaked in the GUI: the hybrid threshold, and the selectrangeevery parameters for the avisynth script. I've explained the hybridthreshold briefly above, and the selectrangeevery parameters are there to control how much of the video is analysed. The length parameter should be kept as a multiple of 5, because the output file is analysed in 5-frame chunks.

Of course, my program is only intended to test the algorithm at this stage in time, and not for any practical purposes until the algorithm is either more reliable, or a better algorithm is found.

Last edited by berrinam; 10th January 2006 at 12:44.
berrinam is offline   Reply With Quote
Old 30th December 2005, 15:01   #2  |  Link
berrinam
Registered User
 
berrinam's Avatar
 
Join Date: Apr 2005
Posts: 1,740
I suspect I chose wrongly when posting this in the AVC forum. Could someone please move this to the AviSynth forum?
berrinam is offline   Reply With Quote
Old 30th December 2005, 16:06   #3  |  Link
charleski
Registered User
 
charleski's Avatar
 
Join Date: Jul 2004
Posts: 383
I'm so glad you're doing this - I was thinking of reverse-engineering AGK for MeGUI as well, but had been putting it off until the New Year. Now I don't need to bother .
charleski is offline   Reply With Quote
Old 30th December 2005, 21:06   #4  |  Link
Dark-Cracker
Registered User
 
Dark-Cracker's Avatar
 
Join Date: Feb 2002
Posts: 1,195
Perhaps could you ask Neuron2 if it kown some usefull tips to improve your algo.
__________________

AutoDub v1.8 : Divx3/4/5 & Xvid Video codec and .OGG/.MP3/.AC3/.WMA audio codec.
AutoRV10 v1.0 : Use RealVideo 10 Codec and support 2 Audio Streams and Subtitles.

Dark-Cracker is offline   Reply With Quote
Old 31st December 2005, 07:00   #5  |  Link
Guest
Guest
 
Join Date: Jan 2002
Posts: 21,901
tritical and scharfis_brain, too, should be consulted. Unfortunately I cannot even download the files until I return from vacation.
Guest is offline   Reply With Quote
Old 31st December 2005, 18:19   #6  |  Link
Dark-Cracker
Registered User
 
Dark-Cracker's Avatar
 
Join Date: Feb 2002
Posts: 1,195
i have try to work on such tool :

http://forum.doom9.org/showthread.php?s=&threadid=68024

and i should still have a few hybrid sample, i will try to find the time to test it once i come back in my house.

Bye and happy new year
__________________

AutoDub v1.8 : Divx3/4/5 & Xvid Video codec and .OGG/.MP3/.AC3/.WMA audio codec.
AutoRV10 v1.0 : Use RealVideo 10 Codec and support 2 Audio Streams and Subtitles.

Dark-Cracker is offline   Reply With Quote
Old 5th January 2006, 09:14   #7  |  Link
berrinam
Registered User
 
berrinam's Avatar
 
Join Date: Apr 2005
Posts: 1,740
Here's a new version.

New features
  1. Field order detection (there you go, Mug Funky )
  2. Updated thresholds
  3. An analysis % way of controlling the SelectRangeEvery parameters.

Ok, so the feature-list isn't very big. But it seems to be giving very similar results to AutoGK, and it also has a field order detection algorithm.

Getting my program
On rapidshare, you can get the
sources: http://rapidshare.de/files/10428446/...n-src.zip.html
binaries: http://rapidshare.de/files/10427282/...n-bin.zip.html

I have also attached them, and they will be downloadable from the end of this post, pending approval of a moderator.

Algorithm
The source detection algorithm remains (from memory) entirely the same as described in my first post.

The field order algorithm is a pretty intuitive algorithm I came up with, which works the same way as humans do it: try separating fields with both assumetff and assumebff, and see which one is jerkier (in more concerete terms, work out which one gives more motion, as defined by Y/U/VDifferenceFromPrevious). This algorithm seems to work very well. I've put a threshold in for saying that the field order changes (ie if the amount of the wrong field order detected is more than threshold, declare it as a changing field order). Once again, from lack of sources, I have not really had any way of tuning this threshold, so I pulled the value from thin air.

My testing results
For pure sources, the results are accurate. For hybrid sources, I believe it is just a matter of finding the thresholds.

I've done some testing of my results against AutoGK's results. With the current default thresholds, my results seem quite similar to AutoGK's results.

AutoGK is different, because
  1. It seems to take into account the input framerate, whereas my program only looks at the statistics output by AviSynth.
  2. I call my clip a hybrid if the ratio between the first and second most common combing types is less than hybrid threshold. AutoGK calls it hybrid if the ratio between telecine and interlaced patterns is less than some threshold. I'm not sure how much difference this makes.

I presume that (a) taking into account the framerate, and (b) taking into account what DGIndex reports as the film % (assuming mpeg2 input) could make this algorithm more accurate, but at the moment, I am trying to see how much can be done without this extra information.

What you can do to help me (please do )
  1. Download my program
  2. Run it on your sources
  3. Tell me if it works.

I would especially like people to run it on hybrid clips, because these are the most problematic.
Attached Files
File Type: zip interlace_detection-bin.zip (6.9 KB, 443 views)
File Type: zip interlace_detection-src.zip (10.0 KB, 288 views)

Last edited by berrinam; 5th January 2006 at 09:17.
berrinam is offline   Reply With Quote
Old 5th January 2006, 09:20   #8  |  Link
berrinam
Registered User
 
berrinam's Avatar
 
Join Date: Apr 2005
Posts: 1,740
Quote:
Originally Posted by Dark-Cracker
I had a look through that thread, but it seems to have ended rather abruptly. Wilbert said on the AviSynth forum that you implemented that in AutoRV. Is this true, and how good are your results (if you don't mind sharing, of course)?

Quote:
and i should still have a few hybrid sample, i will try to find the time to test it once i come back in my house.
Are you still offering to do this?
berrinam is offline   Reply With Quote
Old 5th January 2006, 11:35   #9  |  Link
stax76
Registered User
 
stax76's Avatar
 
Join Date: Jun 2002
Location: On thin ice
Posts: 6,837
Great work, for average Joe deinterlacing is far to complicated. Besides encoding frondends it makes also sense for any AviSynth user having a standalone application. Instead of mplayer maybe the avifile API could be used, I would be willing to contribute such things, I have a very fast .NET avifile wrapper that might be easy to use for this.
stax76 is offline   Reply With Quote
Old 5th January 2006, 11:46   #10  |  Link
berrinam
Registered User
 
berrinam's Avatar
 
Join Date: Apr 2005
Posts: 1,740
@stax: No problem, I would love it if you contributed. You might find the code disorganised, however -- I wasn't expecting anyone else to work on it.

@edit: The code is under GPL.

Last edited by berrinam; 5th January 2006 at 11:49.
berrinam is offline   Reply With Quote
Old 6th January 2006, 12:21   #11  |  Link
charleski
Registered User
 
charleski's Avatar
 
Join Date: Jul 2004
Posts: 383
Using the latest version, it crashes with the error
Could not find file 'C:\MyVideos\interlace.log'
Code:
************** Exception Text **************
System.IO.FileNotFoundException: Could not find file 'C:\MyVideos\interlace.log'.
File name: 'C:\MyVideos\interlace.log'
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
   at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize)
   at System.IO.StreamReader..ctor(String path)
   at WindowsApplication3.Form1.analyse(String filename, String inFileName)
   at WindowsApplication3.Form1.analyseSourceButton_Click(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
charleski is offline   Reply With Quote
Old 6th January 2006, 12:43   #12  |  Link
berrinam
Registered User
 
berrinam's Avatar
 
Join Date: Apr 2005
Posts: 1,740
Well, the error is pretty simple. Anyway, AviSynth is supposed to be generating that file, so I would guess that the problem is that, for some reason, AviSynth is not running properly. Can you see what happens when you try loading this script in VDub?

EDIT: Just in case it isn't clear, you need to specify where mplayer is (and it needs to be able to play avs, which means a more recent build than about half a year ago), and you need Decomb.dll in your AviSynth plugins folder. Also, just for safety's sake, make sure your script ends in a newline. I think that's all you need.

Looking at it in VDub should hopefully solve it, but I did get one problem which VDub managed fine, but mplayer crashed on, which had problems.

Last edited by berrinam; 6th January 2006 at 13:17.
berrinam is offline   Reply With Quote
Old 6th January 2006, 18:09   #13  |  Link
stax76
Registered User
 
stax76's Avatar
 
Join Date: Jun 2002
Location: On thin ice
Posts: 6,837
I've removed the mplayer dependency: http://rapidshare.de/files/10522699/...n-src.zip.html
stax76 is offline   Reply With Quote
Old 10th January 2006, 12:43   #14  |  Link
berrinam
Registered User
 
berrinam's Avatar
 
Join Date: Apr 2005
Posts: 1,740
Thanks to stax for providing a version which uses AVIFIle.

Ok, here is what I hope could be a final version before it is integrated into MeGUI (and staxrip, if stax wants to take the time to wade through my code again). It does better field order detection, it recommends a script, and it adds 'portion management', which is ideally for progressive content with interlaced sections in it, like the credits or something, in which case it would only deinterlace the credits. I've put a fair bit of work into that, and I'm interested in the results of that, because it often kicked in when it shouldn't.

I'm too lazy at this point in time to write a summary of the algorithm or any of the other sections I did before, so here are the links:

Bins on rapidshare (required .NET 2.0): http://rapidshare.de/files/10771821/...n_bin.zip.html
Sources on rapidshare: http://rapidshare.de/files/10771626/...n_src.zip.html

I've once again attached the files here as well.
Attached Files
File Type: zip source-detection_bin.zip (13.1 KB, 1013 views)
File Type: zip source-detection_src.zip (18.4 KB, 471 views)
berrinam is offline   Reply With Quote
Old 11th January 2006, 23:21   #15  |  Link
berrinam
Registered User
 
berrinam's Avatar
 
Join Date: Apr 2005
Posts: 1,740
@stax: Do you mind if I use the extra AVIFile code you added in MeGUI?
berrinam is offline   Reply With Quote
Old 11th January 2006, 23:53   #16  |  Link
stax76
Registered User
 
stax76's Avatar
 
Join Date: Jun 2002
Location: On thin ice
Posts: 6,837
No but since you port the entire thing to MeGUI maybe it's better to use the code that is already there because it's probably derived from the same source and identical. If you need very fast avifile drawing btw. check out my source code.

Dimzon mentioned there is a lot duplicated code and I noticed this as well e.g. each and every codec dialog has the same zones code, I think that's really not good and belongs in a zones user control.

http://c2.com/cgi/wiki?DontRepeatYourself
stax76 is offline   Reply With Quote
Old 15th January 2006, 11:44   #17  |  Link
stax76
Registered User
 
stax76's Avatar
 
Join Date: Jun 2002
Location: On thin ice
Posts: 6,837
Quote:
Ok, here is what I hope could be a final version before it is integrated into MeGUI (and staxrip, if stax wants to take the time to wade through my code again).
Thanks for offerring me using the code, of course I'm much interested in having such a feature available in StaxRip. Maybe I can help you as well somehow with something I did for StaxRip or AVSEdit?
stax76 is offline   Reply With Quote
Old 16th January 2006, 04:12   #18  |  Link
berrinam
Registered User
 
berrinam's Avatar
 
Join Date: Apr 2005
Posts: 1,740
Quote:
Originally Posted by stax
Thanks for offerring me using the code, of course I'm much interested in having such a feature available in StaxRip. Maybe I can help you as well somehow with something I did for StaxRip or AVSEdit?
Well, of course, as all of these projects are GPL'd anyone could use the code without asking if they wanted to, but it's nice to be polite. Also, I want to make sure that the algorithm doesn't disappear even if MeGUI does.

If you plan to add this to StaxRip, then I would actually recommend using the MeGUI code. It went through considerable alterations when being put into MeGUI, which should make it interface better with a program.

As regards to your offer, nothing springs to mind at the moment, but thanks anyway. I'll keep it in mind in case I want anything in the future
berrinam is offline   Reply With Quote
Old 16th January 2006, 11:40   #19  |  Link
stax76
Registered User
 
stax76's Avatar
 
Join Date: Jun 2002
Location: On thin ice
Posts: 6,837
Thanks, since you've helped me twice maybe I can spot a bug, sent a patch or share some experience here and there for MeGUI as well. Is there a source release or do I have to make a anonymous cvs checkout?
stax76 is offline   Reply With Quote
Old 16th January 2006, 12:19   #20  |  Link
berrinam
Registered User
 
berrinam's Avatar
 
Join Date: Apr 2005
Posts: 1,740
Sharktooth puts the sources up here, but they tend to become obsolete quite quickly. CVS is your best option, although SF's CVS is a bit unreliable.

Sharktooth's sources: http://files.x264.nl/?dir=./Sharktooth/megui/Sources
berrinam 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 13:58.


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