Buckets:
| """ | |
| python vnc2mp4.py vnc2mp4_46_4_104_218_5902_1.mp4 46.4.104.218::5902 18 ts | |
| python vnc2mp4.py "VNC_Recs/5_9_138_201_5904_$(date +%s)_2.mp4" 5.9.138.201::5904 2 $(date +%s) $(date +%s) 1>> Rec_logs/log.txt 2>>Rec_logs/err.txt | |
| python tst.py 1>Rec_logs/log.txt 2>Rec_logs/err.txt | |
| ffmpeg -framerate 1 -pattern_type glob -i 'VNC_Recs/IMGs_TMP/*28_071*.jpg' -c:v libx264 -pix_fmt yuv420p tst_ffmpeg_out.mp4 | |
| ffmpeg -framerate 1 -pattern_type glob -i 'VNC_Recs/IMGs_TMP/*.jpg' -c:v libx264 tst_ffmpeg_out.mp4 | |
| """ | |
| import sys, time, os, signal | |
| import numpy as np | |
| from PIL import Image, ImageDraw | |
| import cv2 | |
| from vncdotool import api | |
| import requests | |
| def p_chk(host,log,err): | |
| #print(host,log,err) | |
| #print("Checking port for", host) | |
| global p_chk_rtries | |
| print("Port chk retries", p_chk_rtries) | |
| try: | |
| #print(f"http://{host.split('::')[0]}:{host.split('::')[1]}") | |
| rsp=requests.get(f"http://{host.split('::')[0]}:{host.split('::')[1]}", timeout=30) | |
| os.system(f""" echo req done >> {log} """) | |
| print(rsp.status_code, rsp.text) | |
| except requests.exceptions.ConnectionError as e: | |
| if ('RFB' in str(e)): | |
| #op_ports.append(port) | |
| #print("Prt", port) | |
| #get_snap(ip,port) | |
| return True | |
| else: | |
| if p_chk_rtries<2: | |
| os.system(f""" echo "Port chk Exception {p_chk_rtries}: {str(e).replace('"',"'")}" >> {err} """) | |
| print(f""" echo "Port chk Exception {p_chk_rtries}: {str(e).replace('"',"'")}" >> {err} """) | |
| p_chk_rtries=p_chk_rtries+1 | |
| print("Sleeping") | |
| time.sleep(10) | |
| p_chk(host,log,err) | |
| else: | |
| #print(str(e)) | |
| os.system(f""" echo "Port chk Exception {p_chk_rtries}: {str(e).replace('"',"'")}" >> {err} """) | |
| print(f""" echo Port chk Exception {p_chk_rtries}: {str(e).replace('"',"'")} """) | |
| return False | |
| except Exception as e: | |
| os.system(f""" echo "Port chk Unknown Exception: {str(e).replace('"',"'")}" >> {err} """) | |
| print("Something Wrong",str(e)) | |
| return False | |
| #finally: | |
| # print(rsp.status_code, rsp.text) | |
| # return False | |
| def record(output,host,fps,ts,log,err,password=None): | |
| #print("Start")# Recording") | |
| os.system(f""" echo Start >> {log} """) | |
| pid = 0 | |
| retval = 0 | |
| global p_chk_rtries | |
| cli = api.connect(host,password=password) | |
| cli.timeout=10 | |
| if p_chk(host,log,err): | |
| cli.refreshScreen(False) | |
| else: | |
| os.system(f""" echo Not Active >> {log} """) | |
| raise KeyboardInterrupt | |
| os.system(f""" echo 0 > Rec_stats/st_file_{ts}.txt """) | |
| os.system(f""" echo Connected >> {log} """) | |
| videodims = cli.screen.size | |
| fourcc = cv2.VideoWriter_fourcc(*'mp4v') | |
| frame = int(fps) | |
| video = cv2.VideoWriter(output,fourcc, frame,videodims) | |
| p_start = time.time() | |
| try: | |
| def sigint_handler(sig, frame): | |
| raise KeyboardInterrupt | |
| signal.signal(signal.SIGINT, sigint_handler) | |
| try: | |
| cli.timeout=5 | |
| while 1: | |
| elapse = int() | |
| start = time.time() | |
| for i in range(0,frame): | |
| try: | |
| f_fetch_strt=time.time() | |
| cli.refreshScreen(False) | |
| p_chk_rtries=0 | |
| f_fetch_end=time.time() | |
| except TimeoutError: | |
| #""" | |
| if p_chk(host,log,err): | |
| #print("Timeout\t", end="") | |
| os.system(f""" echo Timeout >> {log} """) | |
| cli = api.connect(host,password=password) | |
| cli.timeout=5 | |
| continue | |
| else: | |
| #print("Dying for a reason....") | |
| os.system(f""" echo "Dying for a reason...." >> {log} """) | |
| #p_stop = time.time() | |
| #print(p_stop-p_start) | |
| #video.release() | |
| #cli.disconnect() | |
| #print("Stop Recording 0") | |
| exit() | |
| """ | |
| print("Timeout") | |
| cli = api.connect(host,password=password) | |
| cli.timeout=10 | |
| continue | |
| """ | |
| except Exception as e: | |
| os.system(f""" echo "Exception in frame fetch: {str(e).replace('"',"'")}" >> {err} """) | |
| continue | |
| #print("Scrn Refreshed in", f_fetch_end-f_fetch_strt, "secs") | |
| os.system(f""" echo Scrn Refreshed in {f_fetch_end-f_fetch_strt} secs >> {log} """) | |
| imtemp = cli.screen.copy() | |
| #print(type(imtemp)) | |
| #print("Got something") | |
| video.write(cv2.cvtColor(np.array(imtemp), cv2.COLOR_RGB2BGR)) | |
| #print("frame written") | |
| stop = time.time() | |
| elapse = stop-start | |
| #print(cli.connected, cli.timeout) | |
| #print("1 Sec Frames Processed in : " + str(elapse)) | |
| os.system(f""" echo 1 Sec Frames Processed in : {str(elapse)} >> {log} """) | |
| #print("Going for next frame..") | |
| #if elapse < 1: | |
| # time.sleep(1-elapse) | |
| except Exception as e: | |
| print("Excpetion",str(e)) | |
| os.system(f""" echo "Some Exception: {str(e).replace('"',"'")}" >> {err} """) | |
| finally: | |
| p_stop = time.time() | |
| os.system(f""" echo Completed process in {int(p_stop-p_start)} Secs >> {log} """) | |
| video.release() | |
| #print("Vid written") | |
| cli.disconnect() | |
| os.system(f""" echo Stopping Recording >> {log} """) | |
| #sys.exit() | |
| #print("Pid",pid) | |
| try: | |
| os.killpg(os.getpgid(pid), signal.SIGTERM) | |
| except Exception as e: | |
| print(str(e)) | |
| except KeyboardInterrupt: | |
| pass | |
| if pid: | |
| os.killpg(os.getpgid(pid), signal.SIGTERM) | |
| #return retval | |
| def main(args): | |
| # python3 vnc2mp4.py output.mp4 host:port fps password[OPTIONAL] | |
| if len(args) < 3: | |
| print("Missing parameters") | |
| sys.exit() | |
| else: | |
| output = args[0] | |
| host = args[1] | |
| fps = args[2] | |
| password = "trofacor" | |
| ts = args[3] | |
| f_ts = args[4] | |
| global p_chk_rtries | |
| p_chk_rtries = 0 | |
| log = f"Rec_logs/{f_ts}.log.txt" | |
| err = f"Rec_logs/{f_ts}.err.txt" | |
| #if len(args) == 4 : password=args[3] | |
| record(output=output,host=host,fps=fps,ts=ts,log=log,err=err,password=password) | |
| #if __name__ == "__main__": sys.exit(main(sys.argv[1:])) | |
| if __name__ == "__main__": | |
| main(sys.argv[1:]) |
Xet Storage Details
- Size:
- 7.08 kB
- Xet hash:
- eb81d54b931b1db57eb4bdd053e32e64d677c86823fd72ece8b3ec66f994f2c1
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.