-
Notifications
You must be signed in to change notification settings - Fork 8
/
f-nstamp
executable file
·126 lines (104 loc) · 3.92 KB
/
f-nstamp
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
#!/usr/bin/env python
#
# Copyright 2009 Claudio Pisa (claudio dot pisa at uniroma2 dot it)
#
# This file is part of SVEF (SVC Streaming Evaluation Framework).
#
# SVEF 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 3 of the License, or
# (at your option) any later version.
#
# SVEF 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 SVEF. If not, see <http://www.gnu.org/licenses/>.
#
import sys
import commands
import tempfile
import os
from nalulib import *
if(len(sys.argv) < 3):
print """
For each line of a BitstreamExtractor-generated trace file, add a
column with the frame number corresponding to the NALU associated to
that line.
Usage: %s <original stream's H264AVCDecoder output> <BitsreamExtractor
generated trace> > sendingtrace.txt
Where:
<original stream's H264AVCDecoder output>: the screen output obtained
from the H264AVCDecoder ran using the sent H.264 file as argument. For
example:
$ H264AVCDecoderLibTestStatic foreman.264 foreman_null.yuv > originaldecoderoutput.txt
<BitstreamExtractor generated trace>: the trace file obtained by using
the "-pt" option of the BitstreamExtractor executable using as argument
the sent H.264 file, or from the purgeLastGOP.py script.
For example:
$ BitstreamExtractorStatic -pt originaltrace.txt foreman.264
Example: $ %s originaldecoderoutput.txt originaltrace.txt > originaltrace-frameno.txt
""" % (os.path.basename(sys.argv[0]), os.path.basename(sys.argv[0]))
sys.exit(1)
GOPSIZE = 16
originaldecoderoutputfilename = sys.argv[1]
originaltraceptfilename = sys.argv[2]
# load lines from the original trace file
originaltracefile = open(originaltraceptfilename)
slicedatatracelist = []
tracelist = []
for line in originaltracefile:
try:
nalu = NALU(line)
if nalu.packettype == "SliceData":
if not nalu.isControlNALU():
slicedatatracelist.append(nalu)
if nalu.length != -1:
tracelist.append(nalu)
except NALUException:
pass
originaltracefile.close()
# load lines from the decoder file
originaldecoderoutputfile = open(originaldecoderoutputfilename)
decoderlist = []
offset = -2 * GOPSIZE + 1
offsetjustchanged = False
positive = False
for line in originaldecoderoutputfile:
try:
decnalu = DecoderNALU(line)
# find the frame for each line/NALU
if decnalu.frame == 0 and not offsetjustchanged:
offset += GOPSIZE
offsetjustchanged = True
elif decnalu.frame > 0 and not offsetjustchanged and not positive: # in the last GOP the sign changes
offset += GOPSIZE
positive = True
offsetjustchanged = True # delete?
if offset < 0:
decnalu.realframe = abs(decnalu.frame)
else:
decnalu.realframe = offset + abs(decnalu.frame)
decoderlist.append(decnalu)
except NALUException:
offsetjustchanged = False
originaldecoderoutputfile.close()
if len(slicedatatracelist) != len(decoderlist):
print "Length problem: %d vs. %d" % (len(slicedatatracelist), len(decoderlist))
sys.exit(1)
# check that tracefile and decoder output match
zippedlists = zip(slicedatatracelist, decoderlist)
for tn, dn in zippedlists:
if tn.lid != dn.lid or tn.tid != dn.tl or tn.qid != dn.ql:
print "Problem: %d %d %d vs. %d %d %d" % (tn.lid, tn.tid, tn.qid, dn.lid, dn.tl, dn.ql)
sys.exit(2)
tn.frame_number = dn.realframe
# find frame numbers for control NALUs
for n, nalu in enumerate(tracelist):
if nalu.isControlNALU():
nalu.frame_number = tracelist[n+1].frame_number
# print on standard output a copy of the originaltracefile with frame numbers
for nalu in tracelist:
print nalu