~ubuntu-branches/ubuntu/precise/mythexport/precise

« back to all changes in this revision

Viewing changes to usr/share/mythtv/mythexport/save_setup.cgi

  • Committer: Bazaar Package Importer
  • Author(s): John Baab
  • Date: 2010-08-13 01:53:54 UTC
  • mfrom: (1.1.16 upstream)
  • Revision ID: james.westby@ubuntu.com-20100813015354-h2w1q6caq1mlv5vo
Tags: 2.2.0-0ubuntu1
* FFe (LP: #617570).
* Added HTML5 streaming page to web interface.
* New device config method. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/perl
2
 
 
3
 
use strict;
4
 
use CGI qw(:standard);
5
 
use HTML::Template;
6
 
use Config::Simple '-strict'; 
7
 
 
8
 
require includes;
9
 
 
10
 
my $delete = param("delete");
11
 
my $title = param("title");
12
 
# remove whitespace, as it causes issues later
13
 
$title =~ s/\s/_/g;
14
 
 
15
 
my $content = "";
16
 
my $file = "/etc/mythtv/mythexport/mythexport_settings.cfg";
17
 
my $cfg = new Config::Simple(syntax=>'ini');
18
 
 
19
 
if(-e $file){
20
 
    if(-s $file < 208){
21
 
        unlink($file);
22
 
    }
23
 
    else{
24
 
        $cfg->read($file) || die $cfg->error();
25
 
    }
26
 
}
27
 
 
28
 
my $template = HTML::Template->new(filename => 'template/template.tmpl');
29
 
 
30
 
if ($delete == 1){
31
 
    $cfg->delete("$title.sizeX");
32
 
    $cfg->delete("$title.sizeY");
33
 
    $cfg->delete("$title.audioBR");
34
 
    $cfg->delete("$title.videoBR");
35
 
    $cfg->delete("$title.device");
36
 
    $cfg->delete("$title.codec");
37
 
    $cfg->delete("$title.deletePeriod");
38
 
    $cfg->delete("$title.podcastName");
39
 
    $cfg->delete("$title.deinterlace");
40
 
    $cfg->delete("$title.removeCommercials");
41
 
    $cfg->delete("$title.audioChannels");
42
 
    $cfg->delete("$title.ffmpegArgs");
43
 
    $cfg->delete("$title.threads");
44
 
    $cfg->delete("$title.extension");
45
 
    $cfg->delete("$title.aspect");
46
 
    $cfg->write($file) || die $cfg->error();
47
 
 
48
 
    $content = "Configuration delete sucessfully.";
49
 
}
50
 
else{
51
 
    my $sizeX = param("sizeX"); 
52
 
    my $sizeY = param("sizeY"); 
53
 
    my $aspect = param("aspect");
54
 
    my $audioBR = param("audioBR"); 
55
 
    my $videoBR = param("videoBR"); 
56
 
    my $device = param("device"); 
57
 
    my $codec = param("codec"); 
58
 
    my $deletePeriod = param("deletePeriod"); 
59
 
    my $podcastName = param("podcastName"); 
60
 
    my $deinterlace = param("deinterlace");
61
 
    my $threads = param("threads");
62
 
    my $removeCommercials = param("removeCommercials");
63
 
    my $audioChannels = param("audioChannels");
64
 
    my $extension = param("extension");
65
 
    
66
 
    my $size = $sizeX . "x$sizeY";
67
 
    
68
 
    my ($audioChannelsText,$deinterlaceText,$codecText,$threadsText) = "";
69
 
    
70
 
    if($audioChannels ne ""){
71
 
        $audioChannelsText = " -ac $audioChannels";
72
 
    }
73
 
    if($deinterlace ne ""){
74
 
        $deinterlaceText = " -deinterlace";
75
 
    }
76
 
    if($codec eq "xvid"){
77
 
        $codecText = "libxvid";
78
 
    }
79
 
    else{
80
 
        $codecText = $codec;
81
 
    }
82
 
    if($threads ne ""){
83
 
        $threadsText = " -threads 2";
84
 
    }
85
 
    
86
 
    #my $cfg = new Config::Simple(syntax=>'ini');
87
 
    # or you could also do:
88
 
    # $cfg->autosave('ini')
89
 
    my $args = param("args");
90
 
    if ($device eq "mp3"){
91
 
        $args = "-acodec libmp3lame -ac 2 -ab $audioBR -vn ";
92
 
    }
93
 
    elsif ($device eq "ipod" || $device eq "zune" || $device eq "cowon" || $device eq "android" || $device eq "xbox 360" || $device eq "laptop"){
94
 
        if ($codecText eq "mpeg4" or $codecText eq "libxvid"){
95
 
            $args = "-y -acodec libmp3lame -ab $audioBR -vcodec $codecText -b $videoBR -mbd 2 -flags +mv4+aic -trellis 2 -cmp 2 -subcmp 2 -s $size$audioChannelsText$deinterlaceText$threadsText -aspect $aspect";
96
 
        }
97
 
        elsif ($codecText eq "h264"){
98
 
            # First pass
99
 
            $args = "-y -an -v 1 -vcodec libx264 -b $videoBR -bt 175k -refs 1 -deblockalpha 0 -deblockbeta 0 -partitions +parti4x4+partp8x8 -me_method full -subq 1 -me_range 21 -bf 0 -level 30 -g 300 -keyint_min 30 -sc_threshold 40 -rc_eq \"blurCplx^(1-qComp)\" -qcomp 0.7 -qmax 51 -qdiff 4 -i_qfactor 0.71428572 -maxrate 768k -bufsize 2M -cmp +chroma -flags +loop+slice -s $size$audioChannelsText$deinterlaceText$threadsText -aspect $aspect -f mp4 -pass 1 /dev/null";
100
 
 
101
 
            # Second pass
102
 
            $args .= "|-y -v 1 -vcodec libx264 -b $videoBR -bt 175k -refs 1 -deblockalpha 0 -deblockbeta 0 -partitions +parti4x4+partp8x8 -me_method full -subq 6 -me_range 21 -bf 0 -level 30 -g 300 -keyint_min 30 -sc_threshold 40 -rc_eq \"blurCplx^(1-qComp)\" -qcomp 0.7 -qmax 51 -qdiff 4 -i_qfactor 0.71428572 -maxrate 768k -bufsize 2M -cmp +chroma -flags +loop+slice -s $size$audioChannelsText$deinterlaceText$threadsText -aspect $aspect -acodec libmp3lame -ab $audioBR -ar 48000 -f mp4 -pass 2";
103
 
        }
104
 
    }
105
 
    elsif ($device eq "psp"){
106
 
        if ($codecText eq "mpeg4" or $codecText eq "libxvid"){
107
 
            $args = "-y -acodec libmp3lame -ab $audioBR -vcodec $codecText -b $videoBR -ar 24000 -mbd 2 -flags +4mv+aic -trellis 2 -cmp 2 -subcmp 2 -s $size$audioChannelsText$deinterlaceText$threadsText -aspect $aspect -r 30000/1001 -f psp -level 21 -coder 1";
108
 
        }
109
 
        elsif ($codecText eq "h264"){
110
 
            $args = "-y -acodec libmp3lame -ab $audioBR -vcodec libx264 -b $videoBR -ar 48000 -coder 1 -s $size$audioChannelsText$deinterlaceText$threadsText -aspect $aspect -f psp -flags +loop -trellis 2 -partitions parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 -level 21 -g 250 -vpre default";
111
 
        }
112
 
    }
113
 
    elsif ($device eq "archos"){
114
 
        if ($codecText eq "mpeg4" or $codecText eq "libxvid"){
115
 
            # ffmpeg line from courtesy of freymann
116
 
            $args = "-y -acodec libmp3lame -ab $audioBR -vcodec $codecText -b $videoBR -mbd 2 -flags +mv4+aic -trellis 2 -cmp 2 -subcmp 2 -aspect $aspect -s $size$audioChannelsText$deinterlaceText$threadsText";
117
 
        }
118
 
    }
119
 
 
120
 
    $cfg->param("$title.sizeX", $sizeX);
121
 
    $cfg->param("$title.sizeY", $sizeY);
122
 
    $cfg->param("$title.audioBR", $audioBR);
123
 
    $cfg->param("$title.videoBR", $videoBR);
124
 
    $cfg->param("$title.device", $device);
125
 
    $cfg->param("$title.aspect", $aspect);
126
 
    $cfg->param("$title.codec", $codec);
127
 
    $cfg->param("$title.deletePeriod", $deletePeriod);
128
 
    $cfg->param("$title.podcastName", $podcastName);
129
 
    $cfg->param("$title.deinterlace", $deinterlace);
130
 
    $cfg->param("$title.removeCommercials", $removeCommercials);
131
 
    $cfg->param("$title.audioChannels", $audioChannels);
132
 
    $cfg->param("$title.ffmpegArgs", $args);
133
 
    $cfg->param("$title.threads", $threads);
134
 
    $cfg->param("$title.extension", $extension);
135
 
    $cfg->write($file) || die $cfg->error();
136
 
 
137
 
    $content = "<p>Configuration has been sucessfully saved.</p>";
138
 
}
139
 
 
140
 
$template->param(CONTENT => $content);
141
 
$template->param(LOCATION => "setup");
142
 
 
143
 
print generateContentType(), $template->output;
144
 
exit(0);