You are not logged in.
Pages: 1
Hi all,
I need a bit of help looping a command on a bash script,
please see below the command I need to loop:
ffmpeg -s 2720x1024 -r 25 -f x11grab -i :0.0 -acodec libmp3lame -ab 128k -vcodec mpeg4 -sameq -y -t 60 /media/z/.cam/screen/screen_`date +%F_%T`.avi
So basically I record my screen for a period of 1 minutes and the process once done need to restart.
I have search on how to loop the command but I must admit it seem rather complicated, so for the time being I added && at the end and paste the command a lot...
Any help would be appreciated,
Many thanks,
Regards
Offline
Offline
No I do not have a ending conditions, basically I want it to run until the computer is switch off or the user is log out.
And I looked at it, and did some try but after few drinks I must be .....
Thanks for your help,
Offline
Right, I have read that but I cannot make it work with my command for some reason,
would you be kind enought to give me an example with my command?
Many thanks
Offline
would you be kind enought to give me an example with my command?
while true; do
ffmpeg -s 2720x1024 -r 25 -f x11grab -i :0.0 -acodec libmp3lame -ab 128k -vcodec mpeg4 -sameq -y -t 60 /media/z/.cam/screen/screen_`date +%F_%T`.avi
done
If that isn't working, you need to give us more information about exactly what you are experiencing, error messages etc.
Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline
Well I tried it but; it doesn't stop and create a new file every minute like the command demand.
It create a continues file instead.
P.s no error message.
Offline
Does the ffmpeg command by itself stop after 60 seconds? Try adding some debugging like an echo command before/after the ffmpeg inside the loop.
Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline
Just altered Fukawi's code.
Added a wait command
while true; do
ffmpeg -s 2720x1024 -r 25 -f x11grab -i :0.0 -acodec libmp3lame -ab 128k -vcodec mpeg4 -sameq -y -t 60 /media/z/.cam/screen/screen_`date +%F_%T`.avi
wait
done
Just add wait to it, will process the grab for a minute and then loop once more.
Only after the command has run completely that is.
Could be unnecessary but alas, I tried.
Last edited by 3]) (2011-03-14 09:00:28)
“There are two ways of constructing a software design. One way is to make it so simple that there are obviously no deficiencies. And the other way is to make it so complicated that there are no obvious deficiencies.”-- C.A.R. Hoare
Offline
It's unnecessary. From TFM:
Waits for the process identified by ID, which may be a process ID or a
job specification, and reports its termination status. If ID is not
given, waits for all currently active child processes, and the return
status is zero. If ID is a a job specification, waits for all processes
in the job's pipeline.
The key part being 'child processes'. There are no child processes. Execution blocks while ffmpeg runs, and then the loop continues. If this loop isn't doing what the OP requires, then I suspect the issue is with the invocation of ffmpeg.
Offline
while true;do ffmpeg -s 2720x1024 -r 25 -f x11grab -i :0.0 -acodec libmp3lame -ab 128k -vcodec mpeg4 -sameq -y -t 60 /media/z/.cam/screen/screen_`date +%F_%T`.avi;done;
Works for me, repeats every 60 seconds, creates a new file every 60 seconds.
Problem must be something else.
Offline
Sorry I wasn't around much lately,
I had a typing error, it work like a charm,
Edit: Only issue is that I can not close the process via a "pkill ffmpeg" - even the ctrl+c on the terminal while the script is working that doesn't stop it?
However if i launch the command on a terminal and then run the "pkill ffmpeg" on another it does stop, so I tried a "pkill desktop-test3.sh" (name of the script, but then again it doesn't stop..
Man many thanks for your help
Regards
Last edited by sweetthdevil (2011-03-23 10:18:25)
Offline
you might want a trap for that. Something like...
while true; do
ffmpeg -s 2720x1024 -r 25 -f x11grab -i :0.0 -acodec libmp3lame -ab 128k -vcodec mpeg4 -sameq -y -t 60 /media/z/.cam/screen/screen_$(date +%F_%T).avi &
pid=$!
trap "kill '$pid'; exit" 1 2 15
wait
done
Last edited by freak (2011-03-23 15:11:41)
Offline
so with that addition to the script what pkill command or other command should I use to terminate it?
Offline
so with that addition to the script what pkill command or other command should I use to terminate it?
I suggest, before you ask these questions, that you do a bit of experimentation. Try pkill ffmpeg. Did it work? Try pkill scriptname.sh - did it work? Put some effort in.
Offline
Sorry I should have mentioned it, I did try those two option without success...
pkill ffmpeg do not work what so ever, it just restart the process from the begining (i.e. starting a new record) but doing a pkill new.process work after 2 or 3 "pkill name.process" shouldn't it work the first time?
Offline
ffmpeg -s 2720x1024 -r 25 -f x11grab -i :0.0 -acodec libmp3lame -ab 128k -vcodec mpeg4 -sameq -y -t 60 /media/z/.cam/screen/screen_`date +%F_%T`.avi
I recommend using the FFmpeg commands shown here:
How to do Proper Screencasts on Linux Using FFmpeg
It's a well-written guide and the author, verb3k, keeps it up to date which is essential when working with FFmpeg. Compared to your command the output will probably look better. The command from the guide will also probably be closer to your requested frame rate because the lossless output should be easier for the CPU to deal with and the command utilizes the -threads option. Lastly, the -sameq option should not be used. The documentation is misleading and should read something like, "use same quantizer as source" instead of "use same video quality as source". Use of the same quantizer does not mean same quality, and this option especially should not be used when the source and output formats do not share the same quantizer scale.
Last edited by DrZaius (2011-03-27 00:31:46)
Offline
Pages: 1