Part 1 : I am running a Python script using cv2 to save the video from a webcam to a pendrive.
import cv2,os
dypa = ('/media/pi/PSYCH') #specify the absolute output path here
fnam1 = 'output.avi' #specify the output file name here
fnam2 = 'output1.avi'
dypa1 = os.path.join(dypa,fnam1)
dypa2 = os.path.join(dypa, fnam2)
if __name__ == "__main__":
# find the webcam
capture = cv2.VideoCapture(0)
capture1 = capture
# video recorder
fourcc = cv2.cv.CV_FOURCC(*'XVID')
videoOut = cv2.VideoWriter(dypa1, fourcc, 10.0, (640, 480))
videoOut1 = cv2.VideoWriter(dypa2, fourcc, 10.0, (640, 480))
# record video
while (capture.isOpened() and capture1.isOpened()):
ret, frame = capture.read()
ret1, frame1 = capture1.read()
if ret:
videoOut.write(frame)
else:
break
if ret1:
frame1 = cv2.flip(frame1,1)
videoOut1.write(frame1)
else:
break
# Tiny Pause
key = cv2.waitKey(1)
capture1.release()
videoOut1.release()
capture.release()
videoOut.release()
cv2.destroyAllWindows()
I managed to do that if I know the name of the pendrive ("/media/pi/PSYCH"). But then I put the command in a bash file
sudo nano /etc/rc.local
and added
sudo python /home/pi/Desktop/TheCode.py
so that it executes on startup.
When I reboot then there still exists a
/media/pi/PSYCH
but is now not accessible and the pendrive is now at
/media/pi/PSYCH1
. Next reboot and it's at /media/pi/PSYCH2 and so on.
PS : I am using a Rasberry Pi 3 with Raspbian Jessie