VideoHelp Forum
+ Reply to Thread
Results 1 to 3 of 3
Thread
  1. Member vhelp's Avatar
    Join Date
    Mar 2001
    Location
    New York
    Search Comp PM
    Hi, I would like to know how scene detection is done. I'm sure there are tools floating around that already do this, but I want to write my own, education purposes, etc.

    So, I want to write my own version as a command line tool and write the results to a text file and then load that into another app that I'm working on. Is it too difficult ?

    I already have an avi file reader. I just need the logic that analyzes the frame(s) and writes the frame numbers: 00001, 00010, 00105, 00200, ... and so on.

    Also, I would be happy to post that cli app once completed.

    My language is Pascal (Delphi) but I may be able to read some light c/c++ if it is straight-forward or I could ask questions for any c/c++ speaking people.

    Thank you in advance.
    Quote Quote  
  2. There are lots of posts in the AVISynth section of doom9.org. Check out scene detection done by StainlessS.

    I have almost a dozen different scene detection scripts, many of which I've posted at doom9.org. Each of them uses a different approach. The simplest thing is to use the YDifference function that is built into AVISynth. It provides a number that is based on the sum of the absolute differences between each and every pixel in adjacent frames. At a scene change, virtually every pixel is different, so this metric "blows up" and gets really large when there is a scene change. A good script will compare this value for the current frame with the values in adjacent frames in order to detect the spike.

    Here is some code to get you started. It will create a text file that contains the frame number where scene changes happen.

    Code:
    filename = "e:\Scenes.txt"
    global blankthreshold=1.8
    source = AVISource("e:\fs.avi").convertTOYV12().killaudio()
    
    #Remove the /* and */ comment block in order to see the metrics on screen in order to tune the "blankthreshold" parameter
    /*
    script = """Subtitle("\nNext/Prev = " + String( YDifferenceToNext(last) / YDifferenceFromPrevious(last) ), lsp=0)"""
    final = ScriptClip(source,script)
    return final
    */
    
    WriteFileIf(source, filename, "(YDifferenceToNext(last) / YDifferenceFromPrevious(last)>blankthreshold)", "current_frame+1", append = false)
    If your video is low contrast, you can sometimes get better results by stretching the histogram with "ColorYUV(AutoGain=true)" added to the end of the "source" line.

    There are quite a few simple utilities that will do this. The old freeware "Scenalyzer" had an "optical" scene detection utility built in. I don't know if it can be used for anything other than DV, however.
    Last edited by johnmeyer; 7th Nov 2016 at 21:58. Reason: added last sentence
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!