LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 03-16-2019, 12:55 PM   #1
äxl
Member
 
Registered: Feb 2013
Location: Germany, EU
Distribution: Debian (stable release)
Posts: 67

Rep: Reputation: 10
cpulimit spawns two ffmpeg instances


Hi,

I'm using Gnome Terminal 3.22.2 (bash).
I'm running this in one terminal:
Code:
$ cpulimit -e ffmpeg -l 25
In another terminal I'm running this:
Code:
$ ls
01.gif 02.gif 03.gif 04.gif
and then
Code:
$ for i in *.gif; do ffmpeg -i $i -b:v 2M $i.webm; done
But I see in yet another terminal (and hear from the fan) that the usage is too high for my old computer:
Code:
$ ps aux | grep -Ei ffmpeg
aexl     18242  0.1  0.0   8428  1544 pts/2    S+   17:51   0:00 cpulimit -e ffmpeg -c 1 -l 25
aexl     18259 40.0  2.1 657440 174284 pts/3   Tl   17:51   0:02 ffmpeg -i 01.gif -an -b:v 2M 01.gif.webm
aexl     18270 92.0  1.6 618004 137208 pts/3   Rl+  17:51   0:02 ffmpeg -i 02.gif -an -b:v 2M 02.gif.webm
Usage varies between 40 and 110 percent which sometimes accumulates to 170%.

What am I doing wrong?

(It works if I create a ffmpeg.sh like this:
Code:
#!/bin/bash
[ -d "${1}" ] && FOLDER=$(dirname "${1}")
DATA=$(basename "${1}")
[ -f "${1}" ] && FOLDER=$(dirname "${1}")
cd "$FOLDER"
FILE="$DATA"

for FILE in *.gif; do
ffmpeg -i "$FILE" -b:v 2M "$FILE".webm
done
and then run:
Code:
$ ./ffmpeg.sh /media/Disk1/gifs/*
Now in another terminal:
Code:
$ ps aux | grep -Ei ffmpeg
aexl     21662  0.1  0.0   8428  1540 pts/2    S+   18:14   0:02 cpulimit -e ffmpeg -c 1 -l 50
aexl     27014  0.0  0.0  11188  3000 pts/3    S+   18:46   0:00 /bin/bash ./ffmpeggif.sh /media/Disk1/gifs/*
aexl     27016 53.2  2.1 661140 178948 pts/3   Tl+  18:46   0:06 ffmpeg -i 01.gif -b:v 2M 01.gif.webm
So this one instance of ffmpeg varies between 40 and 90% which is alright for my computer.
)

Last edited by äxl; 03-16-2019 at 05:43 PM.
 
Old 03-16-2019, 01:31 PM   #2
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Quote:
Originally Posted by äxl View Post
What am I doing wrong?
It's not cpulimit spawning two ffmpeg instances (per your title); you are starting two (actually three) instances, one in each terminal.
Quote:
I'm running this in one terminal:
Code:
$ cpulimit -e ffmpeg -l 25
In another terminal I'm running this:
Code:
$ for i in $i; do ffmpeg -i $i -b:v 2M $i.webm; done
which starts one instance, in pts/2 and loops through a file list starting instances in pts/3, causing, in your posted example, two instances at one time...not sure why it didn't start all four instances from the pty/3 commands.

Nor do I understand why you are starting one instance in pty/2 that's not doing anything at all.

Last edited by scasey; 03-16-2019 at 01:33 PM.
 
Old 03-16-2019, 01:36 PM   #3
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
here is a script I wrote for using cpulimit.
I have not used it in a while, but what i think it did was for each pid of command it would limit it to whatever percent given, as I do remember I was running something in a loop so when it would loop to the next item to process, this script would catch that pid for the same command then set the limit to it.

I gave it a three pass fail setup so if nothing after the 3rd pass looking for a pid it would then stop running. cpulimit throws its error messages, which I pay no attention to.

start cpulimit after the command is running.

Code:
#!/bin/bash

# requires cpulimit

 


[[ -z $1 ]] || [[ $# -ne '2' ]] && { echo "Usage bash limitcpu [command] [limit] #" ; exit 1 ; }

echo $1
echo $2
count=0

    pidd=$(pidof $1)
    pidd=${pidd%% *}
	echo "pid $pidd"
	cpulimit  -p $pidd -l $2 -z -i
while sleep 3;
do
	
	pidd=$(pidof $1)
	pidd=${pidd%% *} 
	cpulimit  -p $pidd -l $2 -z -i
	
	if [[ $count -eq '2' ]] && [[ -z "$pidd" ]] ; then
		{
		echo "Ran dry...
			exiting .....
			
			"
		exit
		}
		else
		{
		((count++))
		}
		fi
		[[ -n "$pidd" ]] && count=0
done
say if you are running a script that is using ffmpeg within it to process, then you'd start that script, then this script, citing the ./scriptname ffmpeg 20 after ffmpeg first starts pressing a file. This was cpulimint can finds its pid.

if I remember correctly It works if I was running multiple scripts using the same command.

I now use a different script to just limit my cpu overall temp. therefore eliminating the need for this script.

Last edited by BW-userx; 03-16-2019 at 02:18 PM.
 
Old 03-16-2019, 02:41 PM   #4
äxl
Member
 
Registered: Feb 2013
Location: Germany, EU
Distribution: Debian (stable release)
Posts: 67

Original Poster
Rep: Reputation: 10
@scasey: Please tell me why it's working with the script. And the pts/2 command is to monitor for ffmpeg instances. It should only limit the one process I'm running. This can even be done after the process is started as described in the man page's EXAMPLES:
http://manpages.ubuntu.com/manpages/...pulimit.1.html
(I didn't find any other "official" man page but this is similar to Debian's.)

@BW-userx: But I wanna know why it's not working with a simple for-loop. It's already working with a script. Thanks anyway.
 
Old 03-16-2019, 03:22 PM   #5
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
slap in a while loop in instead.
Code:
#!/bin/bash
#where the files are currently at
working_dir=
 #where ever you want your output to go
file_to=

while read f
do                     
ffmpeg -i "$f" -b:v 2M "$file_to"/"$f".webm
done <<<"$(find "$working_dir" -type f -iname "*.ext-goes-here")"
now you can run the script at a centralized location, and have the output go to whatever dir you want your final product. It keeps it separated, not tested so kinks maybe needed to be worked out of it first.

for loops are funny with dir structures

Last edited by BW-userx; 03-16-2019 at 03:27 PM.
 
Old 03-16-2019, 05:37 PM   #6
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
BW-userx seems to know more specifics than I so I'll defer to them, but I do have to wonder about this:
Code:
for i in $i; do something with $i...
...doesn't that change the value of the variable the loop is running over??
 
Old 03-16-2019, 05:45 PM   #7
äxl
Member
 
Registered: Feb 2013
Location: Germany, EU
Distribution: Debian (stable release)
Posts: 67

Original Poster
Rep: Reputation: 10
Quote:
Originally Posted by scasey View Post
BW-userx seems to know more specifics than I so I'll defer to them, but I do have to wonder about this:
Code:
for i in $i; do something with $i...
...doesn't that change the value of the variable the loop is running over??
Yes, sorry that was a typo. Corrected above.

But BW-userx's doesn't help me. I don't need another script. *I've got one that works already.* I just wanna know why it doesn't work as expected when I call it in a terminal via the for-loop ...

Last edited by äxl; 03-16-2019 at 06:04 PM.
 
Old 03-16-2019, 06:14 PM   #8
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Code:
for i in ./*.gif ; do echo "$i" ; done
 
Old 03-17-2019, 08:59 AM   #9
äxl
Member
 
Registered: Feb 2013
Location: Germany, EU
Distribution: Debian (stable release)
Posts: 67

Original Poster
Rep: Reputation: 10
That's not helpful. But I appreciate you trying.
 
  


Reply

Tags
bash, bash loop, ffmpeg, for loop, temperature



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
LXer: How to limit CPU usage with CPULimit on Ubuntu Linux LXer Syndicated Linux News 0 09-03-2014 09:41 PM
Opening a shell spawns infinite instances of it trainreq Linux - Software 1 01-10-2013 02:50 AM
Help cpulimit command fajarpri Programming 3 04-15-2012 06:01 AM
LXer: How To Limit CPU Usage Of A Process With cpulimit (Debian/Ubuntu) LXer Syndicated Linux News 0 09-14-2009 09:50 AM
segmentation fault when using cpulimit Adrianrob Linux - Software 1 07-23-2008 10:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:23 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