Subtitling Data Code from MiniDV

RandyHayes wrote on 4/22/2006, 6:15 AM
Hi,
I have been needing to back up my home videos from MiniDV to DVD for the convenience of random access and just as a backup. The thing is, I would like to be able to view the date/time stamp info that is buried in what my Sony camera calls the "Data Code". I haven't seen proof that Vegas is even aware of this information in captured video, but I figured someone in this forum might know if it's there, and how to retrieve it and turn it into the subtitle information for creating a subtitle track in DVD Architect.
The data code clock includes seconds. I'm guessing this would probably take up considerable space in the subtitle portion of the DVD.
I am using Vegas 5 and DVD Architect 2. Any suggestions?

Comments

JohnnyRoy wrote on 4/22/2006, 9:16 AM
If you could do it, it would probably be extremely impractical to have 30 subtitles per second on a DVD. You could burn in timecode using the Sony Timecode FX but there is no way to remove it and it would not follow the Data Code of the original video; it would simply be fresh timecode. It will also be permanent on the video which is not what you want. I don’t think there is anyway to achieve what you are look for.

~jr
johnmeyer wrote on 4/22/2006, 10:40 AM
If I understand the request, I think this is possible, although unfortunately not entirely within Vegas itself.

Vegas does display this information in the project view, but unlike timecode information, it doesn't make it available via an fX. I also don't think there is any API call to let you get at it via a script. This is true of other information on the tape, such as exposure, closed caption, etc.

However, there are several utilities, such as this one:

A very, very nice Date/Time stamper for DV files

that gives you some of what you are looking for.

While I agree that you would not want to put a different subtitle up for every frame of video, I would think that it would be quite sufficient to have a single subtitle for every video event. The way I would do this would be to designate one track as the "master" track. The date/time information will come from the video on this track. Next, extract the date/time information from the video on that track using a utility similar to the one in the link above (although that utility may not give you the option of putting the info into a text file). Finally, create a marker and name it with the appropriate information from that text file. This will give you the date/time of the beginning of the event. Export markers as subtitles, import those subtitles into DVDA, and I think you've got what you want, unless you absolutely need to have date/time down to the second.

Certainly this is what I've wanted to do for a long time.

Here is an AVISynth utility that reads the date/time and puts it on the video. If you know AVISynth, it can be used to also put the info into a text file:

DVInfo

Here's another:

DV Time Stamp

If you really want to get your creative juices flowing on what is possible if Sony were to give us access to some of this information, read this:

DV_Datecode

Finally, here is what I think the original poster wanted:DV Sub Maker

Description: Extract DV Date and Time from DV Avi file and make Subtitles from it.

Sounds pretty darned interesting.


johnmeyer wrote on 4/22/2006, 11:28 AM
OK, I just played around with the utility mentioned at the end of my last post. I think it does exactly what you want. However, it will require a little "programming" to get the format into something that DVD Architect will understand.

I simply downloaded and ran the utility. Opened a DV AVI file, and pressed "start" (no setup or anything). It created a file that looks like this:
00000001 06 03 18 17 56 08
00000008 06 03 18 17 56 09
00000038 06 03 18 17 56 10
00000068 06 03 18 17 56 11
00000098 06 03 18 17 56 12
00000128 06 03 18 17 56 13
00000158 06 03 18 17 56 14
00000188 06 03 18 17 56 15
00000218 06 03 18 17 56 16
00000248 06 03 18 17 56 17
00000278 06 03 18 17 56 18
00000308 06 03 18 17 56 19
00000338 06 03 18 17 56 20
00000368 06 03 18 17 56 21
00000398 06 03 18 17 56 22
00000428 06 03 18 17 56 23
00000458 06 03 18 17 56 24
00000488 06 03 18 17 56 25
00000518 06 03 18 17 56 26
00000548 06 03 18 17 56 27
00000578 06 03 18 17 56 28
00000608 06 03 18 17 56 29
00000638 06 03 18 17 56 30
00000668 06 03 18 17 56 31
As you can see, these are NTSC 30 fps frame numbers, each one second apart (except for the first few). The date is March 18, 2006, and the time is 5:56 in the evening. This gives you the date/time info for the AVI file. The utility can be configured to output the stamp information in different formats and in different intervals, if you desire.

The script would then need to read this file; use the offset of the event start to determine where in this file to read; read the date/time information from that file, and then create a marker at the start of the event and name that marker with the date/time info, suitably formatted for export to DVD subtitles (actually I think it needs to be a region if it is to be exported to a subtitle file).

Anyway, the project is definitely something that can be done, and would be something I'd personally love to have, but is is several hours of time that I just don't have right now.

[Edit]

Wow, I should have waited a little longer to post. This utility is even better:

DV datecode
bittersweet_parallel wrote on 5/22/2006, 11:32 PM
Ok, I have been playing around with the scripts you posted and integrating in the dv_datecode utility you point to. As this is really the first time I have played with JScript and Vegas scripting, I certainly don't have a good feel for how to do this stuff right. Seems this date codes stuff has been a problem in Vegas for a long time from reading the forums, so at this point I like the fact I have anything working at all :-)

SONY:: Please expose the Date/Time Stamp information from the Media object and our life would be much simpler...

>> The script would then need to read this file; use the offset of the event start to
>> determine where in this file to read; read the date/time information from that file,
>>and then create a marker at the start of the event and name that marker with the
>>date/time info, suitably formatted for export to DVD subtitles (actually I think it needs
>>to be a region if it is to be exported to a subtitle file).

Well, I certainly understand the "use the offset of the event ..." and read from the dv_datacode output file -- but in my case I really only wanted the date on the video. I figured out how to do just the date pretty easy from your code and descriptions :-) Is it a really needed to get down to the Hour/min (what about seconds) in the subtitle as well? The Subtitle would just be that one time for the whole region right? Does a region now become 1 second or 1 minute so that the subtitle time changes at the appropriate times? I suppose it depends on how detailed you are. For me I am just looking at the DD/MM/YY from the beginning of the clip which is totally sufficient for home videos so that in 20 years we will know on what date they were taken.

My concerns are:
1) I had to put a hard coded path to the dv_datacode.exe so I could run it. Is there a way to do this where it can be saved away nicely by vegas after the first time maybe?
2) I used the .srt output and used the first valid date that was output into that file (reason: some of my clips seem to have uninitialized time/date codes at the beginning 1/0/1900) The .srt format seemed to be the easiest to use. Could be wrong on this one.
3) I didn't even attempt the lookup based on being in the middle of the file - although I can see how that could be useful for some people. I am sure with more time I could figure out how to do it, but personally I have no need for it. I just want the date it was recorded DD/MM/YYYY :-)
4) There are parameters into the dv_datacode.exe that could be written into the INI configuration file from the jscript to automatically control the stuff. (Dialog to ask if you want date plus time and seconds kind of thing) For now, the script assumes the INI file is setup the way you want it.
5) I don't know how to do dialogs yet, so it just does what I have hardcoded
6) The error recovery, well is non-existant ...

My DV_DATECODE.INI looks like: (put a # in front of lines to comment them out if you want the TIME and SECONDS back in for example):


# programoption = NODATECODEDISPLAY
programoption = COMPRESSED_SUBTITLES
programoption = THREAD_PRIORITY THREAD_PRIORITY_NORMAL
programoption = IGNORE_SECONDS
programoption = IGNORE_TIME
programoption = IGNORE_INVALID_DATECODE

outputfiletype = NOSSA
outputfiletype = NOSUB
outputfiletype = NOTXT
outputfiletype = SRT

debuglevel = BRIEF
debugoutput = NONE


Gota have the DV datecode from DV Datecode Program

Then here is my Regions From AVI Date and Time.js script (it certainly can be made cleaner):


/**
* This script has a dependency on dv_datecode which can be downloaded from:
* http://www.skydiver.de/stef/dvdatecode_v1.4_exe.zip
*
* This script will add regions to all events on the first selected track,
* and name those regions using the first Date/Time code in the media file name.
* The regions will not overlap, even if the events overlap (because overlapping
* regions will be rejected by DVD Architect's subtitle facility).
* If a region already exists in the same location, no region is created.
*
* If more than one event comes from the same media, this will result in
* duplicate region names (which is OK, because you may want the same
* subtitle text in more than one place).
*
* Use the Edit Details view in Vegas to quickly view, modify, or delete
* the resulting regions.
*
* You can then use the script that ships with Vegas to convert these
* region names to a subtitle file that can be imported into DVD Architect
* (or other DVD authoring program). Thus, the file names of your media
* can become subtitles, without any work on your part.
*
* By Mike Lotz 5/22/2006:
*
* With most credit going to John Meyer.
* This script is based off a script by:
* By John Meyer 4/11/2005
* (updated 8/1/2005)
*
**/

import System;
import System.IO;
import System.Windows.Forms;
import Sony.Vegas;

var evnt : TrackEvent;
var myRegion : Region;
var RegionName : String;
var reader : StreamReader = null;
var regenerate : Boolean = 0 ;

try {

var dv_datacode = "\"d:\\Downloads\\Sony\\dvdatecode_v1.4_exe\\dv_datecode.exe\""
var dv_file_ext = ".dv_datecode.srt"

//Find first selected track
var track = FindSelectedTrack();
if (null == track)
throw "no selected track";

var eventEnum = new Enumerator(track.Events);
while (!eventEnum.atEnd()) {
RegionName = "";
evnt = TrackEvent(eventEnum.item());
var MyFilePath = evnt.ActiveTake.MediaPath;
var StartTime = evnt.Start;
var LengthTime = evnt.Length;

// Construct the command and the output file name that will be generated
var cmd2run = dv_datacode + " \"" + MyFilePath + "\"";
var outputFilename = MyFilePath + dv_file_ext

// If the output file does not already exist, then create it ...
if ( regenerate || !File.Exists( outputFilename ) ) {
var shell = new ActiveXObject("wscript.shell");
// The dv_datecode.ini file in the same directory as the executable
// determines whether date/time/seconds are saved away. I could write
// out that file here and then we could control the whole thing....
// For now, the INI file has to be set the way you want it ...
var objExec = shell.exec( cmd2run );

// Not sure if this next line is really needed, but I do want to wait
// on the program to stop running - it pops up a dialog
var OutputFromExeFile = objExec.StdOut.ReadAll();
}

// Now that the command is done, I want to read in the output file that was
// created
reader = new StreamReader( outputFilename );

// Find the first date in the file. On some of mine the date code is messed
// up and the first date is obviously wrong - 1/0/1900 - The format seems
// to be the 3rd line is the date and the 4th (if not blank) is the time.
// I just save the first timecode that is not the obvious wrong one :-)
var line : String;
var counter : int = 1;
var saveDate : String;
while ( (line = reader.ReadLine()) != null ) {
if ( line != "" ) {
if ( counter == 3 ) {
RegionName = line;
saveDate = line;
} else if ( counter == 4) {
RegionName = RegionName + " " + line;
}
counter = counter + 1;
} else {
// We are at a blank line, so see if the saved code was valid,
// if so then get out of this loop
if ( saveDate != "01/00/1900" )
break;
// We are at a blank line, this is a divider, so reset our counter
// If we did not break, then we need to get the next time code
counter = 1;
}
}
reader.Close()
// MessageBox.Show(RegionName)


if (evnt.FadeOut.Length.Nanos > 0) {
LengthTime = LengthTime - evnt.FadeOut.Length; // Eliminates region overlaps at crossfades.
}


// if (evnt.Selected) { // Add this IF statement, and ending brace, to only add regions for SELECTED events.

// The RegionExist function checks if a region already exists at this point.
if (!RegionExist(StartTime.ToMilliseconds(),LengthTime.ToMilliseconds() ) ) {
myRegion = new Region(StartTime,LengthTime,RegionName); //Insert a region over this event
Vegas.Project.Regions.Add(myRegion);
}

// } // End if evnt.Selected

eventEnum.moveNext();
} // End while (!eventEnum.atEnd()

} catch (e) {
MessageBox.Show(e);
}


function FindSelectedTrack() : Track {
var trackEnum = new Enumerator(Vegas.Project.Tracks);
while (!trackEnum.atEnd()) {
var track : Track = Track(trackEnum.item());
if (track.Selected) {
return track;
}
trackEnum.moveNext();
}
return null;
}


function RegionExist(dStart,dLength) : boolean {

var fmarkerEnum = new Enumerator(Vegas.Project.Regions);

while (!fmarkerEnum.atEnd()) {
var fRegion = fmarkerEnum.item();
var fRegionLength = fRegion.Length.ToMilliseconds();
var fRegionStart = fRegion.Position.ToMilliseconds();

if ( (dLength == fRegionLength) && (dStart == fRegionStart) ) {
return 1;
}
fmarkerEnum.moveNext();
}
return 0;
}

Mike
bittersweet_parallel wrote on 5/22/2006, 11:35 PM
Please tell me how to post the code so the indenting is nice. Cut/paste didn't seem to have it look nice in the end.
Thanks, Mike
johnmeyer wrote on 5/23/2006, 7:37 AM
You put <pre> at the beginning of the code and </pre> at the end.

Here's the remaining information I usually post about adding HTML to posts in this forum.

To create a link, you type this:
<a href="http://www.google.com">Google Main Page</a>
and that creates this:

Google Main Page


To open that link in a new window, you type this:
<a href="http://www.google.com/" target="_blank">Google Main Page</a>
to get this:

Google Main Page


How do I include HTML characters in my post so that they show up as chacters rather than generate HTML code?

You use the HTML ampersand (&) codes in place of the character itself. For instance, to get the

<

to appear, but not be interpreted as HTML, you type

&#38

If you type this, and then submit your post to the Sony forum, all you will get is the

<

character, and it will NOT be interpreted as HTML code. You then do this for every other special character in the HTML syntax.

Now, don't even think of asking me how I got &#38 to appear above instead of just the < character.

Here are many of the codes
 &#38 &
&#34 "
&#47 / slash
&#48- &#57; digits 0-9
&#58 : colon
&#59 ; semicolon
&#60 < less-than sign
&#61 = equals sign
&#62 > greater-than sign
&#63 ? question mark
&#64 @ at sign
&#65- &#90; uppercase letters A-Z
&#91 [ left square bracket
&#92 \ backslash
&#93 ] right square bracket
&#94 ^ caret
&#95 _ horizontal bar (underscore)
&#96 ` grave accent
&#97- &#122; lowercase letters a-z
&#123 { left curly brace
&#124 | vertical bar
&#8226 bullet



bittersweet_parallel wrote on 5/23/2006, 9:49 AM
Thank you, thank you, thank you !

&#38

but I think you really wanted me to type in

&#6( to get the <

Thanks :-),
Mike
bittersweet_parallel wrote on 5/23/2006, 9:51 AM
let me try again:

&#60

to get

<
johnmeyer wrote on 5/23/2006, 9:47 PM
Good catch. Thanks.