LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-10-2013, 06:03 AM   #1
elliotjreed
LQ Newbie
 
Registered: Jul 2013
Location: Nottingham, United Kingdom
Distribution: Arch Linux, Ubuntu Linux
Posts: 4

Rep: Reputation: Disabled
Question BASH script to record webcam & save in defined directory, stop recording then repeat?


Hi! First go on LQ so I'm hoping someone can help. Basically I want to record a webcam stream with a given filename set as a variable ($USERINPUTNUM), stop that recording when a user enters a number (eg. 123456) and hits enter, then begin recording again under the new number they've entered (eg. 678910). Here's what I've got so far, but the user has to Ctrl+C out of it first - I just need them to be able to enter the new number followed by Enter to stop the previous recording and start the next.

Any ideas? Here's the script so far... (quite new to this just to warn!):

Code:
#!/bin/bash
while true
do

YELLOW="\033[1;33m"
BLUE="\033[1;34m"
ENDCOLOUR="\033[0m"
TIMESTAMP=$(date +"%Y.%m.%d_%H.%M")

read -p "Scan your barcode and get packing: " USERINPUTNUM

echo -e $YELLOW"Saving order process..."$ENDCOLOUR

avconv -f video4linux2 -r 3 -fs 52428800 -i /dev/video0 /home/$USER/records/$TIMESTAMP-$USERINPUTNUM.avi 

echo -e $BLUE"Video recording complete, keep going!"$ENDCOLOUR

done
Thanks

Last edited by elliotjreed; 07-10-2013 at 06:04 AM. Reason: Error in code
 
Old 07-10-2013, 09:06 AM   #2
elliotjreed
LQ Newbie
 
Registered: Jul 2013
Location: Nottingham, United Kingdom
Distribution: Arch Linux, Ubuntu Linux
Posts: 4

Original Poster
Rep: Reputation: Disabled
Sorted! Did:

Code:
#!/bin/bash

stop() { [ $CPID -ne 0 ] && kill -INT $CPID && wait $CPID && echo "Killed $CPID"; }

trap "stop; exit" INT

CPID=0
while :; do
  read -p "Please scan your order barcode, and scan the next when complete: " USERINPUTNUM
  stop
  [ "$USERINPUTNUM" == quit ] && break;
  TIMESTAMP=$(date +"%Y.%m.%d_%H.%M")
  avconv -f video4linux2 -r 3 -fs 52428800 -i /dev/video0 /home/$USER/orders/$TIMESTAMP-$USERINPUTNUM.avi > /dev/null 2>&1 &
  CPID=$!
done
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem : Recording video & audio from webcam remstereo Linux - Software 2 11-23-2010 03:58 PM
BASH Script --> read a file & cp -r to my ~/ directory manwithaplan Linux - Newbie 6 10-05-2009 11:25 PM
Bash script to rename photos in directory & all subdirectories shy_guest Linux - Software 7 09-02-2009 01:40 PM
Bash script to rename photos in directory & all subdirectories shy_guest Linux - Software 2 09-02-2009 05:53 AM
Bash script to rename photos in directory & all subdirectories shy_guest Linux - Software 1 09-02-2009 05:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration