Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 10-06-2014, 08:07 AM   #1
Registered: Sep 2008
Posts: 546

Rep: Reputation: 37
bash script to switch between video file and live camera

I'm running a centos 6 server (command line only) with ffmpeg and I want to create a script that will switch between a video file and live camera and back again.

what I've done already:
1) I have scripts for both the mp4 video and the live camera that will stream them to red5 server like so:
# etc/init.d/stream start <-- this streams the live cam to red5 media server and it works fine
# /etc/init.d/video start <-- this starts the mp4 video and does the same.
I've also done:
#/etc/init.d/mylist start <-- this starts a file called mylist.txt which plays a set of mp4's in sequence and stream them to red5 server. It works fine and mylist.txt contains this:
file 'video1.mp4'
file 'video2.mp4'
file 'video3.mp4'
the problem with mylist.txt is it only caters for files and I don't know if it's possible to syntax this file to play a live camera stream for a certain time.
All the above scripts work fine, I just need to work out a way to switch from one to the other. I have done a search on google but couldn't find any examples that did this. Thanks for any help.
Old 10-07-2014, 05:15 PM   #2
Senior Member
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
If all you need is a delay between switching from one command to the next you can use the sleep command but im not sure if thats what you are looking for.

So like
ffmpeg command to play video1.mp4
sleep 300 # Sleep for 5 minutes
ffmpeg command to play video2.mpy
sleep 300 # sleep for 5 minutes
This is a way simple solution and may not be what you are looking for, if its not let us know and can get into more technical scripting if needed.
Old 10-08-2014, 04:05 AM   #3
Registered: Sep 2008
Posts: 546

Original Poster
Rep: Reputation: 37
thankyou for that, I have tried something similar to your suggestion but it is not useable. I'm beginning to think that what I need may not be possible. I need to seamlessly switch from pre-recorded video to live camera and both of these streams go to red5 server like so:
live (web) camera - /dev/video0
# /root/bin/ffmpeg -f video4linux2 -i '/dev/video0' blah-de-blah...'rtmp://<red5-server>:1935/live/livestream1'"
video.mp4 file
# /root/bin/ffmpeg -i /path/to/video.mp4 blah-de-blah...'rtmp://<red5server>:1935/live/livestream1'"
Because both streams go out on port 1935 they can't both run at the same time. They could if I had a second red5 server on a different port but that wouldn't work because the player on the web pulls the stream via port 1935. Stopping one stream and then starting the next doesn't work because the video player (which is on a web page) doesn't cater for auto resume when the stream stops. So I need seamless immediate switching at the source of the video. I may have to go for a hardware solution. I have tried other solutions like LIVES and snowmix but I got nowhere with LIVES (I think it's an abandoned project) and I haven't been able to get past an install problem yet with snowmix.
sorry for the long-winded post

Last edited by tonj; 10-08-2014 at 04:07 AM.
Old 10-09-2014, 03:12 AM   #4
Senior Member
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
Maybe checkout Also a different tool but seems to suite.
Old 10-09-2014, 03:41 AM   #5
Registered: Sep 2008
Posts: 546

Original Poster
Rep: Reputation: 37
thankyou for that zhjim I'll check it out


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Live Video Streaming from a SBC with Camera or USB interface Linux - Software 1 03-30-2012 01:15 AM
[SOLVED] Bash script - switch on filecontent Kjanss Programming 3 10-11-2011 03:36 PM
Switch user in a bash script bribon Programming 7 07-29-2011 10:33 AM
Switch statement for bash script wjs1990 Linux - Newbie 7 11-20-2009 12:37 AM
need the code for capturing the live video from the camera to the pc in linux pavankumar Programming 1 04-29-2006 06:48 AM > Forums > Linux Forums > Linux - Software

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

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