~ubuntu-branches/ubuntu/precise/v4l-utils/precise

« back to all changes in this revision

Viewing changes to contrib/v4l_rec.pl

  • Committer: Bazaar Package Importer
  • Author(s): Gregor Jasny
  • Date: 2010-02-28 19:44:15 UTC
  • Revision ID: james.westby@ubuntu.com-20100228194415-067hdj8rvawj91zw
Tags: upstream-0.7.90
ImportĀ upstreamĀ versionĀ 0.7.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
use strict;
 
3
 
 
4
# This is a very simple script to record a v4l program with ffmpeg or mencode
 
5
# Currenlty, works only with PAL-M or NTSC with ntsc-cable freqs
 
6
#
 
7
# mencode is easier due to usage of ALSA
 
8
 
 
9
my $station = shift or die "Usage: $0 <station> [standard] [device]";
 
10
my $dev;
 
11
my $std;
 
12
 
 
13
# Parameters with optional values
 
14
 
 
15
$std=shift or $std='PAL-M';
 
16
$dev=shift or $dev="/dev/video1";
 
17
 
 
18
##############################################
 
19
# Those stuff below are currently "hardcoded"
 
20
 
 
21
my $acard=0;
 
22
my $rec_ctrl="Aux,0";
 
23
my $file="out.mpg";
 
24
my $vbitrate=1500;
 
25
my $abitrate=224;
 
26
 
 
27
##############################################
 
28
# Those stuff below are NTSC / PAL-M specific
 
29
 
 
30
my $list="/usr/share/xawtv/ntsc-cable.list";
 
31
my $fps=30000/1001;
 
32
my $width=640;
 
33
my $height=480;
 
34
##############################################
 
35
 
 
36
my $on=0;
 
37
my $freq;
 
38
 
 
39
open IN,$list or die "$list not found";
 
40
 
 
41
while (<IN>) {
 
42
        if ($on) {
 
43
                if (m/freq\s*=\s*(\d+)(\d..)/) {
 
44
                        $freq="$1.$2";
 
45
                        $on=0;
 
46
                }
 
47
        };
 
48
 
 
49
        if (m/[\[]($station)[\]]/) {
 
50
                $on=1;
 
51
        }
 
52
}
 
53
 
 
54
close IN;
 
55
 
 
56
if ( !$freq ) {
 
57
        printf "Can't find station $station\n";
 
58
        exit;
 
59
}
 
60
 
 
61
printf "setting to channel $station, standard $std, freq=$freq on device $dev\n";
 
62
system "v4l2-ctl -d $dev -f $freq -s $std";
 
63
 
 
64
printf "Programming alsa to capture on $rec_ctrl at hw $acard\n";
 
65
system "amixer -c $acard sset $rec_ctrl 80% unmute cap";
 
66
system "amixer -c $acard sset Capture 15%";
 
67
 
 
68
printf "recording with ffmpeg on device $dev\n";
 
69
 
 
70
my $encode="/usr/bin/mencoder -tv driver=v4l2:device=$dev:norm=$std:width=$width:height=$height:input=0:alsa:adevice=hw.".$acard.":amode=1:forceaudio:fps=$fps tv:// -o $file -oac mp3lame -lameopts cbr:br=$abitrate -ovc lavc -lavcopts dia=-2:vcodec=mpeg4:vbitrate=$vbitrate -noodml";
 
71
#my $encode="ffmpeg -ad /dev/dsp".$acard." -vd $dev -tvstd $std -s ".$width."x".$height." -vcodec mpeg2video -f mpeg test.mpg";
 
72
 
 
73
print "$encode\n";
 
74
exec $encode;