LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices

Reply
 
Search this Thread
Old 12-05-2012, 02:52 PM   #1
XXLRay
Member
 
Registered: May 2010
Posts: 117

Rep: Reputation: 16
How to reduce mencoder cpu load against frame drops


I use mencoder to record my old VHS tapes from a USB video grabber. Unfortunately the CPU loads is such high that I loose frames. Until now I tried the following command:

Code:
mencoder tv:// -tv driver=v4l2:width=720:height=576:outfmt=uyvy:device=/dev/video0:input=1:fps=25:alsa:adevice=plughw.1,0:audiorate=48000:amode=1:forceaudio:immediatemode=0 -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=8000:vbitrate=5000:keyint=15:acodec=ac3:abitrate=192:aspect=4/3 -o test.mpg
Is there a way to reduce the compression rate such that no more frames get lost? I could use ffmpeg afterwards to achieve better compression.
 
Old 12-06-2012, 11:54 PM   #2
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Gentoo
Posts: 15,438
Blog Entries: 2

Rep: Reputation: 4001Reputation: 4001Reputation: 4001Reputation: 4001Reputation: 4001Reputation: 4001Reputation: 4001Reputation: 4001Reputation: 4001Reputation: 4001Reputation: 4001
You should record it without compression at all and in a second pass use ffmpeg to compress it. MPEG is a lossy format, so further compressing an already compressed video will exponentially decrease quality.
 
Old 12-07-2012, 01:35 AM   #3
XXLRay
Member
 
Registered: May 2010
Posts: 117

Original Poster
Rep: Reputation: 16
Thank you for the answer but what would be the command to record the stream without compression?
 
Old 12-07-2012, 05:02 AM   #4
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Gentoo
Posts: 15,438
Blog Entries: 2

Rep: Reputation: 4001Reputation: 4001Reputation: 4001Reputation: 4001Reputation: 4001Reputation: 4001Reputation: 4001Reputation: 4001Reputation: 4001Reputation: 4001Reputation: 4001
As audio codec use pcm, as video codec use raw as container format use avi instead of mpeg.
I am not a mencoder user and have not the possibilities to test it, I got that info from this site: http://www.mplayerhq.hu/DOCS/HTML/en...ing-codec.html
 
1 members found this post helpful.
Old 12-07-2012, 05:53 AM   #5
XXLRay
Member
 
Registered: May 2010
Posts: 117

Original Poster
Rep: Reputation: 16
So the command would be something like:
Code:
mencoder tv:// -tv driver=v4l2:width=720:height=576:outfmt=uyvy:device=/dev/video0:input=1:fps=25:alsa:adevice=plughw.1,0:audiorate=48000:amode=1:forceaudio:immediatemode=0 -oac pcm -ovc raw -of avi -o test.mpg
right?
 
Old 12-07-2012, 06:20 AM   #6
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Gentoo
Posts: 15,438
Blog Entries: 2

Rep: Reputation: 4001Reputation: 4001Reputation: 4001Reputation: 4001Reputation: 4001Reputation: 4001Reputation: 4001Reputation: 4001Reputation: 4001Reputation: 4001Reputation: 4001
The option should be -o test.avi, of course. As stated before, I don't have the possibility to test that, so just give it a test run and see what happens.
 
Old 12-07-2012, 07:44 AM   #7
XXLRay
Member
 
Registered: May 2010
Posts: 117

Original Poster
Rep: Reputation: 16
Ooops might have worked anyway but thank you for the hint. I will try this when I am back to the depending machine.
 
Old 12-08-2012, 04:45 PM   #8
teckk
Senior Member
 
Registered: Oct 2004
Distribution: FreeBSD Arch
Posts: 1,752

Rep: Reputation: 188Reputation: 188
Frames get skipped because the input and output framerates don't match. Is that what you mean?
fps=25 that's input fps, I don't see a -ofps 25
If that's a NTSC recording it should be 24.98 or 2400/10001

Is the video teleclined or interlaced?
http://www.mplayerhq.hu/DOCS/HTML/en...g4-interlacing

100% CPU load won't cause skipped frames. It's a mismatch.
 
Old 12-08-2012, 04:58 PM   #9
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Gentoo
Posts: 15,438
Blog Entries: 2

Rep: Reputation: 4001Reputation: 4001Reputation: 4001Reputation: 4001Reputation: 4001Reputation: 4001Reputation: 4001Reputation: 4001Reputation: 4001Reputation: 4001Reputation: 4001
Quote:
Originally Posted by teckk View Post
100% CPU load won't cause skipped frames. It's a mismatch.
Sure about that? The input is a video-grabber device, so if the CPU si to slow to do real time encoding, wouldn't that cause skipped frames?
 
Old 12-09-2012, 02:15 PM   #10
teckk
Senior Member
 
Registered: Oct 2004
Distribution: FreeBSD Arch
Posts: 1,752

Rep: Reputation: 188Reputation: 188
I don't think so. I think that mencoder will encode as fast as the CPU, codec etc will allow. If there are more frames than it can handle you get a buffer overrun error.
I would like to know more from the OP what the actual skipping message from mencoder is.

I took that 1st post to mean that mencoder was complaining about skipped frames.
This video grabber gets the video full speed from the VHS player and doesn't buffer it?
And mencoder can't keep up with the codec selected? Maybe increasing the cache would help.

If that is the case then why not dump the stream to file, then encode it later?
Something like
Code:
mplayer tv:// -tv driver=v4l2:width=720...etc -dumpstream -dumpfile outputfile
Then encode outfile however you want.
 
1 members found this post helpful.
Old 12-10-2012, 12:36 PM   #11
XXLRay
Member
 
Registered: May 2010
Posts: 117

Original Poster
Rep: Reputation: 16
I tried the following command:
Code:
 mencoder tv:// -tv driver=v4l2:width=720:height=576:outfmt=uyvy:device=/dev/video2:input=1:fps=25:alsa:adevice=plughw.1,0:audiorate=48000:amode=1:forceaudio:immediatemode=0 -oac pcm -ovc raw -of avi -o test.avi
Unfortunately there was no audio and CPU load caused by mencoder was 60%. mencoder regularly was stuck below 20fps. That migth be because I have a VIA Board with single core C7 1,5Ghz CPU for which driver support is not outrageous.

I also wanted to try the command that teckk posted but I was not sure what exactly to put for the "etc".

The problem is that mencoder says "video buffer full - dropping frame" even if I set buffersize=1024 which is the maximum. The resulting video is really stuck at certain images for some time.

The USB grabber I use is a Logilink VG0001 with STK1160 chipset which is a rather cheap one.

I was able to successfully encode he video on my other PC that has a quadcore Intel i5 2.5Ghz where CPU load was about 23% (including mp4 encoding an de-interlacing filter). Nevertheless I am still interested in a solution how to achieve the same result on my VIA PC although this is not an urgent issue any more.
 
Old 12-10-2012, 02:31 PM   #12
teckk
Senior Member
 
Registered: Oct 2004
Distribution: FreeBSD Arch
Posts: 1,752

Rep: Reputation: 188Reputation: 188
Quote:
CPU load caused by mencoder was 60%. mencoder regularly was stuck below 20fps.
60% CPU load with mencoder isn't a heavy load. I encode with two cores running at 99%.
The 20 fps is all the faster that machine will encode with the codec and parameters that you have selected, not a problem, that's all the faster that it will go.

Quote:
says "video buffer full - dropping frame"
That's the problem. I've had that before. I don't know how that capture device that you are using works. The VHS tape runs at one speed so I suspect that you have to get it all as it streams.

I can't direct you step by step here. Too many variables. You'll have to research it.

1. Are you using the same line on the faster machine? If so can you copy the video and audio on the slower machine using mencoder?
Code:
mencoder tv:// -tv driver=v4l2:width=720:height=576:outfmt=uyvy:device=/dev/video2:input=1:fps=25:alsa:adevice=plughw.1,0:audiorate=48000:amode=1:forceaudio:immediatemode=0 -oac copy -ovc copy  -o outoutfile
Then take outfile re-encode it and do what you want with it.


2. What line do you use to play the tv:// with mplayer? Does this worK?
Code:
mplayer tv:// -tv driver=v4l2:width=720:height=576:outfmt=uyvy:device=/dev/video2:input=1:fps=25:alsa:adevice=plughw.1,0:audiorate=48000:amode=1:forceaudio:immediatemode=0
Find out how to play the tv:// with mplayer then you can dump the stream to file.
Code:
mplayer tv:// -tv driver=v4l2:width=720:height=576........-dumpstream -dumpfile outputfile
Then take outputfile and do what you want with it.

The idea is to stop trying to encode on the fly. Dump it to file first. Then encode the file.

Last edited by teckk; 12-10-2012 at 02:32 PM.
 
Old 12-14-2012, 01:44 PM   #13
XXLRay
Member
 
Registered: May 2010
Posts: 117

Original Poster
Rep: Reputation: 16
I tried the following command to watch the grabber output on the, let's call it slow, computer:
Code:
$ mplayer tv:// -tv driver=v4l2:width=720:height=576:outfmt=uyvy:device=/dev/video0:input=1:fps=25:alsa:amode=1:forcechan=2:audiorate=48000:adevice=plughw.1,0:forceaudio:immediatemode=0:buffersize=64
but even that let the video lag. Thus I think there is no chance for this machine. Nevertheless dumping the output on the fast machine did not work either (although recording is fine):
Code:
$ mplayer tv:// -tv driver=v4l2:width=720:height=576:outfmt=uyvy:device=/dev/video0:input=1:fps=25:alsa:amode=1:forcechan=2:audiorate=48000:adevice=plughw.1,0:forceaudio:immediatemode=0:buffersize=64 -dumpstream -dumpfile test.dmp
MPlayer svn r34540 (Ubuntu), built with gcc-4.6 (C) 2000-2012 MPlayer Team
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.

Playing tv://.
dump: 0 bytes written to 'test.dmp'.
Core dumped ;)
 
Old 12-14-2012, 02:40 PM   #14
teckk
Senior Member
 
Registered: Oct 2004
Distribution: FreeBSD Arch
Posts: 1,752

Rep: Reputation: 188Reputation: 188
Quote:
but even that let the video lag
Because your machine is not capable of playing the video. The idea is to dump to file without watching the video. (single core C7 1,5Ghz CPU)

You can always try and watch it later with something like
Code:
mplayer -lavdopts skiploopfilter=all video.avi
or
Code:
-lavdopts skipframe=nonref:skiploopfilter=all:fast=1
And or push the d key while playing the video to enable framedrop.

The -oac copy and -ovc copy with mencoder should pass the video/audio right through.
See post 12.
 
  


Reply


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
does killing child processes help reduce CPU load average?? expeliarmus Linux - Software 2 08-02-2007 02:12 AM
does killing child processes reduce CPU load average?? expeliarmus Linux - General 2 08-02-2007 12:43 AM
does killing child processes reduce CPU load average?? expeliarmus Programming 1 08-02-2007 12:19 AM
share cpu time and reduce process load sailu_mvn Linux - Software 3 03-09-2006 06:20 PM


All times are GMT -5. The time now is 09:00 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration