gonzopi

git clone https://git.tarina.org/gonzopi
Log | Files | Refs | README | LICENSE

commit 6e793b8b9bb5ef3091427a9efd7f9880cc1e0d88
parent 38e71e856dafd15c04a4e20b54eadd316de9cc56
Author: rob <rob@tarina.org>
Date:   Wed, 22 Nov 2023 12:09:02 +0200

Merge branch 'master' of https://git.tarina.org/gonzopi

Diffstat:
Aextras/gonzopi.conf | 33+++++++++++++++++++++++++++++++++
Dextras/tarinaretake.conf | 34----------------------------------
Mgonzopi.py | 107++++++++++++++++++++++++++++++++++++++++++++++---------------------------------
Minstall.sh | 7+++----
Rsrv/tarinaserver.py -> srv/gonzopiserver.py | 0
5 files changed, 99 insertions(+), 82 deletions(-)

diff --git a/extras/gonzopi.conf b/extras/gonzopi.conf @@ -0,0 +1,33 @@ +<VirtualHost *:80> + WSGIScriptAlias / /home/pi/gonzopi/srv/gonzopiserver.py + WSGIPassAuthorization On + AddType text/html .py + Alias /static /home/pi/gonzopi/srv/static + <Directory /> + Options FollowSymLinks + AllowOverride None + </Directory> + <Directory /home/pi/srv> + Options Indexes FollowSymLinks MultiViews + AllowOverride None + Order allow,deny + allow from all + </Directory> + + ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ + <Directory "/usr/lib/cgi-bin"> + AllowOverride None + Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch + Order allow,deny + Allow from all + </Directory> + + ErrorLog ${APACHE_LOG_DIR}/error.log + + # Possible values include: debug, info, notice, warn, error, crit, + # alert, emerg. + LogLevel warn + + CustomLog ${APACHE_LOG_DIR}/access.log combined + +</VirtualHost> diff --git a/extras/tarinaretake.conf b/extras/tarinaretake.conf @@ -1,34 +0,0 @@ -<VirtualHost *:80> - ServerAdmin info@tarina.org - WSGIScriptAlias / /home/pi/tarinaretake/srv/tarinaserver.py - WSGIPassAuthorization On - AddType text/html .py - Alias /static /home/pi/tarinaretake/srv/static - <Directory /> - Options FollowSymLinks - AllowOverride None - </Directory> - <Directory /home/pi/srv> - Options Indexes FollowSymLinks MultiViews - AllowOverride None - Order allow,deny - allow from all - </Directory> - - ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ - <Directory "/usr/lib/cgi-bin"> - AllowOverride None - Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch - Order allow,deny - Allow from all - </Directory> - - ErrorLog ${APACHE_LOG_DIR}/error.log - - # Possible values include: debug, info, notice, warn, error, crit, - # alert, emerg. - LogLevel warn - - CustomLog ${APACHE_LOG_DIR}/access.log combined - -</VirtualHost> diff --git a/gonzopi.py b/gonzopi.py @@ -109,7 +109,8 @@ def main(): cammode = 'film' camera_model='' fps = 25 - fps_selected=2 + fps_selected=8 + fps_selection=[] quality = 27 profilelevel='4.2' headphoneslevel = 40 @@ -1157,7 +1158,7 @@ def main(): if onlysound != True: camera.start_recording(filmfolder+ '.videos/'+video_origins+'.h264', format='h264', quality=quality, level=profilelevel) starttime = time.time() - os.system('ln -s '+filmfolder+'.videos/'+video_origins+'.h264 '+foldername+filename+'.h264') + os.system('ln -sfr '+filmfolder+'.videos/'+video_origins+'.h264 '+foldername+filename+'.h264') recording = True showmenu = 0 if cammode == 'picture': @@ -1419,12 +1420,10 @@ def main(): if channels == 1: channels = 2 elif menu[selected] == 'FPS:': - if camera_model == 'imx477': - if fps_selected < len(fps_selection)-1: - fps_selected+=1 - fps_selection=[5,8,10,11,12,13,14,15,24.985,35,49] - fps=fps_selection[fps_selected] - camera.framerate = fps + if fps_selected < len(fps_selection)-1: + fps_selected+=1 + fps=fps_selection[fps_selected] + camera.framerate = fps elif menu[selected] == 'Q:': if quality < 39: quality += 1 @@ -1584,12 +1583,10 @@ def main(): if channels == 2: channels = 1 elif menu[selected] == 'FPS:': - if camera_model == 'imx477': - if fps_selected > 0: - fps_selected-=1 - fps_selection=[5,8,10,11,12,13,14,15,24.985,35,49] - fps=fps_selection[fps_selected] - camera.framerate = fps + if fps_selected > 0: + fps_selected-=1 + fps=fps_selection[fps_selected] + camera.framerate = fps elif menu[selected] == 'Q:': if quality > 10: quality -= 1 @@ -1634,9 +1631,9 @@ def main(): quality = filmsettings[18] #wifistate = filmsettings[19] #serverstate=filmsettings[20] - plughw=filmsettings[21] + #plughw=filmsettings[21] channels=filmsettings[22] - cammode=filmsettings[23] + #cammode=filmsettings[23] scene=filmsettings[24] shot=filmsettings[25] take=filmsettings[26] @@ -3080,7 +3077,7 @@ def compileshot(filename,filmfolder,filmname): os.system('rm ' + video_origins + '.mp4') print(filename+'.mp4 removed!') run_command('MP4Box -fps 25 -add ' + video_origins + '.h264 ' + video_origins + '.mp4') - os.system('ln -sf '+video_origins+'.mp4 '+filename+'.mp4') + os.system('ln -sfr '+video_origins+'.mp4 '+filename+'.mp4') if not os.path.isfile(filename + '.wav'): audiosilence('',filename) #add audio/video start delay sync @@ -3114,7 +3111,7 @@ def compileshot(filename,filmfolder,filmname): os.system('rm ' + video_origins + '.h264') os.system('rm ' + filename + '.h264') os.system('rm /dev/shm/temp.wav') - os.system('ln -sf '+video_origins+'.mp4 '+filename+'.mp4') + os.system('ln -sfr '+video_origins+'.mp4 '+filename+'.mp4') logger.info('compile done!') #run_command('omxplayer --layer 3 ' + filmfolder + '/.rendered/' + filename + '.mp4 &') #time.sleep(0.8) @@ -3264,24 +3261,29 @@ def rendershot(filmfolder, filmname, renderfilename, scene, shot): #Video videohash = '' oldvideohash = '' + scenedir = filmfolder + filmname + '/scene' + str(scene).zfill(3) + '/shot' + str(shot).zfill(3) + '/' #take = counttakes(filmname, filmfolder, scene, shot) #renderfilename = filmfolder + filmname + '/scene' + str(scene).zfill(3) + '/shot' + str(shot).zfill(3) + '/take' + str(take).zfill(3) #return if no file # Video Hash - #if something shutdown in middle of process - if os.path.isfile(renderfilename + '_tmp.mp4') == True: - os.system('cp ' + renderfilename + '_tmp.mp4 ' + renderfilename + '.mp4') if os.path.isfile(renderfilename + '.h264') == True: compileshot(renderfilename,filmfolder,filmname) - if os.path.isfile(renderfilename + '.mp4') == True: + audiohash = str(int(countsize(renderfilename + '.wav'))) + with open(scenedir + '.audiohash', 'w') as f: + f.write(audiohash) + #if something shutdown in middle of process + elif os.path.isfile(renderfilename + '_tmp.mp4') == True: + os.system('cp ' + renderfilename + '_tmp.mp4 ' + renderfilename + '.mp4') + elif os.path.isfile(renderfilename + '.mp4') == True: videohash = videohash + str(int(countsize(renderfilename + '.mp4'))) + video_origins = (os.path.realpath(renderfilename+'.mp4'))[:-4] print('Videohash of shot is: ' + videohash) + #time.sleep(3) else: vumetermessage('Nothing here to play hit record') return '', '' #if os.path.isfile(renderfilename + '.h264') and os.path.isfile(renderfilename + '.mp4'): # os.system('rm ' + renderfilename + '.h264 ') - scenedir = filmfolder + filmname + '/scene' + str(scene).zfill(3) + '/shot' + str(shot).zfill(3) + '/' # Check if video corrupt renderfix = False if os.path.isfile(renderfilename + '.jpeg') == False: @@ -3296,7 +3298,8 @@ def rendershot(filmfolder, filmname, renderfilename, scene, shot): print('Okey, shot file not found or is corrupted') # For backwards compatibility remove old rendered scene files # run_command('rm ' + renderfilename + '*') - renderfix = True + return '', '' + #renderfix = True try: with open(scenedir + '.videohash', 'r') as f: oldvideohash = f.readline().strip() @@ -3323,6 +3326,8 @@ def rendershot(filmfolder, filmname, renderfilename, scene, shot): with open(scenedir + '.audiohash', 'w') as f: f.write(audiohash) if audiohash != oldaudiohash or newmix == True or renderfix == True: + print('rerendering') + #time.sleep(3) #make scene rerender os.system('touch '+filmfolder + filmname + '/scene' + str(scene).zfill(3)+'/.rerender') #copy original sound @@ -3342,13 +3347,9 @@ def rendershot(filmfolder, filmname, renderfilename, scene, shot): #muxing mp3 layer to mp4 file #count estimated audio filesize with a bitrate of 320 kb/s audiosize = countsize(renderfilename + '.wav') * 0.453 - os.system('mv ' + renderfilename + '.mp4 ' + renderfilename + '_tmp.mp4') - if debianversion == 'stretch': - p = Popen(['avconv', '-y', '-i', renderfilename + '.wav', '-acodec', 'libmp3lame', '-ac', '2', '-b:a', '320k', renderfilename + '.mp3']) - else: - p = Popen(['ffmpeg', '-y', '-i', renderfilename + '.wav', '-acodec', 'libmp3lame', '-ac', '2', '-b:a', '320k', renderfilename + '.mp3']) + p = Popen(['ffmpeg', '-y', '-i', renderfilename + '.wav', '-acodec', 'libmp3lame', '-ac', '2', '-b:a', '320k', renderfilename + '.mp3']) while p.poll() is None: - time.sleep(0.02) + time.sleep(0.2) try: rendersize = countsize(renderfilename + '.mp3') except: @@ -3357,13 +3358,19 @@ def rendershot(filmfolder, filmname, renderfilename, scene, shot): ##MERGE AUDIO & VIDEO writemessage('Merging audio & video') #os.remove(renderfilename + '.mp4') - call(['MP4Box', '-rem', '2', renderfilename + '_tmp.mp4'], shell=False) - call(['MP4Box', '-add', renderfilename + '_tmp.mp4', '-add', renderfilename + '.mp3', '-new', renderfilename + '.mp4'], shell=False) + call(['MP4Box', '-rem', '2', video_origins + '.mp4'], shell=False) + call(['MP4Box', '-fps', '25', '-add', video_origins + '.mp4', '-add', renderfilename + '.mp3', '-new', video_origins + '_tmp.mp4'], shell=False) + os.system('cp -f ' + video_origins + '_tmp.mp4 ' + video_origins + '.mp4') try: - os.remove(renderfilename + '_tmp.mp4') + os.remove(video_origins + '_tmp.mp4') os.remove(renderfilename + '.mp3') except: - print('nothin to remove') + print('nothing to remove') + #origin=os.path.realpath(renderfilename+'.mp4') + #os.system('rm ' + filename + '.h264') + #os.system('rm /dev/shm/temp.wav') + #os.system('ln -sfr '+video_origins+'.mp4 '+filename+'.mp4') + logger.info('compile done!') else: print('Already rendered!') return renderfilename, newaudiomix @@ -4304,9 +4311,10 @@ def copytousb(filmfolder): holdbutton = '' writemessage('Searching for usb storage device, middlebutton to cancel') films = getfilms(filmfolder) + usbmount = 0 while True: pressed, buttonpressed, buttontime, holdbutton, event, keydelay = getbutton(pressed, buttonpressed, buttontime, holdbutton) - usbconnected = os.path.ismount('/media/usb0') + usbconnected = os.path.ismount('/media/usb'+str(usbmount)) if pressed == 'middle': writemessage('canceling..') time.sleep(2) @@ -4319,7 +4327,7 @@ def copytousb(filmfolder): except: pass try: - p = subprocess.check_output('stat -f -c %T /media/usb0', shell=True) + p = subprocess.check_output('stat -f -c %T /media/usb'+str(usbmount), shell=True) filesystem = p.decode() print('filesystem info: ' + filesystem) except: @@ -4330,6 +4338,7 @@ def copytousb(filmfolder): #check filmhash filmname = filmname[0] usbpath = '/media/usb0/gonzopifilms/'+filmname + usbvideopath = '/media/usb0/gonzopifilms/.videos/' usbfilmhash = '' filmhash = '' while True: @@ -4361,18 +4370,21 @@ def copytousb(filmfolder): except: writemessage('Found existing ' + filmname + ', copying new files... ') try: - run_command('rsync -avr -P ' + filmfolder + filmname + ' ' + usbpath) + run_command('rsync -avr -P ' + filmfolder + filmname + '/ ' + usbpath) + run_command('rsync -avr -P ' + filmfolder + '.videos/ ' + usbvideopath) except: writemessage('couldnt copy film ' + filmname) waitforanykey() return run_command('sync') - run_command('pumount /media/usb0') writemessage('all files copied successfully!') waitforanykey() + run_command('pumount /media/usb0') writemessage('You can safely unplug the usb device now') time.sleep(2) return + else: + usbmount = usbmount + 1 #-----------Check for the webz--------- @@ -4759,7 +4771,7 @@ def stopinterface(camera): print('no camera to close') os.system('pkill arecord') os.system('pkill startinterface') - os.system('pkill gonzopigui') + os.system('pkill tarinagui') #run_command('sudo systemctl stop apache2') return camera @@ -4798,13 +4810,20 @@ def startcamera(lens, fps): # if there's more frames then the video will be longer when converting it to 25 fps, # I try to get it as perfect as possible with trial and error. # ov5647 Rev C - if camera_revision == 'rev.C': - camera.framerate = 26.03 + if camera_revision == 'rev.C': + #camera.framerate = 26.03 + fps_selection=[5,8,10,11,12,13,14,15,26.03,35,49] + fps=fps_selection[fps_selected] + camera.framerate = fps # ov5647 Rev D" if camera_revision == 'rev.D': - camera.framerate = 23.15 + #camera.framerate = 23.15 + fps_selection=[5,8,10,11,12,13,14,15,23.15,35,49] + fps=fps_selection[fps_selected] + camera.framerate = fps elif camera_model == 'imx477': - fps_selection=[5,15,24.985,35,49] + #fps_selection=[5,15,24.985,35,49] + fps_selection=[5,8,10,11,12,13,14,15,24.985,35,49] fps=fps_selection[fps_selected] camera.framerate = fps else: @@ -4842,5 +4861,5 @@ if __name__ == '__main__': except: os.system('pkill arecord') os.system('pkill startinterface') - os.system('pkill gonzopigui') + os.system('pkill tarinagui') print('Unexpected error : ', sys.exc_info()[0], sys.exc_info()[1]) diff --git a/install.sh b/install.sh @@ -70,6 +70,7 @@ echo "installing picamerax with lens shading correction..." sudo pip3 install --upgrade picamerax echo "installing web.py for the gonzopi webserver..." sudo pip3 install web.py==0.61 + if [ "$screen" = "ugeek-hdtft" ] then echo "installing ugeek screen drivers" @@ -153,15 +154,14 @@ enable_dpi_lcd=1 display_default_lcd=1 display_rotate=1 dpi_group=2 -hdmi_group=2 +hdmi_group=3 dpi_mode=87 dpi_output_format=0x7f216 hdmi_timings=480 0 10 16 59 800 0 15 113 15 0 0 0 60 0 32000000 6 #--------GonzoPi configuration end here--------- EOF - -if [ "$screen" = "hdmi-screen" ] +elif [ "$screen" = "hdmi-screen" ] then echo "configuring hdmi screen" echo "GonzoPi configuration seems to be in order in /boot/config.txt" @@ -188,7 +188,6 @@ hdmi_group=1 hdmi_mode=3 #--------GonzoPi configuration end here--------- EOF - else echo "screen driver already there, to change it remove gonzopi config in /boot/config.txt" fi diff --git a/srv/tarinaserver.py b/srv/gonzopiserver.py