• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/perl
2use 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
9my $station = shift or die "Usage: $0 <station> [standard] [device]";
10my $dev;
11my $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
21my $acard=0;
22my $rec_ctrl="Aux,0";
23my $file="out.mpg";
24my $vbitrate=1500;
25my $abitrate=224;
26
27##############################################
28# Those stuff below are NTSC / PAL-M specific
29
30my $list="/usr/share/xawtv/ntsc-cable.list";
31my $fps=30000/1001;
32my $width=640;
33my $height=480;
34##############################################
35
36my $on=0;
37my $freq;
38
39open IN,$list or die "$list not found";
40
41while (<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
54close IN;
55
56if ( !$freq ) {
57	printf "Can't find station $station\n";
58	exit;
59}
60
61printf "setting to channel $station, standard $std, freq=$freq on device $dev\n";
62system "v4l2-ctl -d $dev -f $freq -s $std";
63
64printf "Programming alsa to capture on $rec_ctrl at hw $acard\n";
65system "amixer -c $acard sset $rec_ctrl 80% unmute cap";
66system "amixer -c $acard sset Capture 15%";
67
68printf "recording with ffmpeg on device $dev\n";
69
70my $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
73print "$encode\n";
74exec $encode;
75