118 lines
3.2 KiB
Perl
118 lines
3.2 KiB
Perl
#!/usr/bin/perl
|
|
#
|
|
# marks2bytepos.pl: perl script to convert VDR cutting marks (marks.vdr) to byte positions
|
|
#
|
|
# Copyright (C) 2007 - 2010 Christoph Haubrich
|
|
#
|
|
# V 1.0 first public release
|
|
# V 1.1 added support for ts format
|
|
#
|
|
# This program is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU General Public License
|
|
# as published by the Free Software Foundation; either version 2
|
|
# of the License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program; if not, write to the Free Software
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
# Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
#
|
|
# The author can be reached at christoph.haubrich(AT)web.de
|
|
#
|
|
# The project's page is at http://firefly.vdr-developer.org/patches
|
|
#
|
|
# This script is intended to be used for cutting with Project X
|
|
# set CollectionPanel.CutMode=0 in the X.ini file or
|
|
# select "(0) use bytepos for cuts" in the GUI for the correct cut mode
|
|
#
|
|
# usage: marks2bytepos.pl /path/to/recording/with/timestamp
|
|
# output: byte positions (one per line) are printed on STDOUT
|
|
#
|
|
# Example:
|
|
# marks2bytepos.pl /path/to/recording/with/timestamp >cut.px
|
|
# java -jar ProjectX.jar -demux -cut cut.px /path/to/recording/with/timestamp/[0-9]*.vdr
|
|
#
|
|
|
|
use strict;
|
|
use bigint;
|
|
|
|
|
|
if (1 != @ARGV)
|
|
{
|
|
print "\nmarks2bytepos - convert vdr cutting marks to byte positions\n\n";
|
|
print "Usage: $0 /path/to/recording\n";
|
|
print "byte positions (one per line) are printed on STDOUT\n";
|
|
|
|
exit (1);
|
|
}
|
|
|
|
my $type = "";
|
|
my $ext = "";
|
|
my $fps = 25; # assume 25 frames/sec
|
|
|
|
if ( -e "$ARGV[0]/marks.vdr" && -e "$ARGV[0]/index.vdr")
|
|
{
|
|
$type="pes";
|
|
$ext=".vdr";
|
|
}
|
|
|
|
if ( -e "$ARGV[0]/marks" && -e "$ARGV[0]/index")
|
|
{
|
|
$type="ts";
|
|
|
|
if (defined(open (INFO, "<$ARGV[0]/info")))
|
|
{
|
|
$fps=1*substr((grep(/^F /,<INFO>))[0], 2);
|
|
close(INFO);
|
|
}
|
|
}
|
|
|
|
if ($type eq "") { die ("Couldn't find marks or index file in $ARGV[0]") };
|
|
|
|
|
|
open (MARKS, "<$ARGV[0]/marks${ext}") or die ("Couldn't open $ARGV[0]/marks${ext}");
|
|
my @marks=<MARKS>;
|
|
close(MARKS);
|
|
|
|
open (INDEX, "<$ARGV[0]/index${ext}") or die ("Couldn't open $ARGV[0]/index${ext}");
|
|
|
|
foreach (@marks)
|
|
{
|
|
my $buffer;
|
|
my $bytepos = 0;
|
|
my ($h, $m, $s, $f) = split /[:.]/,$_;
|
|
($f, undef) = split / /, $f;
|
|
my $frame = ($h * 3600 + $m * 60 + $s)* $fps + $f-1;
|
|
|
|
seek (INDEX, 8*$frame, 'SEEK_SET');
|
|
read (INDEX, $buffer, 8);
|
|
|
|
my ($offset, $offset2, $filenumber);
|
|
|
|
if ( $type eq "pes" )
|
|
{
|
|
($bytepos, undef, $filenumber, undef) = unpack("LCCS", $buffer);
|
|
}
|
|
else
|
|
{
|
|
($bytepos, $offset2, undef, $filenumber) = unpack("LCCS", $buffer);
|
|
$bytepos += 32*$offset2;
|
|
}
|
|
|
|
for (my $i=1; $i<$filenumber; $i++)
|
|
{
|
|
$bytepos += (-s sprintf (($type eq "pes") ? "%s/%03d.vdr" : "%s/%05d.ts", $ARGV[0], $i));
|
|
}
|
|
|
|
printf("%.0f\n", $bytepos);
|
|
};
|
|
|
|
close (INDEX);
|
|
|
|
exit (0);
|