VideoHelp Forum

Our website is made possible by displaying online advertisements to our visitors. Consider supporting us by disable your adblocker or Try ConvertXtoDVD and convert all your movies to DVD. Free trial ! :)
+ Reply to Thread
Results 1 to 4 of 4
Thread
  1. Member
    Join Date
    Feb 2018
    Location
    Saudi Arabia
    Search PM
    Hello,

    i'm new in the video field and i'm doing a research, and i'm in need for a way on how to split a video into segments automatically and randomly where the segment duration can be defined. for example: i added a 3 minute video and the output can be 6 segments taken randomly each segment is 1 second.

    if you can provide me with any tools or at least hint that it can be done either by some kind of codec or that it can only be developed by a software i would really appreciate it.

    Thank you
    Quote Quote  
  2. There are many ways to accomplish your goal (if I understand it correctly).
    I implemented a solution with AviSynth+ just to see if I could.
    It's a little awkward without language support for arrays. VapourSynth might be a better tool here.
    I assume you don't know AviSynth, so expect a learning curve. I added verbose comments if that helps.
    Code:
    AviSource("your video here.avi")
    ## (implicit 'Last' variable = your master clip)
    
    ShowFrameNumber(x=16, y=16) ## for testing
    
    Trim(80, 0) ## optional - delete first X frames
    
    fc = Round(FrameRate) ## enough frames for aprox. 1 second
    
    ## create a bunch of 1-second clips
    ## (repeatedly take a 1 sec. clip off the front and remove it from master)
    ## clips must be named "A" through "Z" (26 clips max)
    A=Trim(0, length=fc)    Trim(fc, 0)
    B=Trim(0, length=fc)    Trim(fc, 0)
    C=Trim(0, length=fc)    Trim(fc, 0)
    D=Trim(0, length=fc)    Trim(fc, 0)
    E=Trim(0, length=fc)    Trim(fc, 0)
    F=Trim(0, length=fc)    Trim(fc, 0)
    
    ## for testing purposes - add visual ID
    A=A.bigsub("A")
    B=B.bigsub("B")
    C=C.bigsub("C")
    D=D.bigsub("D")
    E=E.bigsub("E")
    F=F.bigsub("F")
    
    ## this will become the final "edit decision list"
    edl = ""
    
    ## the initial list - one letter for every clip you want to output 
    lst1="ABCDEF"
    len = StrLen(lst1)
    
    while (len>0) {
    
        ## pick a letter at random, remove it from 'lst1', add it to 'edl'   
        i = Rand(max=StrLen(lst1), seed=true)
    
        ct = MidStr(lst1, i+1, 1)
        lt = (i==0) ? "" : LeftStr(lst1, i)
        rt = (i==(len-1)) ? "" : MidStr(lst1, i+2)
        lst1 = lt + rt
        len = StrLen(lst1)
        
        edl = (StrLen(edl)==0) 
        \ ? ct 
        \ : edl + "++" + ct
    }
    
    ## "execute" the edl string as a script fragment
    Eval(edl)
    
    ## for testing, show the edl
    Subtitle(edl, align=1) 
    
    ## optional - save edl to file (re-use it with the Import statement)
    #WriteFileStart("<path>\random.avs", "edl")
    
    ## exit
    return Last
    
    ## for testing - show clip ID
    function bigsub(clip C, string msg)
    {
        return C.Subtitle(msg, align=2, size=C.Height, 
        \          text_color=$aaffff00, halo_color=$ff000000)
    }
    Quote Quote  
  3. Member
    Join Date
    Feb 2018
    Location
    Saudi Arabia
    Search PM
    Originally Posted by raffriff42 View Post
    There are many ways to accomplish your goal (if I understand it correctly).
    I implemented a solution with AviSynth+ just to see if I could.
    It's a little awkward without language support for arrays. VapourSynth might be a better tool here.
    I assume you don't know AviSynth, so expect a learning curve. I added verbose comments if that helps.
    Thank you very much for your feedback.. and i actually don't know AviSynth or VapourSynth but i don't mind learning them if they are going to help me with my research, but can i ask some questions regarding them; do they have libraries that i can use them in an application developed by Java or C# for example like the FFMPEG also, do they deal with audio signals? for example i want to do is that after randomly picking the segment video then separate the audio signal. and lastly as i noticed the code below:

    Originally Posted by raffriff42 View Post

    ## create a bunch of 1-second clips
    ## (repeatedly take a 1 sec. clip off the front and remove it from master)
    ## clips must be named "A" through "Z" (26 clips max)
    A=Trim(0, length=fc) Trim(fc, 0)
    B=Trim(0, length=fc) Trim(fc, 0)
    C=Trim(0, length=fc) Trim(fc, 0)
    D=Trim(0, length=fc) Trim(fc, 0)
    E=Trim(0, length=fc) Trim(fc, 0)
    F=Trim(0, length=fc) Trim(fc, 0)

    ## for testing purposes - add visual ID
    A=A.bigsub("A")
    B=B.bigsub("B")
    C=C.bigsub("C")
    D=D.bigsub("D")
    E=E.bigsub("E")
    F=F.bigsub("F")

    ## this will become the final "edit decision list"
    edl = ""

    ## the initial list - one letter for every clip you want to output
    lst1="ABCDEF"
    len = StrLen(lst1)

    while (len>0) {

    ## pick a letter at random, remove it from 'lst1', add it to 'edl'
    i = Rand(max=StrLen(lst1), seed=true)

    ct = MidStr(lst1, i+1, 1)
    lt = (i==0) ? "" : LeftStr(lst1, i)
    rt = (i==(len-1)) ? "" : MidStr(lst1, i+2)
    lst1 = lt + rt
    len = StrLen(lst1)

    edl = (StrLen(edl)==0)
    \ ? ct
    \ : edl + "++" + ct
    }

    ## "execute" the edl string as a script fragment
    Eval(edl)

    ## for testing, show the edl
    Subtitle(edl, align=1)

    ## optional - save edl to file (re-use it with the Import statement)
    #WriteFileStart("<path>\random.avs", "edl")

    ## exit
    return Last

    ## for testing - show clip ID
    function bigsub(clip C, string msg)
    {
    return C.Subtitle(msg, align=2, size=C.Height,
    \ text_color=$aaffff00, halo_color=$ff000000)
    }
    [/code]
    i get the idea that the code is going to split my video into segments of 1 second then store them into variables; then a loop will randomly pick one of the letters to later display the video segment. is my understanding correct?
    Quote Quote  
  4. > do they have libraries that i can use them in an application developed by Java or C# for example like the FFMPEG

    Yes, many of the audio and video filters in ffmpeg also exist in AviSynth - and more besides. Here is a page describing them. There are many more filters available as plugins.

    If you want to do advanced special effects or color correction, you would do better with a GUI interface - a real video editor. More on this below.

    AviSynth is not primarily a procedural language like Java or C#; its basic function is to set up filter graphs, similar to ffmpeg's -filter_complex (described here) but much easier to work with in my opinion.

    To start learning about AviSynth, you might want to scan the Wikipedia page:
    https://en.wikipedia.org/wiki/AviSynth

    Then install it and play with a few basic scripts:
    http://avisynth.nl/index.php/First_script

    VapourSynth has more procedural features (like arrays, as I said). You write VapourSynth code in Python, which you might like, I don't know.


    > also, do they deal with audio signals? for example i want to do is that after randomly picking the segment video then separate the audio signal.

    Yes, it has support for basic audio mixing, editing and fading, but it's not suited to precision edits, or equalization, noise reduction etc - these things should be done in another program. Audacity is good for these tasks.

    VapourSynth does not support audio.


    > and lastly... i get the idea that the code is going to split my video into segments of 1 second then store them into variables; then a loop will randomly pick one of the letters to later display the video segment. is my understanding correct?

    Yes, that is correct. It assembles a string containing all the clips in random order. Here's an example:
    Code:
    E++A++D++C++B++F
    This is a valid script fragment that is inserted into the main script with the Eval filter. The "++" symbols invoke the AlignedSplice filter

    Having said all this, remember "there are many ways to do this." Another way would be to get a video editor that supports exporting and importing of edit decision lists (EDLs), cut your clips, export the EDL (which is a text file, one edit per line), randomize the clip order in some way (maybe in a spreadsheet) and re-import the EDL. This "hack" may not even be required. For all I know, there may be an editor with a built in "randomize" effect...
    Quote Quote  



Similar Threads