View previous topic :: View next topic |
Author |
Message |
pahud Tux's lil' helper
Joined: 26 Nov 2002 Posts: 103
|
Posted: Wed Mar 05, 2003 3:37 am Post subject: realtime video capture and DivX/XviD encoding |
|
|
Is there anyone ever trying to capture the video/audio from
TV card or webcam device and encode the stream into divx/xvid
on-the-fly?
What is your software/hardware spec and what is your
divx/xvid quality(resolution and bitrate,etc.)
Any experience is highly welcome. |
|
Back to top |
|
|
rew n00b
Joined: 28 Aug 2002 Posts: 47 Location: Oregon
|
Posted: Wed Mar 05, 2003 10:25 pm Post subject: Not doing this right now. |
|
|
But I have done stuff like it in the past. Look into the program vcr, i think it can encode mpeg-4 and if that doesnt work, i know mplayer/mencoder can. - Andrew _________________ linux-2.4.20 i686 SMP
Tyan Tiger MP
Dual Athlon MP 1600+
512MB EEC (1/4)
PNY Verto 64MB - GeForce4 MX 420
'Cheep-ass NIC, CDRW & DVD' |
|
Back to top |
|
|
commanderfoxtrot n00b
Joined: 07 Dec 2002 Posts: 40 Location: University of Durham, UK
|
Posted: Wed Mar 05, 2003 11:57 pm Post subject: |
|
|
This is an FAQ.
Look up nuvrec/nvrec, vcr, transcode and mencoder.
Personally I would advise mencoder as the easiest for you to set up. Record to MJPEG first unless you have the CPU power for MPEG4. ffmpeg's MPEG4 implementation is fastest. |
|
Back to top |
|
|
thinair Tux's lil' helper
Joined: 01 Nov 2002 Posts: 144 Location: Suisse
|
|
Back to top |
|
|
Sastraxi Apprentice
Joined: 25 Feb 2003 Posts: 258
|
Posted: Thu Mar 06, 2003 4:25 am Post subject: |
|
|
Is NVRec that one with the dynamic framedropping? I always wanted to try that, but the compile NEVER worked in any other linux OS. Maybe it will work in Gentoo (is there an ebuild?) |
|
Back to top |
|
|
Robelix l33t
Joined: 21 Jul 2002 Posts: 760 Location: in a World created by a Flying Spaghetti Monster
|
Posted: Sun Mar 09, 2003 8:50 pm Post subject: |
|
|
A (long) thread that may be interesting for you:
https://forums.gentoo.org/viewtopic.php?t=12286 _________________ mysql> SELECT question FROM life, universe, everything WHERE answer=42;
Empty set (2079460347 sec) |
|
Back to top |
|
|
drakonite l33t
Joined: 02 Nov 2002 Posts: 768 Location: Lincoln, NE
|
Posted: Sun Mar 09, 2003 9:40 pm Post subject: |
|
|
commanderfoxtrot wrote: |
Personally I would advise mencoder as the easiest for you to set up. Record to MJPEG first unless you have the CPU power for MPEG4. ffmpeg's MPEG4 implementation is fastest. |
I agree with the comment about mencoder being a good choice (vcr is easier but has some bugs, and doesn't have as good of performace) but for me MJPEG seems to take a lot more CPU power than MPEG4 does.
I have a 400mhz Celery, and recording both MPEG4 and MP3 at the same time takes a bit more cpu power than I have, but I created a script that records off of my tv tuner using MPEG4 compression on the fly, and raw audio frames, and after it's done recording it reencodes the audio using MP3. Using it I've been able to successfully record 320x240 DivX at a fairly solid 30fps (even if I surf the web while it records). _________________ Shoot Pixels Not People
My GPG/PGP Public key |
|
Back to top |
|
|
pahud Tux's lil' helper
Joined: 26 Nov 2002 Posts: 103
|
Posted: Mon Mar 10, 2003 12:44 am Post subject: |
|
|
drakonite wrote: |
but I created a script that records off of my tv tuner using MPEG4 compression on the fly, and raw audio frames, and after it's done recording it reencodes the audio using MP3. Using it I've been able to successfully record 320x240 DivX at a fairly solid 30fps (even if I surf the web while it records). |
Can you share your script for us?
I just can't wait to do the same thing as you said. |
|
Back to top |
|
|
drakonite l33t
Joined: 02 Nov 2002 Posts: 768 Location: Lincoln, NE
|
Posted: Mon Mar 10, 2003 12:52 am Post subject: |
|
|
pahud wrote: | drakonite wrote: |
but I created a script that records off of my tv tuner using MPEG4 compression on the fly, and raw audio frames, and after it's done recording it reencodes the audio using MP3. Using it I've been able to successfully record 320x240 DivX at a fairly solid 30fps (even if I surf the web while it records). |
Can you share your script for us?
I just can't wait to do the same thing as you said. |
What speed cpu do you have?
Yeah, I'll post my script. I'm going to take a look at it and see if I can make it a little more flexible first (I think I have it hardcoded to record from the av inputs...) _________________ Shoot Pixels Not People
My GPG/PGP Public key |
|
Back to top |
|
|
pahud Tux's lil' helper
Joined: 26 Nov 2002 Posts: 103
|
Posted: Mon Mar 10, 2003 1:21 am Post subject: |
|
|
drakonite wrote: |
What speed cpu do you have?
Yeah, I'll post my script. I'm going to take a look at it and see if I can make it a little more flexible first (I think I have it hardcoded to record from the av inputs...) |
I have a P4-1.6G desktop but actually I'd like to put everything together
in a VIA EPIA mini-itx box
Quote: |
CPU: VIA Samuel 2 with 64KB cache
RAM: 256MB SDRAM
|
with your recommended CFLAGS. However, I am still working on the
emerge problem of xfree-4.2.1-r2 on thie platform. |
|
Back to top |
|
|
drakonite l33t
Joined: 02 Nov 2002 Posts: 768 Location: Lincoln, NE
|
Posted: Mon Mar 10, 2003 1:51 am Post subject: |
|
|
Code: | #/bin/sh
if [ -z $3 ]
then
mencoder -tv on:driver=v4l:norm=ntsc:device=/dev/video0:width=320:height=240:chanlist=us-cable:channel=$2:audiorate=48000 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1000:vme=5 -oac copy -ofps 25
else
mencoder -tv on:driver=v4l:norm=ntsc:device=/dev/video0:width=320:height=240:chanlist=us-cable:channel=$2:audiorate=48000 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1000:vme=5 -oac copy -ofps 25 -endpos $3
fi
mencoder -noskip -ovc copy -oac mp3lame test.avi -o $1 -lameopts vbr=0:br=128:aq=0
rm test.avi |
(note: some of the lines are somewhat long the forums wrap the lines so I left spaces between each line so you can see where the lines breaks should be. If you copy and paste it should come out correct though...)
The script takes three arguments. The first one is the name you want the file to be called (do not use test.avi !!! If you do it won't work. if you use this script in a directory with a file called test.avi the file will be overwritten regardless of the filename you choose. test.avi is the name of the file mencoder likes to use by default)
The second argument is the channel you want to record.
The first and second arguments are both required.
The third argument is the length of time you want to record, and is optional. If you choose to not give a 3rd argument you can press ctrl+c during the initial capture to stop recording, the script will then begin converting the audio and will stop when done.
Yes, it's kinda ugly... But it works pretty good for me. And yes, it does encode at 25fps instead of 30fps, this is because at 30fps it was fairly easy for it to loose a few frames if a cron job started, but at 25 it has a slight buffer so it takes quite a bit to make it loose frames.
If you have any questions or comments let me know... _________________ Shoot Pixels Not People
My GPG/PGP Public key |
|
Back to top |
|
|
nacs n00b
Joined: 21 Feb 2003 Posts: 41
|
Posted: Fri Mar 14, 2003 4:17 am Post subject: |
|
|
I had been seeking for a good way to record for a while now (I don't like Xawtv's built in recorder and such) but this script did the trick.
Works perfectly--thanks. |
|
Back to top |
|
|
kwiqsilver Guru
Joined: 19 Mar 2003 Posts: 360
|
Posted: Sat Mar 22, 2003 4:52 am Post subject: A Perl mencoder script |
|
|
For those who are interested...
I have the following script for recording tv.
It takes the name of the show (or some other string to make the filenames distinct), the channel to record, and the length of time to record (in minutes, not seconds).
It then saves the tv show to $HOME/Documents/TV/<show>-YYYY-MM-DD.avi (you can easily change the directory to meet your needs). If that file exists it adds a ".0" (or ".1" if ".0" exists, etc.) suffix to the filename.
I also broke down the mencoder command to make it more legible and easier to modify for those of you with a different device or encoding choice.
To run it I just put a command like this in my personal crontab:
Code: |
00 00 * * 1-5 $HOME/perl/tv_rec Futurama 53 30
|
You can also run it by hand the same way, of course.
An important note: If a show your record starts as another ends, cut the record time by a minute, or mencoder might fail to record the second one.
But that applies to any use of mencoder.
I still haven't figured out how to get mencoder to record quietly.
Code: |
#!/usr/bin/perl -w
################################################################################
# tv_rec
#
# Records TV using mencoder and my bttv tv card.
#
# $ARGV[0] is the name of the show (used in the filename).
# $ARGV[1] is the channel to record.
# $ARGV[2] is the time in minutes to record.
################################################################################
use POSIX;
die "Wrong!\n" unless @ARGV == 3;
my ($show, $channel, $length) = @ARGV;
my $tvDir = "$ENV{HOME}/Documents/TV";
$length *= 60; # Go from minutes to seconds.
my $today = strftime "%Y-%m-%d", localtime;
my $file = "$tvDir/$show-$today.avi";
if (-f $file)
{
foreach (0..1000)
{
print "($_)\n($file.$_)\n";
next if -f "$file.$_";
$file .= ".$_";
last;
}
}
my $cmd = "/usr/bin/mencoder -tv on:" .
"driver=v4l:" .
"norm=ntsc:" .
"device=/dev/video:" .
"adevice=/dev//dsp3:" .
"width=320:" .
"height=240:" .
"chanlist=us-cable:" .
"channel=$channel:" .
"audiorate=48000 " .
"-ovc lavc " .
"-lavcopts " .
"vcodec=mpeg4:" .
"vbitrate=1000:" .
"vme=5 " .
"-oac mp3lame " .
"-ofps 25 " .
"-o $file " .
"-endpos $length";
my $ret = system $cmd;
exit $ret;
|
|
|
Back to top |
|
|
pahud Tux's lil' helper
Joined: 26 Nov 2002 Posts: 103
|
Posted: Thu Apr 03, 2003 8:10 am Post subject: |
|
|
drakonite wrote: | Code: | #/bin/sh
if [ -z $3 ]
then
mencoder -tv on:driver=v4l:norm=ntsc:device=/dev/video0:width=320:height=240:chanlist=us-cable:channel=$2:audiorate=48000 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1000:vme=5 -oac copy -ofps 25
else
mencoder -tv on:driver=v4l:norm=ntsc:device=/dev/video0:width=320:height=240:chanlist=us-cable:channel=$2:audiorate=48000 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1000:vme=5 -oac copy -ofps 25 -endpos $3
|
|
this is my code
Code: |
#!/bin/sh
mencoder -tv on:driver=v4l:norm=ntsc:width=320:height=240:chanlist=us-cable:freq=194.18:outfmt=i420 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1000:vme=5 -oac copy -ofps 25
|
But when I run this script, it complains
Code: | TV detected! ;-)
Selected driver: v4l
name: Video 4 Linux input
author: Alex Beregszaszi <alex@naxine.org>
comment: under development
Selected device: BT878(Leadtek WinFast 2000/ W)
Capabilites: capture tuner overlay clipping frameram scales
Device type: 235
Supported sizes: 48x32 => 768x480
Inputs: 4
0: Television: tuner audio tv camera (tuner:1, norm:ntsc)
1: Composite1: audio camera (tuner:0, norm:ntsc)
2: S-Video: audio camera (tuner:0, norm:ntsc)
3: Composite3: audio camera (tuner:0, norm:ntsc)
Card reports an unknown audio mode !
Trying two channel audio. Use forcechan to override.
Unable to set trigger: 1
audio block size too low, setting to 16384!
Using input 'Television'
[V] filefmt:9 fourcc:0x30323449 size:320x240 fps:29.00 ftime:=0.0345
Opening video filter: [expand=-1:-1:-1:-1:1]
Expand: -1 x -1, -1 ; -1 (-1=autodetect) osd: 1
==========================================================================
Opening video decoder: [raw] RAW Uncompressed Video
VDec: vo config request - 320 x 240 (preferred csp: Planar I420)
VDec: using Planar I420 as output csp (no 0)
Movie-Aspect is undefined - no prescaling applied.
videocodec: libavcodec (320x240 fourcc=58564944 [DIVX])
Selected video codec: [rawi420] vfm:raw (RAW I420)
==========================================================================
audiocodec: framecopy (format=1 chans=2 rate=44100 bits=16 bps=176400 sample=4)
Writing AVI header...
Forcing audio preload to 0, max pts correction to 0
Pos: 0.0s 2f ( 0%) 0fps Trem: 0min 0mb A-V:0.000 [0:0]
video buffer full - dropping frame
video buffer full - dropping frame
video buffer full - dropping frame
video buffer full - dropping frame
video buffer full - dropping frame
video buffer full - dropping frame
video buffer full - dropping frame
|
What can I do to solve this problem? |
|
Back to top |
|
|
|