-
Notifications
You must be signed in to change notification settings - Fork 1
/
tarina.py
executable file
·4858 lines (4675 loc) · 208 KB
/
tarina.py
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# ```````` `````` ``````` ``` ```` ``` ``````
# ` ``` ` `` ``` ``` ``` ``` ```` `` `` ```
# ``` ``````` ``` ```` ``` ```````` ``````
# ``` `` `` `````` ``` `` ````` ``` ``
# ``` ``` ``` ``` ``` ``` ``` ```` ``` ```
# ```` ``` ```` ``` ``` ``` ```` ``` ``` ````
# a Muse of Filmmaking
# https://tarina.org
import picamerax as picamera
import numpy as np
import string
import os
import time
import datetime
import multiprocessing as mp
from subprocess import call
from subprocess import Popen
from omxplayer import OMXPlayer
from multiprocessing import Process, Queue
import subprocess
import sys
import pickle
import RPi.GPIO as GPIO
from PIL import Image
import socket
import configparser
import shortuuid
import smbus
import ifaddr
import web
#import shlex
from blessed import Terminal
# bless the code!
term = Terminal()
#DEBIAN VERSION
pipe = subprocess.check_output('lsb_release -c -s', shell=True)
debianversion = pipe.decode().strip()
print('running debian ' + debianversion)
#I2CBUTTONS
probei2c = 0
while probei2c < 3:
try:
if debianversion == "stretch":
os.system('sudo modprobe i2c-dev')
bus = smbus.SMBus(3) # Rev 2 Pi uses 1
else:
os.system('sudo modprobe i2c-dev')
bus = smbus.SMBus(11) # Rev 2 Pi uses 1
DEVICE = 0x20 # Device address (A0-A2)
IODIRB = 0x0d # Pin pullups B-side
IODIRA = 0x00 # Pin pullups A-side 0x0c
IODIRApullup = 0x0c # Pin pullups A-side 0x0c
GPIOB = 0x13 # Register B-side for inputs
GPIOA = 0x12 # Register A-side for inputs
OLATA = 0x14 # Register for outputs
bus.write_byte_data(DEVICE,IODIRB,0xFF) # set all gpiob to input
bus.write_byte_data(DEVICE,IODIRApullup,0xF3) # set two pullup inputs and two outputs
bus.write_byte_data(DEVICE,IODIRA,0xF3) # set two inputs and two outputs
bus.write_byte_data(DEVICE,OLATA,0x4)
print("yes, found em i2c buttons!")
i2cbuttons = True
break
except:
print("could not find i2c buttons!! running in keyboard only mode")
print("trying again...")
i2cbuttons = False
probei2c += 1
time.sleep(1)
bus=''
#MAIN
def main():
global headphoneslevel, miclevel, tarinafolder, screen, loadfilmsettings, plughw, channels, filmfolder, scene, showmenu, rendermenu, quality, profilelevel, i2cbuttons, menudone, soundrate, soundformat, process, serverstate, que, port, recording, onlysound, camera_model, fps_selection, fps_selected, fps, db, selected, cammode, newfilmname, camera_recording, abc
# Get path of the current dir, then use it as working directory:
rundir = os.path.dirname(__file__)
if rundir != '':
os.chdir(rundir)
#filmfolder = "/home/pi/Videos/"
#picfolder = "/home/pi/Pictures/"
tarinafolder = os.getcwd()
#MENUS
standardmenu = 'FILM:', 'SCENE:', 'SHOT:', 'TAKE:', '', 'SHUTTER:', 'ISO:', 'RED:', 'BLUE:', 'FPS:', 'Q:', 'BRIGHT:', 'CONT:', 'SAT:', 'FLIP:', 'BEEP:', 'LENGTH:', 'HW:', 'CH:', 'MIC:', 'PHONES:', 'COMP:', 'TIMELAPSE', 'MODE:', 'DSK:', 'SHUTDOWN', 'SRV:', 'SEARCH:', 'WIFI:', 'UPDATE', 'UPLOAD', 'BACKUP', 'LOAD', 'NEW', 'TITLE', 'LIVE:'
tarinactrlmenu = 'FILM:', 'SCENE:', 'SHOT:', 'TAKE:', '', 'SHUTTER:', 'ISO:', 'RED:', 'BLUE:', 'FPS:', 'Q:', 'BRIGHT:', 'CONT:', 'SAT:', 'FLIP:', 'BEEP:', 'LENGTH:', 'HW:', 'CH:', 'MIC:', 'PHONES:', 'COMP:', 'TIMELAPSE', 'MODE:', 'DSK:', 'SHUTDOWN', 'SRV:', 'SEARCH:', 'WIFI:', 'CAMERA:', 'Add CAMERA', 'New FILM', 'New SCENE', 'Sync SCENE'
#tarinactrlmenu = "BACK","CAMERA:", "Add CAMERA","New FILM","","New SCENE","Sync SCENE","Snapshot"
emptymenu='','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','',''
menu = standardmenu
showtarinactrl = False
recordwithports = False
pressagain = ''
#STANDARD VALUES (some of these may not be needed, should do some clean up)
abc = '_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','1','2','3','4','5','6','7','8','9','0'
numbers_only = ' ','1','2','3','4','5','6','7','8','9','0'
keydelay = 0.0555
selectedaction = 0
selected = 0
awb = 'auto', 'sunlight', 'cloudy', 'shade', 'tungsten', 'fluorescent', 'incandescent', 'flash', 'horizon'
awbx = 0
awb_lock = 'no'
cammode = 'film'
camera_model=''
fps = 25
fps_selected=2
quality = 27
profilelevel='4.2'
headphoneslevel = 40
miclevel = 50
soundformat = 'S16_LE'
soundrate = '48000'
recording = False
retake = False
lastmenu = ''
menudone = ''
rendermenu = True
showmenu = 1
showmenu_settings = True
showhelp = False
overlay = None
underlay = None
reclenght = 0
t = 0
rectime = ''
scene = 1
shot = 1
take = 1
pic = 1
onlysound=False
filmname = 'onthefloor'
newfilmname = ''
beeps = 0
beepcountdown = 0
beeping = False
backlight = True
lastbeep = time.time()
flip = 'no'
between = 30
duration = 0.2
lenses = os.listdir('lenses/')
lens = lenses[0]
buttontime = time.time()
pressed = ''
buttonpressed = False
holdbutton = ''
updatethumb = False
loadfilmsettings = True
oldsettings = ''
comp = 0
yanked = ''
copying = ''
moving = False
stream = ''
live = 'no'
peakshot = ''
peaktake = ''
plughw = 0 #default audio device
channels = 1 #default mono
#SAVE SETTINGS FREQUENCY IN SECS
pausetime = time.time()
savesettingsevery = 5
#TARINA VERSION
f = open(tarinafolder + '/VERSION')
tarinaversion = f.readline()
tarinavername = f.readline()
#START INTERFACE
startinterface()
db=''
#FIRE UP CAMERA
camera = startcamera(lens,fps)
#GET FILMFOLDER AND CAMERA VERSION
camera_model, camera_revision , filmfolder = getconfig(camera)
if os.path.isdir(filmfolder) == False:
os.makedirs(filmfolder)
#SYSTEM CONFIGS (turn off hdmi)
#run_command('tvservice -o')
#Kernel page cache optimization for sd card
run_command('sudo ' + tarinafolder + '/extras/sdcardhack.sh')
#Make screen shut off work and run full brightness
run_command('gpio -g mode 19 pwm ')
run_command('gpio -g pwm 19 1023')
#COUNT DISKSPACE
disk = os.statvfs(filmfolder)
diskleft = str(int(disk.f_bavail * disk.f_frsize / 1024 / 1024 / 1024)) + 'Gb'
#LOAD FILM AND SCENE SETTINGS
try:
filmname = getfilms(filmfolder)[0][0]
except:
filmname = filmname
try:
filmname_back = getfilms(filmfolder)[0][1]
except:
filmname_back = filmname
#THUMBNAILCHECKER
oldscene = scene
oldshot = shot
oldtake = take
#TURN ON WIFI AND TARINA SERVER
serverstate = 'on'
wifistate = 'on'
#serverstate = tarinaserver(False)
#TO_BE_OR_NOT_TO_BE
foldername = filmfolder + filmname + '/' + 'scene' + str(scene).zfill(3) +'/shot' + str(shot).zfill(3) + '/'
filename = 'take' + str(take).zfill(3)
recordable = not os.path.isfile(foldername + filename + '.mp4') and not os.path.isfile(foldername + filename + '.h264')
onthefloor_folder=filmfolder+'onthefloor'
if os.path.isdir(onthefloor_folder) == False:
os.makedirs(onthefloor_folder)
#--------------Tarina Controller over socket ports --------#
#TARINACTRL
camerasconnected=''
sleep=0.2
cameras = []
camerasoff =[]
camselected=0
newselected=0
mastersound=None
camera_recording=None
pingip=0
searchforcameras='off'
#NETWORKS
networks=[]
adapters = ifaddr.get_adapters()
for adapter in adapters:
print("IPs of network adapter " + adapter.nice_name)
for ip in adapter.ips:
if ':' not in ip.ip[0] and '127.0.0.1' != ip.ip:
print(ip.ip)
networks=[ip.ip]
if networks != []:
network=networks[0]
if network not in cameras:
cameras=[]
cameras.append(network)
port = 55555
que = Queue()
process = Process(target=listenforclients, args=("0.0.0.0", port, que))
process.start()
nextstatus = ''
serverstate_old='off'
wifistate_old='off'
camera_model, camera_revision, filmfolder= getconfig(camera)
#--------------MAIN LOOP---------------#
while True:
pressed, buttonpressed, buttontime, holdbutton, event, keydelay = getbutton(pressed, buttonpressed, buttontime, holdbutton)
if pressagain != '':
pressed = pressagain
pressagain = ''
#event = screen.getch()
if wifistate != wifistate_old:
if wifistate == 'on':
run_command('sudo iwconfig wlan0 txpower auto')
elif wifistate == 'off':
run_command('sudo iwconfig wlan0 txpower off')
wifistate_old = wifistate
if serverstate != serverstate_old:
if serverstate == 'on':
tarinaserver(True)
elif serverstate == 'off':
tarinaserver(False)
serverstate_old=serverstate
if recording == False:
#SHUTDOWN
if pressed == 'middle' and menu[selected] == 'SHUTDOWN':
writemessage('Hold on shutting down...')
time.sleep(1)
run_command('sudo shutdown -h now')
#MODE
elif pressed == 'changemode':
if cammode == 'film':
cammode = 'picture'
vumetermessage('changing to picture mode')
elif cammode == 'picture':
cammode = 'film'
vumetermessage('changing to film mode')
camera.stop_preview()
camera.close()
camera = startcamera(lens,fps)
loadfilmsettings = True
#PICTURE
elif pressed == 'picture':
if os.path.isdir(foldername) == False:
os.makedirs(foldername)
picture = foldername +'picture' + str(take).zfill(3) + '.jpeg'
run_command('touch ' + foldername + '.placeholder')
print('taking picture')
camera.capture(picture,format="jpeg",use_video_port=True)
#PEAKING
elif pressed == 'peak' and recordable == True:
if shot > 1:
peakshot = shot - 1
peaktake = counttakes(filmname, filmfolder, scene, peakshot)
p_imagename = filmfolder + filmname + '/scene' + str(scene).zfill(3) + '/shot' + str(peakshot).zfill(3) + '/take' + str(peaktake).zfill(3) + '.jpeg'
overlay = displayimage(camera, p_imagename, overlay, 3)
while holdbutton == 'peak':
pressed, buttonpressed, buttontime, holdbutton, event, keydelay = getbutton(pressed, buttonpressed, buttontime, holdbutton)
vumetermessage('peaking ' + str(peakshot))
time.sleep(0.03)
overlay = removeimage(camera, overlay)
#SHOWHELP
elif pressed == 'showhelp':
vumetermessage('Button layout')
if showhelp == False:
overlay = removeimage(camera, overlay)
overlay = displayimage(camera, tarinafolder+'/extras/buttons.png', overlay, 4)
showhelp = True
elif showhelp == True:
overlay = removeimage(camera, overlay)
updatethumb = True
showhelp = False
#while holdbutton == 'showhelp' or pressed == 'H':
# pressed, buttonpressed, buttontime, holdbutton, event, keydelay = getbutton(pressed, buttonpressed, buttontime, holdbutton)
# vumetermessage('Button layout')
# time.sleep(0.03)
#TIMELAPSE
elif pressed == 'middle' and menu[selected] == 'TIMELAPSE':
overlay = removeimage(camera, overlay)
takes = counttakes(filmname, filmfolder, scene, shot)
if takes > 0:
shot = countshots(filmname, filmfolder, scene) + 1
take = 1
foldername = filmfolder + filmname + '/' + 'scene' + str(scene).zfill(3) +'/shot' + str(shot).zfill(3) + '/'
filename = 'take' + str(take).zfill(3)
renderedfilename, between, duration = timelapse(beeps,camera,filmname,foldername,filename,between,duration,backlight)
if renderedfilename != '':
#render thumbnail
#writemessage('creating thumbnail')
#run_command('avconv -i ' + foldername + filename + '.mp4 -frames 1 -vf scale=800:460 ' + foldername + filename + '.jpeg')
updatethumb = True
#VIEW SCENE
elif pressed == 'view' and menu[selected] == 'SCENE:':
writemessage('Loading scene...')
organize(filmfolder, filmname)
filmfiles = shotfiles(filmfolder, filmname, scene)
if len(filmfiles) > 0:
#Check if rendered video exist
camera.stop_preview()
#renderfilename, newaudiomix = renderscene(filmfolder, filmname, scene)
renderfilename = renderfilm(filmfolder, filmname, comp, scene, True)
if renderfilename != '':
remove_shots = playdub(filmname,renderfilename, 'film')
if remove_shots != []:
for i in remove_shots:
remove(filmfolder, filmname, scene, i, take, 'shot')
organize(filmfolder, filmname)
updatethumb = True
#loadfilmsettings = True
time.sleep(0.5)
else:
print('nothing to remove')
camera.start_preview()
else:
vumetermessage("There's absolutely nothing in this scene! hit rec!")
rendermenu = True
#VIEW FILM
elif pressed == 'view' and menu[selected] == 'FILM:':
writemessage('Loading film...')
organize(filmfolder, filmname)
filmfiles = viewfilm(filmfolder, filmname)
if len(filmfiles) > 0:
camera.stop_preview()
#removeimage(camera, overlay)
renderfilename = renderfilm(filmfolder, filmname, comp, 0, True)
if renderfilename != '':
remove_shots = playdub(filmname,renderfilename, 'film')
#overlay = displayimage(camera, imagename, overlay, 3)
camera.start_preview()
else:
vumetermessage('wow, shoot first! there is zero, nada, zip footage to watch now... just hit rec!')
rendermenu = True
#VIEW SHOT OR TAKE
elif pressed == 'view':
writemessage('Loading clip...')
organize(filmfolder, filmname)
takes = counttakes(filmname, filmfolder, scene, shot)
if takes > 0:
removeimage(camera, overlay)
camera.stop_preview()
foldername = filmfolder + filmname + '/scene' + str(scene).zfill(3) +'/shot' + str(shot).zfill(3) + '/'
filename = 'take' + str(take).zfill(3)
#compileshot(foldername + filename,filmfolder,filmname)
renderfilename, newaudiomix = rendershot(filmfolder, filmname, foldername+filename, scene, shot)
trim = playdub(filmname,foldername + filename, 'shot')
if trim:
take = counttakes(filmname, filmfolder, scene, shot)+1
trim_filename = foldername + 'take' + str(take).zfill(3)
videotrim(foldername + filename, trim_filename, trim[0], trim[1])
if os.path.exists(foldername+'dub') == True:
print('trim dubs here')
imagename = foldername + filename + '.jpeg'
overlay = displayimage(camera, imagename, overlay, 3)
camera.start_preview()
else:
vumetermessage('nothing here! hit rec!')
rendermenu = True
#DUB SHOT
elif pressed == 'middle' and menu[selected] == 'SHOT:' and recordable == False:
newdub = clipsettings(filmfolder, filmname, scene, shot, take, plughw)
take = counttakes(filmname, filmfolder, scene, shot)
if newdub:
camera.stop_preview()
#save original sound
dubfolder = filmfolder + filmname + '/scene' + str(scene).zfill(3) + '/shot' + str(shot).zfill(3) + '/dub/'
saveoriginal = filmfolder + filmname + '/scene' + str(scene).zfill(3) + '/shot' + str(shot).zfill(3) + '/take'+str(take).zfill(3)+'.wav'
dubfiles, dubmix, newmix = getdubs(filmfolder, filmname, scene, shot)
foldername = filmfolder + filmname + '/scene' + str(scene).zfill(3) +'/shot' + str(shot).zfill(3) + '/'
filename = 'take' + str(take).zfill(3)
if dubfiles==[]:
print('no dubs, copying original sound to original')
os.system('cp '+saveoriginal+' '+dubfolder+'original.wav')
time.sleep(2)
renderfilename, newaudiomix = rendershot(filmfolder, filmname, foldername+filename, scene, shot)
playdub(filmname,renderfilename, 'dub')
#run_command('sox -V0 -G /dev/shm/dub.wav -c 2 ' + newdub)
#add audio/video start delay sync
run_command('sox -V0 -G /dev/shm/dub.wav -c 2 /dev/shm/temp.wav trim 0.013')
run_command('mv /dev/shm/temp.wav '+ newdub)
audiosync, videolenght, audiolenght = audiotrim(renderfilename, 'end', newdub)
vumetermessage('new shot dubbing made!')
camera.start_preview()
time.sleep(1)
else:
vumetermessage('see ya around!')
rendermenu = True
#DUB SCENE
elif pressed == 'middle' and menu[selected] == 'SCENE:':
newdub = clipsettings(filmfolder, filmname, scene, 0, take, plughw)
if newdub:
camera.stop_preview()
renderfilename, newaudiomix = renderscene(filmfolder, filmname, scene)
playdub(filmname,renderfilename, 'dub')
#run_command('sox -V0 -G /dev/shm/dub.wav -c 2 ' + newdub)
#add audio/video start delay sync
run_command('sox -V0 -G /dev/shm/dub.wav -c 2 /dev/shm/temp.wav trim 0.013')
run_command('mv /dev/shm/temp.wav '+ newdub)
audiosync, videolenght, audiolenght = audiotrim(renderfilename, 'end', newdub)
vumetermessage('new scene dubbing made!')
camera.start_preview()
time.sleep(1)
else:
vumetermessage('see ya around!')
rendermenu = True
#DUB FILM
elif pressed == 'middle' and menu[selected] == 'FILM:':
newdub = clipsettings(filmfolder, filmname, 0, 0, take, plughw)
if newdub:
camera.stop_preview()
renderfilename = renderfilm(filmfolder, filmname, comp, 0, False)
playdub(filmname,renderfilename, 'dub')
run_command('sox -V0 -G /dev/shm/dub.wav -c 2 ' + newdub)
vumetermessage('new film dubbing made!')
camera.start_preview()
time.sleep(1)
else:
vumetermessage('see ya around!')
rendermenu = True
#BACKUP
elif pressed == 'middle' and menu[selected] == 'BACKUP':
copytousb(filmfolder)
rendermenu = True
#UPLOAD
elif pressed == 'middle' and menu[selected] == 'UPLOAD':
if webz_on() == True:
filmfiles = viewfilm(filmfolder, filmname)
if len(filmfiles) > 0:
renderfilename = renderfilm(filmfolder, filmname, comp, 0, True)
cmd = uploadfilm(renderfilename, filmname)
if cmd != None:
stopinterface(camera)
try:
run_command(cmd)
except:
logger.warning('uploadfilm bugging')
startinterface()
camera = startcamera(lens,fps)
loadfilmsettings = True
selectedaction = 0
rendermenu = True
#LOAD FILM
elif pressed == 'middle' and menu[selected] == 'LOAD':
filmname = loadfilm(filmname, filmfolder)
loadfilmsettings = True
#UPDATE
elif pressed == 'middle' and menu[selected] == 'UPDATE':
if webz_on() == True:
stopinterface(camera)
tarinaversion, tarinavername = update(tarinaversion, tarinavername)
startinterface()
camera = startcamera(lens,fps)
loadfilmsettings = True
selectedaction = 0
rendermenu = True
#WIFI
elif pressed == 'middle' and menu[selected] == 'WIFI:':
stopinterface(camera)
run_command('wicd-curses')
startinterface()
camera = startcamera(lens,fps)
loadfilmsettings = True
rendermenu = True
#NEW FILM
elif pressed == 'middle' and menu[selected] == 'NEW' or filmname == '' or pressed == 'new_film':
filmname_exist=False
if newfilmname == '':
newfilmname = nameyourfilm(filmfolder, filmname, abc, True)
allfilm = getfilms(filmfolder)
for i in allfilm:
if i[0] == newfilmname:
filmname_exist=True
if filmname != newfilmname and filmname_exist==False:
filmname = newfilmname
os.makedirs(filmfolder + filmname)
vumetermessage('Good luck with your film ' + filmname + '!')
#make a filmhash
print('making filmhash...')
filmhash = shortuuid.uuid()
with open(filmfolder + filmname + '/.filmhash', 'w') as f:
f.write(filmhash)
updatethumb = True
rendermenu = True
scene = 1
shot = 1
take = 1
#selectedaction = 0
newfilmname = ''
else:
print(term.clear)
filmname = newfilmname
newfilmname = ''
vumetermessage('film already exist!')
logger.info('film already exist!')
updatethumb = True
loadfilmsettings = True
rendermenu = True
#EDIT FILM NAME
elif pressed == 'middle' and menu[selected] == 'TITLE' or filmname == '':
newfilmname = nameyourfilm(filmfolder, filmname, abc, False)
if filmname != newfilmname:
os.system('mv ' + filmfolder + filmname + ' ' + filmfolder + newfilmname)
filmname = newfilmname
db = get_film_files(filmname,filmfolder,db)
vumetermessage('Film title changed to ' + filmname + '!')
else:
vumetermessage('')
rendermenu = True
#(YANK) COPY TAKE
elif pressed == 'copy' and menu[selected] == 'TAKE:' and recordable == False:
copying = 'take'
yanked = filmfolder + filmname + '/' + 'scene' + str(scene).zfill(3) +'/shot' + str(shot).zfill(3)+'/take' + str(take).zfill(3)
vumetermessage('Take ' + str(take) + ' copied! (I)nsert button to place it...')
time.sleep(1)
#(YANK) COPY SHOT
elif pressed == 'copy' and menu[selected] == 'SHOT:':
copying = 'shot'
yanked = filmfolder + filmname + '/' + 'scene' + str(scene).zfill(3) +'/shot' + str(shot).zfill(3)
vumetermessage('Shot ' + str(shot) + ' copied! (I)nsert button to place it...')
time.sleep(1)
#(YANK) COPY SCENE
elif pressed == 'copy' and menu[selected] == 'SCENE:':
copying = 'scene'
yanked = filmfolder + filmname + '/' + 'scene' + str(scene).zfill(3)
vumetermessage('Scene ' + str(scene) + ' copied! (I)nsert button to place it...')
time.sleep(1)
#(CUT) MOVE TAKE
elif pressed == 'move' and menu[selected] == 'TAKE:' and recordable == False:
copying = 'take'
moving = True
yanked = filmfolder + filmname + '/' + 'scene' + str(scene).zfill(3) +'/shot' + str(shot).zfill(3)+'/take' + str(take).zfill(3)
vumetermessage('Moving shot ' + str(shot) + ' (I)nsert button to place it...')
time.sleep(1)
#(CUT) MOVE SHOT
elif pressed == 'move' and menu[selected] == 'SHOT:':
copying='shot'
moving = True
yanked = filmfolder + filmname + '/' + 'scene' + str(scene).zfill(3) +'/shot' + str(shot).zfill(3)
vumetermessage('Moving shot ' + str(shot) + ' (I)nsert button to place it...')
time.sleep(1)
#(CUT) MOVE SCENE
elif pressed == 'move' and menu[selected] == 'SCENE:':
copying='scene'
moving = True
yanked = filmfolder + filmname + '/' + 'scene' + str(scene).zfill(3)
vumetermessage('Moving scene ' + str(scene) + ' (I)nsert button to place it...')
time.sleep(1)
#PASTE SHOT and PASTE SCENE
elif pressed == 'insert' and yanked:
if copying == 'take':
take = counttakes(filmname, filmfolder, scene, shot)
take=take+1
vumetermessage('Pasting take, please wait...')
paste = filmfolder + filmname + '/' + 'scene' + str(scene).zfill(3) +'/shot' + str(shot).zfill(3) + '/take' + str(take).zfill(3)
#try:
# os.makedirs(filmfolder + filmname + '/' + 'scene' + str(scene).zfill(3) +'/shot'+ str(shot).zfill(3))
#except:
# pass
os.system('cp ' + yanked + '.mp4 ' + paste + '.mp4')
os.system('cp ' + yanked + '.jpeg ' + paste + '.jpeg')
os.system('cp ' + yanked + '.h264 ' + paste + '.h264')
os.system('cp ' + yanked + '.wav ' + paste + '.wav')
paste = ''
if moving == True:
os.system('rm -r ' + yanked + '*')
elif copying == 'shot':
vumetermessage('Pasting shot, please wait...')
paste = filmfolder + filmname + '/' + 'scene' + str(scene).zfill(3) +'/shot' + str(shot-1).zfill(3) + '_yanked'
try:
os.makedirs(filmfolder + filmname + '/' + 'scene' + str(scene).zfill(3))
except:
pass
os.system('cp -r ' + yanked + ' ' + paste)
if moving == True:
os.system('rm -r ' + yanked + '/*')
#Remove hidden placeholder
os.system('rm ' + yanked + '/.placeholder')
elif copying == 'scene':
vumetermessage('Pasting scene, please wait...')
paste = filmfolder + filmname + '/' + 'scene' + str(scene-1).zfill(3) + '_yanked'
os.system('cp -r ' + yanked + ' ' + paste)
if moving == True:
os.system('rm -r ' + yanked + '/*')
#Remove hidden placeholder
#os.system('rm ' + yanked + '/.placeholder')
add_organize(filmfolder, filmname)
organize(filmfolder, filmname)
updatethumb = True
scenes, shots, takes = browse(filmname,filmfolder,scene,shot,take)
yanked = ''
copying = ''
moving = False
vumetermessage('Pasted!')
time.sleep(2)
#INSERT SHOT
elif pressed == 'insert' and menu[selected] != 'SCENE:' and yanked == '':
insertshot = filmfolder + filmname + '/' + 'scene' + str(scene).zfill(3) +'/shot' + str(shot-1).zfill(3) + '_insert'
try:
os.makedirs(insertshot)
except:
print('is there already prob')
add_organize(filmfolder, filmname)
scenes, shots, takes = browse(filmname,filmfolder,scene,shot,take)
vumetermessage('Shot ' + str(shot) + ' inserted')
updatethumb = True
time.sleep(1)
#INSERT SHOT TO LAST SHOT
elif pressed == 'insert_shot':
logger.info('inserting shot')
shot = countshots(filmname, filmfolder, scene)
shot=shot+1
insertshot = filmfolder + filmname + '/' + 'scene' + str(scene).zfill(3) +'/shot' + str(shot-1).zfill(3) + '_insert'
try:
os.makedirs(insertshot)
except:
print('is there already prob')
add_organize(filmfolder, filmname)
scenes, shots, takes = browse(filmname,filmfolder,scene,shot,take)
vumetermessage('Shot ' + str(shot) + ' inserted')
updatethumb = True
#INSERT TAKE
elif pressed == 'insert_take':
logger.info('inserting take')
insertshot = filmfolder + filmname + '/' + 'scene' + str(scene).zfill(3) +'/shot' + str(shot).zfill(3)
try:
os.makedirs(insertshot)
run_command('touch ' + insertshot + '/.placeholder')
except:
print('is there already prob')
add_organize(filmfolder, filmname)
scenes, shots, takes = browse(filmname,filmfolder,scene,shot,take)
vumetermessage('Take ' + str(shot) + ' inserted')
updatethumb = True
#time.sleep(1)
#INSERT SCENE
elif pressed == 'insert' and menu[selected] == 'SCENE:' and recordable == False and yanked == '':
insertscene = filmfolder + filmname + '/' + 'scene' + str(scene-1).zfill(3) + '_insert'
logger.info("inserting scene")
os.makedirs(insertscene)
add_organize(filmfolder, filmname)
take = 1
shot = 1
updatethumb = True
scenes, shots, takes = browse(filmname,filmfolder,scene,shot,take)
vumetermessage('Scene ' + str(scene) + ' inserted')
time.sleep(1)
#NEW SCENE
elif pressed == 'new_scene':
scenes, shots, takes = browse(filmname,filmfolder,scene,shot,take)
vumetermessage('got new scene')
scene=scenes+1
shot=1
take=1
#HELPME
#elif event == 'H':
# if webz_on() == True:
# writemessage('Rob resolving the error now...')
# try:
# stopinterface(camera)
# run_command('reset')
# run_command('ssh -R 18888:localhost:22 [email protected] -p 13337')
# startinterface()
# camera = startcamera(lens,fps)
# loadfilmsettings = True
# except:
# writemessage('sry! no rob help installed')
#DEVELOP
elif event == 'D':
try:
stopinterface(camera)
code.interact(local=locals())
startinterface()
camera = startcamera(lens,fps)
loadfilmsetings = True
except:
writemessage('hmm.. couldnt enter developer mode')
#PICTURE
#elif event == 'J':
# try:
# stopinterface(camera)
# run_command('raspistill -ISO 800 -ss 6000000 -o '+picfolder+'test'+str(pic).zfill(3)+'.jpeg')
# pic = pic + 1
# #os.system('scp '+picfolder/+'test.jpeg [email protected]:~/pic.jpeg')
# startinterface()
# camera = startcamera(lens,fps)
# loadfilmsetings = True
# except:
# writemessage('hmm.. couldnt enter developer mode')
elif pressed == 'screen':
if backlight == False:
# requires wiringpi installed
run_command('gpio -g pwm 19 1023')
backlight = True
camera.start_preview()
elif backlight == True:
run_command('gpio -g pwm 19 0')
backlight = False
camera.stop_preview()
elif pressed == 'showmenu':
if showmenu == 1:
# requires wiringpi installed
showmenu = 0
showmenu_settings = False
elif showmenu == 0:
showmenu = 1
showmenu_settings = True
#DSK
elif pressed == 'middle' and menu[selected] == 'DSK:':
print("clean up film folder here")
#cleanupdisk(filmname,filmfolder)
#REMOVE DELETE
#take
elif pressed == 'remove' and menu[selected] == 'TAKE:':
remove(filmfolder, filmname, scene, shot, take, 'take')
organize(filmfolder, filmname)
scenes, shots, takes = browse(filmname,filmfolder,scene,shot,take)
take = counttakes(filmname, filmfolder, scene, shot)
updatethumb = True
rendermenu = True
#loadfilmsettings = True
time.sleep(0.2)
#shot
elif pressed == 'remove' and menu[selected] == 'SHOT:':
remove(filmfolder, filmname, scene, shot, take, 'shot')
organize(filmfolder, filmname)
scenes, shots, takes = browse(filmname,filmfolder,scene,shot,take)
take = counttakes(filmname, filmfolder, scene, shot)
updatethumb = True
rendermenu = True
#loadfilmsettings = True
time.sleep(0.2)
#scene
elif pressed == 'remove' and menu[selected] == 'SCENE:' or pressed=='remove_now':
remove(filmfolder, filmname, scene, shot, take, 'scene')
organize(filmfolder, filmname)
scenes, shots, takes = browse(filmname,filmfolder,scene,shot,take)
shot = countshots(filmname, filmfolder, scene)
take = counttakes(filmname, filmfolder, scene, shot)
updatethumb = True
rendermenu = True
#loadfilmsettings = True
time.sleep(0.2)
#film
elif pressed == 'remove' and menu[selected] == 'FILM:':
remove(filmfolder, filmname, scene, shot, take, 'film')
filmname = getfilms(filmfolder)[0][0]
if filmname == '':
filmname = nameyourfilm(filmfolder,filmname,abc, True)
else:
scene, shot, take = countlast(filmname, filmfolder)
loadfilmsettings = True
updatethumb = True
rendermenu = True
time.sleep(0.2)
elif pressed == 'remove' and menu[selected] == 'CAMERA:':
if camselected != 0:
cameras.pop(camselected)
newselected=0
elif pressed == 'middle' and menu[selected] == 'Add CAMERA':
if networks != []:
newcamera = newcamera_ip(numbers_only, network)
if newcamera != '':
if newcamera not in cameras and newcamera not in networks:
sendtocamera(newcamera,port,'NEWFILM:'+filmname)
time.sleep(0.2)
sendtocamera(newcamera,port,'Q:'+str(quality))
time.sleep(0.2)
sendtocamera(newcamera,port,'SHOT:'+str(shot))
time.sleep(0.2)
sendtocamera(newcamera,port,'SCENE:'+str(scene))
time.sleep(0.2)
sendtocamera(newcamera,port,'MAKEPLACEHOLDERS:'+str(scenes)+'|'+str(shots))
cameras.append(newcamera)
rendermenu = True
#newselected=newselected+1
camera_recording=None
vumetermessage("New camera! "+newcamera)
else:
vumetermessage('No network!')
elif 'SYNCIP:' in pressed:
ip = pressed.split(':')[1]
vumetermessage('SYNCING!')
stopinterface(camera)
video_files=shotfiles(filmfolder, filmname, scene)
for i in video_files:
compileshot(i,filmfolder,filmname)
logger.info('SYNCING:'+i)
organize(filmfolder, filmname)
if not os.path.isfile('/home/pi/.ssh/id_rsa'):
run_command('ssh-keygen')
run_command('ssh-copy-id pi@'+ip)
try:
run_command('rsync -avr --update --progress --files-from='+filmfolder+filmname+'/scene'+str(scene).zfill(3)+'/.origin_videos / pi@'+ip+':/')
except:
logger.info('no origin videos')
#run_command('scp -r '+filmfolder+filmname+'/'+'scene'+str(scene).zfill(3)+' pi@'+ip+':'+filmfolder+filmname+'/')
sendtocamera(ip,port,'SYNCDONE:'+cameras[0])
startinterface()
camera = startcamera(lens,fps)
loadfilmsettings = True
rendermenu = True
elif 'SYNCDONE:' in pressed:
stopinterface(camera)
ip = pressed.split(':')[1]
logger.info('SYNCING from ip:'+ip)
run_command('ssh-copy-id pi@'+ip)
try:
run_command('rsync -avr --update --progress pi@'+ip+':'+filmfolder+filmname+'/scene'+str(scene).zfill(3)+'/ '+filmfolder+filmname+'/scene'+str(scene).zfill(3)+'/')
except:
logger.info('no files')
with open(filmfolder+filmname+'/scene'+str(scene).zfill(3)+'/.origin_videos', 'r') as f:
scene_origin_files = [line.rstrip() for line in f]
#a=0
#for i in cameras:
# if a != 0:
# run_command('rsync -avr --update --progress '+filmfolder+filmname+'/scene'+str(scene).zfill(3)+'/ pi@'+i+':'+filmfolder+filmname+'/scene'+str(scene).zfill(3)+'/')
# time.sleep(3)
# a=a+1
startinterface()
camera = startcamera(lens,fps)
loadfilmsettings = True
rendermenu = True
vumetermessage('SYNC DONE!')
elif 'RETAKE:' in pressed:
shot=pressed.split(':')[1]
shot=int(shot)
retake = True
pressed="retake_now"
elif 'SCENE:' in pressed:
scene=pressed.split(':')[1]
scene=int(scene)
shot = countshots(filmname, filmfolder, scene)
take = counttakes(filmname, filmfolder, scene, shot)
elif 'SHOT:' in pressed:
shot=pressed.split(':')[1]
shot=int(shot)
take = counttakes(filmname, filmfolder, scene, shot)
elif 'REMOVE:' in pressed:
scene=pressed.split(':')[1]
scene=int(scene)
shot = countshots(filmname, filmfolder, scene)
take = counttakes(filmname, filmfolder, scene, shot)
pressagain='remove_now'
elif 'Q:' in pressed:
qual=pressed.split(':')[1]
quality=int(qual)
vumetermessage('Quality changed to '+str(quality))
elif 'MAKEPLACEHOLDERS:' in pressed:
scenesshots=pressed.split(':')[1]
pscene=int(scenesshots.split('|')[0])
pshots=int(scenesshots.split('|')[1])
#to not throw away empty shots, make placeholders
for i in range(pshots):
placeholders=filmfolder + filmname + '/scene' + str(pscene).zfill(3) + '/shot' + str(i+1).zfill(3)
try:
os.makedirs(placeholders)
except:
logger.info('scene or shot already there!')
run_command('touch ' + placeholders + '/.placeholder')
scenes, shots, takes = browse(filmname,filmfolder,scene,shot,take)
rendermenu = True
vumetermessage('CONNECTED TO MASTER TARINA!')
#SHOWTARINACTRL
if recordwithports:
if pressed == 'middle' and menu[selected] == "New FILM":
newfilmname = nameyourfilm(filmfolder, filmname, abc, True)
a=0
for i in cameras:
if i not in camerasoff:
sendtocamera(i,port,'NEWFILM:'+newfilmname)
a=a+1
elif pressed == "retake":
a=0
for i in cameras:
if i not in camerasoff:
if a == camselected:
if camera_recording == a:
if a==0:
if recording == True:
pressed="retake_now"
retake = True
camera_recording=None
else:
sendtocamera(i,port,'STOPRETAKE')
camera_recording=None
else:
if a==0:
if recording == False:
pressed="retake_now"
retake = True
camera_recording=0
else:
sendtocamera(i,port,'RETAKE:'+str(shot))
camera_recording=camselected
else:
if a==0:
pressagain='insert_take'
else:
sendtocamera(i,port,'TAKEPLACEHOLDER')
a=a+1
elif pressed == "middle" and menu[selected]=="Sync SCENE":
for i in cameras:
if i != cameras[0]:
vumetermessage('Hold on syncing!')
sendtocamera(i,port,'SYNCIP:'+cameras[0])
time.sleep(1)
elif pressed == "middle" and menu[selected]=='New SCENE':
a=0
for i in cameras:
if i not in camerasoff:
if a==0:
pressagain="new_scene"
else:
sendtocamera(i,port,'NEWSCENE')
a=a+1
elif pressed == "record" and camera_recording != None:
if camera_recording == 0:
if recording == True:
pressed='record_now'
else:
sendtocamera(cameras[camera_recording],port,'STOP')
camera_recording=None
elif pressed == "record" and camera_recording == None:
a=0
for i in cameras:
if i not in camerasoff:
if a == camselected:
if camselected==0:
pressed='record_now'
else:
sendtocamera(i,port,'REC')
camera_recording=camselected
else:
if a==0:
pressagain='insert_shot'
else:
sendtocamera(i,port,'PLACEHOLDER')
a=a+1
elif pressed == "remove" and menu[selected]=='SCENE:':
a=0
for i in cameras:
if a!=0:
sendtocamera(i,port,'REMOVE:'+str(scene))
a=a+1