PDA

View Full Version : Timecode-based scene change detection script?


fvisagie
20th August 2009, 12:07
Hi All,

Do you know of a script that generates a scene change list from DV timecodes?

I need to make a scene change list for an edited DV AVI of around 36GB. There are various utilities that use DATECODEs to do that. However, that is less accurate than using timecodes, because DATECODEs only have 1 s resolution and miss short edits.

For lack of AVS scripting experience, I plan to merely dump each frame's frame number and timecode value into a CSV file using DVInfo, for Excel to pick up the discontinuities.

What is frustrating is all that seems doable in an AVS script in order to output scene changes only (even in ASS format ;-)), but I don't have the AVS know-how yet. Some string manipulation would be needed to convert the timecode frame number returned in DVInfo's tc_time (e.g. 00:55:48-08) to a decimal value, but the logic would go something like this:

/* Initialisation */
previous_tc = -1;

/* Runtime code */
/* Recompressed frames with e.g. text inlay have timecode = 0 */
if ( (tc_time && previous_tc && (tc_time != (previous_tc + 1) MOD frame_rate)) || (!tc_time && previous_tc) || (tc_time && !previous_tc) )

list_change (current_frame, tc_time);
previous_tc = tc_time;

This seems so straight-forward, someone must have already done this. If you know of such an AVS script, please tell me?!

Thanks,
Francois

Gavino
20th August 2009, 17:00
This sort of thing is a bit tricky to do in a script, since it requires processing on a per-frame basis, but can be done using Avisynth's runtime environment (http://avisynth.org/mediawiki/Runtime_environment). Basically, you would do something like this:
# initialise variables
...

AviSource(...)
WriteFileIf("out.txt", " condition ", " desired output ")
FrameEvaluate("""
update variables
""")
DVInfo(...)

The statements inside the FrameEvaluate call are evaluated on each frame and can be used to set variables derived from the tc_time set by DVInfo. These variables can then be used in the condition which controls output to the file. (Note the order of the filters seems 'backwards', due to the way the filter chain works - see the above link).

Hopefully, this will be enough to get you started - ask again if you have problems working out the details.

An alternative approach might be to build a custom version of DVInfo - the source code is in the zip file.

fvisagie
20th August 2009, 18:08
Thanks, Gavino, that's roughly what I've figured out in the meantime also. Now for the processing required inside that FrameEvaluate()...

By the way, I've discovered I'm forced to do the scene change detection at AVS runtime for this file. I can't just log frames' timecodes and process them with Excel - the video contains somewhere over 255,000 frames and Excel cannot handle that many lines!

But while I still thought I could do things that way, I came up with a neat trick for outputting the timecode's frame value to the CSV in an accessable way, without additional processing. Remember timecodes are displayed by default as e.g. "00:55:48-08". The last two digits are its frame value. This makes it easy to work with in the CSV file :-) :

timecode_format = "%H:%M:%S, %d"

WriteFileIf(...)
FrameEvaluate(...)
DVInfo (input_file, """ "" """, tc_format = timecode_format)

Ghitulescu
20th August 2009, 19:29
I'm not sure that would work, because an edited DV file has a completely new TC, automatically generated by the editing software. Maybe I'm wrong, maybe it depends on the software ...

fvisagie
20th August 2009, 19:45
I'm not sure that would work, because an edited DV file has a completely new TC, automatically generated by the editing software. Maybe I'm wrong, maybe it depends on the software ...

Thanks for your concern, although in this case it seems unwarranted. I've checked with both DVDate and DVInfo that timecodes in the DV AVI rendered by Windows Movie Maker seem to: 1) run monotonically (?) from the start of each respective source tape, and 2) are discontinuous at scene changes.

I seem to be even more fortunate. The first 1/4 of my footage has no DATECODEs because the camera's on-board clock settings had got lost. That makes subtitling of those DATECODEs very difficult (I had to generate them by hand ;-)), and scene change editing too. But it seems that footage got written with timecodes, and not only that, they have the above characteristics. Which means that hopefully I'll have scene information for that footage even in the absence of DATECODEs.

fvisagie
22nd August 2009, 21:05
Hi People, it seems I got this working, see http://forum.doom9.org/showpost.php?p=1317470&postcount=51.