From: Zach Bartels Date: 2010-02-15T05:55:07+09:00 Subject: Theory behind proof of concept for automatic IVTC decimation Hi again, This relates to my video editing project. Now that I have a list of patterns I can (for sake of ease) hard code into my program I have been googling about file operations. But I have not been able to find an answer to my question.. This post originally started as a question on file operations, but seems to have evolved into an outline for my proof of concept program and what I'd like it to do / how it should work.. Again not asking anyone to code the whole thing for me.. But for questions mentioned in the post, or where it seems I don't understand how something works, pointing me in the right direction with links to tutorials and such, or general advice on better ways to do something, or if you are inclined to give practical examples on how to achieve my goals, it would be greatly appreciated. I am interested in how you would do several different things, such as: Start reading a file at a specific line, that is not guaranteed to be the same line every time.. I.e while the [MATCHES] section in a Yatta Project file might start on line 300 in one case, in another where the user has done different tasks (more, or less) there may be more or less information stored, and the [MATCHES] section might not be on line 300 every single time.. [MATCHES] is the header that proceeds the list of matches for the frames Yatta is working on. So I assume I need to search the file and stop at the first occurance of [MATCHES]. Then start reading line by line, one at a time. Each frame is listed on one line, with one character for the pattern.. So a parttern of CCCNN would be presented as 5 lines in the text file like so: C C C N N I am supposing I should iterate through each line, and store the results in an array? I think this is best, because array indices also start with 0, just like video frame counts. Frame 0 would amount to Array[0]. Easy to keep track of.. If I understand things right, I don't need to worry about getting the frame count beforehand and creating a pre-defined matrix with "X number of spots" to fill.. I can just expand the array on the fly and the appropriate index number will be given? (Array.push?) So the question is, how do I open the yatta project file (just a text file AFAIK) then search until [MATCH] is found - then start counting on the actual line the pattern data was started on? There are no blank lines between [MATCH] and the first frame. However after the last frame in the video there IS a white space, and then the next section header [POSTPROCESS] occurs. So I guess I would want it to iterate through all lines AFTER the line [MATCHES] is found on, and then stop iterating and pushing data into the array at the first blank line it comes across (which is after the last frame in the video). An abbreviated structure of the section would look like this [MATCHES] c c c n n c c c n n <-- note the white space / blank line [POSTPROCESS] The hope is I end up with an array, containing the following (using the above section example): MyArray [c, c, c, n, n, c, c, c, n, n] which in order of index would be... 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 - and would exactly match the frame count numerations.. MyArray[0] == Frame 0 of my video file.. Sound correct so far? Meanwhile.. storing the patterns to match against.. Maybe I am overcomplicating it, but I thought about making object instances (Pattern 1, Pattern 2, etc) that were arrays themselves and then using a loop to find the pattern the section matches.. Of course how would you tell Ruby to compare only 5 individual chunks of the array (0-4, 5-9, 10-14, etc) incrementing by 5 each time so it doesn't lose its place, backtrack, etc and counts up properly? I know how to make an iteration loop to loop through all possible patterns until a match is found - but not how to specify sections of an array, much less doing so in a manner that I don't mess up and compared 0-4, and then 1-5, or skip/miss things in other ways. Would it be simpler to simply read in the patterns 5 lines at a time, keeping each 5 line "chunk" of data inside an array as mentioned before, but using the object method to reference it, and store all objects generated inside a master array ? Like: MasterList: an array holding a list of all items generated from reading the file. Section1: a 5 frame pattern from the file comprised of frames 0 - 4 Section2: same as above but frames 5 - 10 ad nauseum I suspect I would use object references throughout as well, and not necesarrily rely on array indices, to keep things simple since by breaking it up into multiple arrays you could lose track of the real frame numbers.. Well I'm having too many ideas now.. So I should probably cut this short. Sorry to be so long winded, but hopefully everyone gets an idea of what I am aiming to do.. More than anything I just need an answer on the file manipulation problems, once I can get the data into memory, the rest should be pretty simple for me to play around with and find the best method to use. -Zach