File: block2spec

package info (click to toggle)
ucbmpeg 1r2-6
  • links: PTS
  • area: non-free
  • in suites: hamm, potato, slink
  • size: 9,504 kB
  • ctags: 7,643
  • sloc: ansic: 79,920; tcl: 2,985; perl: 313; asm: 284; makefile: 269; csh: 13
file content (232 lines) | stat: -rwxr-xr-x 6,332 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#!/usr/bin/perl
;# 
;#  block2spec:  Convert "block_files" to "Spec files"
;# 
;#  ARGS:   -qs   -mv   -ftype   -ren  -noslice
;#          -start N   -end N   -o outfile
;#
;#  mpeg_stat -block_info block_file foo.mpg
;# will produce a block information file, which can then be converted
;# into a "specifics file" for mpeg_encode 1.5.  This is useful if you have
;# created an mpeg, and would like to recreate it with slightly different 
;# parameters, for example keeping all the same motion vectors, but with a 
;# different bit rate....
;# In that case you would only want the motion vectors information -mv
;#
;# a -makerelative option would be nice....
;# and something to realize all block are the same, and set frame QS etc.
;#
;# Output is to stdout, unless -o is used.


;($myname = $0) =~ s,.*/,,;
;$usage = <<_;
Usage: $myname [-qs] [-mv] [-ftype] [-ren] [-start N] [-end N] [-o outfile] block_file
Options:
    -qs    Put in Qscale information
    -mv    Put in motion vector information
    -ftype Put in frame type information (I, P, B)
    -all   All of the above (i.e. make the video the same).
    -noslice   Do not copy slice information
    -start N   (-sN) Begin at frame N
    -end N     (-eN) End at frame N
    -ren   (renumber) If used with -start, makes output frames start at 0
    -o outfile  Output to file outfile
_


;# Which parts of the spec to keep:
$start = 0;
$end = -1;
$qs = 0;
$mv = 0;
$ft = 0;
$noslice = 0;
$renumber = 0;
$outfile = "";


;# Go through the args....
$i = 0;
$ARGC = $#ARGV;
$_ = $ARGV[1];
if (/^-?$/ || /^-help$/) {&usage("");}
while ($i < $ARGC) {
    $_ = $ARGV[$i];
				# simple options
    if (/^-mv$/) { $mv = 1; $i++; next;}
    if (/^-qs$/) { $qs = 1; $i++; next;}
    if (/^-ftype$/) { $ft = 1; $i++; next;}
    if (/^-ren$/) { $renumber = 1; $i++; next;}
    if (/^-renumber$/) { $renumber = 1; $i++; next;}
    if (/^-noslice$/) { $noslice = 1; $i++; next;}
    if (/^-all$/) { 
	$mv = 1; $qs = 1; $ft = 1;
	$i++; 
	next;
    }
				# two part options
    if (/^-start$/) { $i++; $start=$ARGV[$i]; $i++; next;}
    if (/^-end$/)   { $i++; $end=$ARGV[$i]; $i++; next;}
    if (/^-o$/) {
	$i++;
	$outfile = $ARGV[$i];
	$i++;
	next;
    }
				# appended options
    ($car, $cdr) = /^-?(.)(.*)/;
    if ($car eq 's') { $start=$cdr; $i++; next;}
    if ($car eq 'e') { $end=$cdr; $i++; next;}
    if ($car eq 'o') {
	$outfile = $cdr;
	$i++;
	next;
    }
    &usage("Unknown option: $_\n\n");
    $i++;
}

				# Setup output
$file_name = $ARGV[$ARGC];
if ($outfile ne "") {
    open(OUTPUT, ">$outfile") || die "$outfile: $!\n";
    select(OUTPUT);
}
print("/* Auto-converted block-info file */\n");

$frame = 0;
$time_zero = 0;
open(INPUT, $file_name) || die "$file_name: $!\n";
$_ = <INPUT>;			# Get comment line
print $_;			# Copy comment into output
print "version 2\n";
while (<INPUT>) {
    ($car, $cdr) = /^(\S*) (.*)/;
    $_ = $cdr;
    if ($car eq "gop") {
	next;
    }

    if ($car eq "frame") {
	($mfnstr, $mft, $mpx, $mfn) = /(\d*) (\S) (\S*) (\d*)/;
	if ($mfn == 0) {$time_zero = $mfnstr;}
	$frame = $mfn+$time_zero;# Display frame number is temp_ref more than time 0
	if ($renumber == 1) {	# virtual frame number?
	    $vfn = $frame - $start;
	} else {
	    $vfn = $frame;
	}
	# handle stream order -> display order
	if ($frame < $start) {next;}
	if (($end >= 0) && ($frame > $end)) {last};
	if ($ft == 0) {
	    print "frame $vfn - 0\n";
	} else {
	    print "frame $vfn $mft 0\n";
	}
	next;
    }
    if ($frame < $start) {next;}    
    if ($car eq "slice") {
	if ($noslice == 1) {next;}
	($msn, $msqs) = /(\d*) (\d*)/;
	if ($qs == 0) {
	    print "slice $msn 0\n";
	} else {
	    print "slice $msn $msqs\n";
	}
	next;
    }

    if ($car eq "block") {
	#sample: block 1 B 6 39 forw+back <0, 1> <1, 0> 100010
	@blockinfo = split(' ');
	$bn = $blockinfo[0];
	$bqs = $blockinfo[2];
	if ($qs == 0) {
	    $vqs = 0;
	} else {
	    $vqs = $bqs;
	}
	if ($mv == 0) {		# easy ones!
	    print "block $bn $vqs\n";
	} else {
	    $bty = $blockinfo[4];
	    if ($bty eq "skip") {
		print "block $bn $vqs skip\n";
	    } elsif ($bty eq intra) { # no way to specify!
		print "block $bn $vqs\n";
	    } elsif ($bty eq "forw") {
		$ymv = $blockinfo[5];
		$ymv =~ s/<([-\d]*),/$1/;
		$xmv = $blockinfo[6];
		$xmv =~ s/>//;
		print "block $bn $vqs forw $ymv $xmv\n";
	    } elsif ($bty eq "back") {
		$ymv = $blockinfo[5];
		$ymv =~ s/<([-\d]*),/$1/;
		$xmv = $blockinfo[6];
		$xmv =~ s/>//;
		print "block $bn $vqs back $ymv $xmv\n";
	    } elsif ($bty eq "forw+back") {
		$fymv = $blockinfo[5];
		$fymv =~ s/<([-\d]*),/$1/;
		$fxmv = $blockinfo[6];
		$fxmv =~ s/>//;
		$bymv = $blockinfo[7];
		$bymv =~ s/<([-\d]*),/$1/;
		$bxmv = $blockinfo[8];
		$bxmv =~ s/>//;
		print "block $bn $vqs bi $fymv $fxmv $bymv $bxmv\n";
	    } elsif ($bty eq "0") {
		print "block $bn $vqs\n"; # no way to specify
	    } else {
		print STDERR "Block what? $_\n";
	    }
	}		       
	next;
    }

    print STDERR "What is this?: +$car+ -$cdr-\n"
}

				# All done
if ($outfile ne "") {
    close(OUTPUT);
}
exit;


sub usage {
    select(STDERR);
    print @_, $usage;
    print "$rcsid\n" if $rcsid =~ /:/;
    exit;
}


# Copyright (c) 1995 University of California at Berkeley
# 
# Written by Steve Smoot
# My first "real" Perl program, so I apologize for any sillyness
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose, without fee, and without written agreement is
# hereby granted, provided that the above copyright notices and the following
# two paragraphs appear in all copies of this software.
# 
# IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
# DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
# OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
# CALIFORNIA or the Technical University of Berlin HAS BEEN ADVISED OF THE 
# POSSIBILITY OF SUCH DAMAGE.
# 
# THE UNIVERSITY OF CALIFORNIA
# SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE 
# UNIVERSITY OF CALIFORNIA HAS NO 
# OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, 
# OR MODIFICATIONS.
#