Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 672754a

Browse files
committed
Added 24 bit RGB capture
Added JPEG capture Added multiple-speed VCR sync and single-step VCR sync VCR sync recorded movies get correct timestamps Added (still non-functional) 24-bit picture scaling
1 parent 34d12de commit 672754a

2 files changed

Lines changed: 166 additions & 24 deletions

File tree

Demo/sgi/video/Vb.py

Lines changed: 94 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ def main():
4545
StopCapture = 'StopCapture'
4646

4747
VideoFormatLabels = ['Video off', 'rgb8', 'grey8', 'grey4', 'grey2', \
48-
'grey2 dith', 'mono dith', 'mono thresh']
48+
'grey2 dith', 'mono dith', 'mono thresh', 'rgb24', 'rgb24-jpeg']
4949
VideoFormats = ['', 'rgb8', 'grey', 'grey4', 'grey2', \
50-
'grey2', 'mono', 'mono']
50+
'grey2', 'mono', 'mono', 'rgb', 'jpeg']
5151

5252
VideoModeLabels = ['Continuous', 'Burst', 'Single frame', 'VCR sync']
5353
[VM_CONT, VM_BURST, VM_SINGLE, VM_VCR] = range(1, 5)
@@ -56,11 +56,17 @@ def main():
5656
'16 bit mono', '16 bit stereo', '8 bit mono', '8 bit stereo']
5757
[A_OFF, A_16_MONO, A_16_STEREO, A_8_MONO, A_8_STEREO] = range(1, 6)
5858

59+
VcrSpeedLabels = ['normal', '1/3', '1/5', '1/10', '1/30', 'single-step']
60+
VcrSpeeds = [None, 5, 4, 3, 2, 1, 0]
61+
62+
RgbSizeLabels = ['full', 'quarter', 'sixteenth']
63+
5964
class VideoBagOfTricks:
6065

6166
# Init/close stuff
6267

6368
def init(self):
69+
self.window = None
6470
formdef = flp.parse_form('VbForm', 'form')
6571
flp.create_full_form(self, formdef)
6672
self.g_cont.hide_object()
@@ -119,6 +125,15 @@ def setdefaults(self):
119125
self.in_nframes.set_input('0')
120126
self.in_nframes_vcr.set_input('1')
121127
self.in_rate_vcr.set_input('1')
128+
self.c_vcrspeed.clear_choice()
129+
for label in VcrSpeedLabels:
130+
self.c_vcrspeed.addto_choice(label)
131+
self.c_vcrspeed.set_choice(4)
132+
self.c_rgb24_size.clear_choice()
133+
for label in RgbSizeLabels:
134+
self.c_rgb24_size.addto_choice(label)
135+
self.c_rgb24_size.set_choice(1)
136+
self.rgb24_size = 1
122137
# Audio defaults
123138
self.aout = None
124139
self.aport = None
@@ -174,6 +189,17 @@ def makewindow(self):
174189
gl.qdevice(DEVICE.WINQUIT)
175190
gl.qdevice(DEVICE.WINSHUT)
176191

192+
def optfullsizewindow(self):
193+
if not self.window:
194+
return
195+
gl.winset(self.window)
196+
if not self.use_24:
197+
gl.winconstraints()
198+
return
199+
gl.prefsize(self.maxx, self.maxy)
200+
gl.winconstraints()
201+
self.bindvideo()
202+
177203
def bindvideo(self):
178204
if not self.video: return
179205
x, y = gl.getsize()
@@ -287,6 +313,14 @@ def cb_nframes_vcr(self, *args):
287313
def cb_rate_vcr(self, *args):
288314
pass
289315

316+
def cb_vcrspeed(self, *args):
317+
pass
318+
319+
def cb_rgb24_size(self, *args):
320+
i = self.c_rgb24_size.get_choice()
321+
if i:
322+
self.rgb24_size = i
323+
290324
# Audio controls: format, file
291325

292326
def cb_aformat(self, *args):
@@ -318,7 +352,7 @@ def cb_capture(self, *args):
318352
elif self.vmode == VM_BURST:
319353
self.burst_capture()
320354
elif self.vmode == VM_SINGLE:
321-
self.single_capture()
355+
self.single_capture(None, None)
322356
elif self.vmode == VM_VCR:
323357
self.vcr_capture()
324358

@@ -338,6 +372,9 @@ def burst_capture(self):
338372
self.setwatch()
339373
gl.winset(self.window)
340374
x, y = gl.getsize()
375+
if self.use_24:
376+
fl.show_message('Sorry, no 24 bit continuous capture yet', '', '')
377+
return
341378
vformat = SV.RGB8_FRAMES
342379
nframes = self.getint(self.in_nframes, 0)
343380
if nframes == 0:
@@ -424,7 +461,7 @@ def cont_capture(self):
424461
self.reset()
425462
self.b_capture.label = saved_label
426463

427-
def single_capture(self):
464+
def single_capture(self, stepfunc, timecode):
428465
self.open_if_closed()
429466
self.init_cont()
430467
while 1:
@@ -434,11 +471,32 @@ def single_capture(self):
434471
except sv.error:
435472
pass
436473
sgi.nap(1)
437-
data = cd.InterleaveFields(1)
474+
if stepfunc: # This might step the video
475+
d=stepfunc() # to the next frame
476+
if not self.use_24:
477+
data = cd.InterleaveFields(1)
478+
else:
479+
x, y = self.vout.getsize()
480+
if self.rgb24_size == 1:
481+
data = cd.YUVtoRGB(1)
482+
elif self.rgb24_size == 2:
483+
data = cd.YUVtoRGB_quarter(1)
484+
x = x/2
485+
y = y/2
486+
elif self.rgb24_size == 3:
487+
data = cd.YUVtoRGB_sixteenth(1)
488+
x = x/4
489+
y = y/4
490+
else:
491+
raise 'Kaboo! Kaboo!'
492+
if self.use_jpeg:
493+
import jpeg
494+
data = jpeg.compress(data, x, y, 4)
438495
cd.UnlockCaptureData()
439496
self.end_cont()
440-
t = (self.nframes+1) * (1000/25)
441-
return self.write_frame(t, data)
497+
if timecode == None:
498+
timecode = (self.nframes+1) * (1000/25)
499+
return self.write_frame(timecode, data)
442500

443501
def vcr_capture(self):
444502
if not self.vcr:
@@ -462,9 +520,15 @@ def vcr_capture(self):
462520
self.open_if_closed()
463521
rate = self.getint(self.in_rate_vcr, 1)
464522
rate = max(rate, 1)
523+
vcrspeed = self.c_vcrspeed.get_choice()
524+
vcrspeed = VcrSpeeds[vcrspeed]
525+
if vcrspeed == 0:
526+
stepfunc = self.vcr.step
527+
else:
528+
stepfunc = None
465529
self.speed_factor = rate
466-
addr = self.vcr.sense()
467-
if not self.single_capture():
530+
addr = start_addr = self.vcr.sense()
531+
if not self.single_capture(None, 0):
468532
return
469533
print 'captured %02d:%02d:%02d:%02d' % self.vcr.addr2tc(addr)
470534
count = self.getint(self.in_nframes_vcr, 1) - 1
@@ -477,7 +541,7 @@ def vcr_capture(self):
477541
rate = rate - (here - addr)
478542
addr = here
479543
return
480-
if not self.vcr.fwdshuttle(2): # one tenth speed
544+
if not self.vcr.fwdshuttle(vcrspeed): # one tenth speed
481545
self.vcr_error('fwd shuttle failed')
482546
return
483547
cycle = 0
@@ -494,7 +558,9 @@ def vcr_capture(self):
494558
print 'frame' + 's'*(here-addr-1 <> 1)
495559
cycle = (cycle+1) % rate
496560
if cycle == 0:
497-
if not self.single_capture():
561+
tc = (here-start_addr)*40
562+
if not self.single_capture(stepfunc, \
563+
tc):
498564
break
499565
print 'captured %02d:%02d:%02d:%02d' \
500566
% self.vcr.addr2tc(here)
@@ -516,7 +582,10 @@ def init_cont(self):
516582
else:
517583
self.rate = 2
518584
x, y = self.vout.getsize()
519-
info = (SV.RGB8_FRAMES, x, y, qsize, self.rate)
585+
if self.use_24:
586+
info = (SV.YUV411_FRAMES, x, y, qsize, self.rate)
587+
else:
588+
info = (SV.RGB8_FRAMES, x, y, qsize, self.rate)
520589
info2 = self.video.InitContinuousCapture(info)
521590
if info2 <> info:
522591
# XXX This is really only debug info
@@ -558,6 +627,13 @@ def get_vformat(self):
558627
self.rgb = (format[:3] == 'rgb')
559628
self.mono = (format == 'mono')
560629
self.grey = (format[:4] == 'grey')
630+
self.use_24 = (format in ('rgb', 'jpeg'))
631+
# Does not work.... if self.use_24:
632+
if 0:
633+
self.g_rgb24.show_object()
634+
else:
635+
self.g_rgb24.hide_object()
636+
self.use_jpeg = (format == 'jpeg')
561637
self.mono_use_thresh = (label == 'mono thresh')
562638
s = format[4:]
563639
if s:
@@ -576,6 +652,7 @@ def get_vformat(self):
576652
elif self.greybits == -2:
577653
convertor = imageop.dither2grey2
578654
self.convertor = convertor
655+
self.optfullsizewindow()
579656

580657
def get_aformat(self):
581658
self.reset()
@@ -597,6 +674,11 @@ def open_video(self):
597674
self.close_video()
598675
gl.winset(self.window)
599676
x, y = gl.getsize()
677+
if self.use_24:
678+
if self.rgb24_size == 2:
679+
x, y = x/2, y/2
680+
elif self.rgb24_size == 4:
681+
x, y = x/4, y/4
600682
vout = VFile.VoutFile().init(self.vfile)
601683
vout.setformat(self.vformat)
602684
vout.setsize(x, y)

Demo/sgi/video/VbForm.fd

Lines changed: 72 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Number of forms: 1
99
Name: form
1010
Width: 450.000000
1111
Height: 240.000000
12-
Number of Objects: 33
12+
Number of Objects: 37
1313

1414
--------------------
1515
class: 1
@@ -239,7 +239,7 @@ argument:
239239
--------------------
240240
class: 31
241241
type: 2
242-
box: 220.000000 170.000000 100.000000 30.000000
242+
box: 220.000000 130.000000 100.000000 30.000000
243243
boxtype: 2
244244
colors: 13 5
245245
alignment: 0
@@ -284,7 +284,7 @@ argument:
284284
--------------------
285285
class: 31
286286
type: 1
287-
box: 220.000000 170.000000 100.000000 30.000000
287+
box: 220.000000 130.000000 100.000000 30.000000
288288
boxtype: 2
289289
colors: 13 5
290290
alignment: 0
@@ -299,7 +299,7 @@ argument: 0
299299
--------------------
300300
class: 31
301301
type: 2
302-
box: 220.000000 110.000000 100.000000 30.000000
302+
box: 220.000000 70.000000 100.000000 30.000000
303303
boxtype: 2
304304
colors: 13 5
305305
alignment: 0
@@ -344,7 +344,7 @@ argument:
344344
--------------------
345345
class: 31
346346
type: 2
347-
box: 250.000000 170.000000 40.000000 30.000000
347+
box: 250.000000 130.000000 40.000000 30.000000
348348
boxtype: 2
349349
colors: 13 5
350350
alignment: 0
@@ -359,7 +359,7 @@ argument: 0
359359
--------------------
360360
class: 2
361361
type: 0
362-
box: 220.000000 170.000000 30.000000 30.000000
362+
box: 220.000000 130.000000 30.000000 30.000000
363363
boxtype: 0
364364
colors: 47 47
365365
alignment: 2
@@ -374,7 +374,7 @@ argument:
374374
--------------------
375375
class: 2
376376
type: 0
377-
box: 290.000000 170.000000 30.000000 30.000000
377+
box: 290.000000 130.000000 30.000000 30.000000
378378
boxtype: 0
379379
colors: 47 47
380380
alignment: 2
@@ -389,7 +389,7 @@ argument:
389389
--------------------
390390
class: 13
391391
type: 0
392-
box: 220.000000 110.000000 100.000000 30.000000
392+
box: 220.000000 70.000000 100.000000 30.000000
393393
boxtype: 0
394394
colors: 7 3
395395
alignment: 4
@@ -451,7 +451,7 @@ class: 10000
451451
type: 0
452452
box: 0.000000 0.000000 0.000000 0.000000
453453
boxtype: 0
454-
colors: 1147496041 1852404841
454+
colors: 640 235
455455
alignment: 4
456456
style: 0
457457
size: 11.000000
@@ -464,7 +464,7 @@ argument:
464464
--------------------
465465
class: 31
466466
type: 2
467-
box: 220.000000 110.000000 100.000000 30.000000
467+
box: 220.000000 70.000000 100.000000 30.000000
468468
boxtype: 2
469469
colors: 13 5
470470
alignment: 0
@@ -479,7 +479,7 @@ argument: 0
479479
--------------------
480480
class: 31
481481
type: 2
482-
box: 220.000000 170.000000 100.000000 30.000000
482+
box: 220.000000 130.000000 100.000000 30.000000
483483
boxtype: 2
484484
colors: 13 5
485485
alignment: 0
@@ -491,12 +491,72 @@ name: in_rate_vcr
491491
callback: cb_rate_vcr
492492
argument: 0
493493

494+
--------------------
495+
class: 42
496+
type: 0
497+
box: 220.000000 10.000000 100.000000 30.000000
498+
boxtype: 5
499+
colors: 7 0
500+
alignment: 0
501+
style: 0
502+
size: 11.000000
503+
lcol: 0
504+
label: VCR speed:
505+
name: c_vcrspeed
506+
callback: cb_vcrspeed
507+
argument: 0
508+
494509
--------------------
495510
class: 20000
496511
type: 0
497512
box: 0.000000 0.000000 0.000000 0.000000
498513
boxtype: 0
499-
colors: 544171552 1331849829
514+
colors: 640 235
515+
alignment: 4
516+
style: 0
517+
size: 11.000000
518+
lcol: 0
519+
label:
520+
name:
521+
callback:
522+
argument:
523+
524+
--------------------
525+
class: 10000
526+
type: 0
527+
box: 0.000000 0.000000 0.000000 0.000000
528+
boxtype: 0
529+
colors: 58720287 33751040
530+
alignment: 4
531+
style: 0
532+
size: 11.000000
533+
lcol: 0
534+
label:
535+
name: g_rgb24
536+
callback:
537+
argument:
538+
539+
--------------------
540+
class: 42
541+
type: 0
542+
box: 260.000000 200.000000 60.000000 30.000000
543+
boxtype: 5
544+
colors: 7 0
545+
alignment: 2
546+
style: 0
547+
size: 11.000000
548+
lcol: 0
549+
label: Size:
550+
name: c_rgb24_size
551+
callback: cb_rgb24_size
552+
argument: 0
553+
554+
--------------------
555+
class: 20000
556+
type: 0
557+
box: 0.000000 0.000000 0.000000 0.000000
558+
boxtype: 0
559+
colors: 0 0
500560
alignment: 4
501561
style: 0
502562
size: 11.000000

0 commit comments

Comments
 (0)