File: sreview-previews

package info (click to toggle)
sreview 0.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,504 kB
  • sloc: perl: 12,360; javascript: 509; sh: 72; makefile: 8
file content (126 lines) | stat: -rw-r--r-- 3,398 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/perl

use strict;
use warnings;

use DBI;
use File::Path qw/make_path/;
use SReview::Talk;
use Media::Convert::Asset;
use Media::Convert::Pipe;
use Media::Convert::Asset::ProfileFactory;
use SReview::Config::Common;
use SReview::Files::Factory;

=head1 NAME

sreview-previews - create previews from the C<sreview-cut> output

=head1 SYNOPSIS

sreview-previews TALKID

=head1 DESCRIPTION

C<sreview-previews> performs the following actions:

=over

=item *

Look up the talk with id TALKID in the database.

=item *

Verify if the codecs in the pre, main, and post videos as produced by
L<sreview-cut> are HTML5-compatible. If they are, copy them to a MP4
or WebM container from the Matroska one.

=item *

If they are not, convert them to the C<vp8_lq> profile

=item *

Update the database to set the current talk's C<progress> field to
C<done>.

=back

=head1 CONFIGURATION

C<sreview-previews> considers the following configuration values:

=over

=cut

my $config = SReview::Config::Common::setup;
my $collection = SReview::Files::Factory->create("intermediate", $config->get("pubdir"));

sub convert($) {
	my $relname = shift;
	return unless ($collection->has_file($relname . ".mkv"));
	my $input_file = $collection->get_file(relname => $relname . ".mkv");
	my $input = Media::Convert::Asset->new(url => $input_file->filename);
	my $vc = $input->video_codec;
	my $ac = $input->audio_codec;

	if (!$config->get("force_preview_transcode")) {
		if (($vc eq "vp8" && $ac eq "vorbis") || ($vc eq "vp9" && $ac eq "vorbis") || ($vc eq "vp9" && $ac eq "opus")) {
			my $output_file = $collection->add_file(relname => $relname . ".webm");
			my $output = Media::Convert::Asset->new(url => $output_file->filename);
			Media::Convert::Pipe->new(inputs => [$input], output => $output, vcopy => 1, acopy => 1)->run();
			$output_file->store_file;
			return;
		}
		if ($vc eq "h264" && $ac eq "aac") {
			my $output_file = $collection->add_file(relname => $relname . ".mp4");
			my $output = Media::Convert::Asset->new(url => $output_file->filename);
			Media::Convert::Pipe->new(inputs => [$input], output => $output, vcopy => 1, acopy => 1)->run();
			$output_file->store_file;
			return;
		}
	}
	my $profile = Media::Convert::Asset::ProfileFactory->create('vp8_lq', $input, $config->get('extra_profiles'));
	my $output_file = $collection->add_file(relname => $relname . ".webm");
	my $output = Media::Convert::Asset->new(url => $output_file->filename, reference => $profile);
	Media::Convert::Pipe->new(inputs => [$input], output => $output)->run();
	$output_file->store_file;
}

=item dbistring

The DBI string used to connect to the database.

=cut

my $dbh = DBI->connect($config->get('dbistring'), '', '') or die "Cannot connect to database!";
my $talkid = $ARGV[0];

$dbh->prepare("UPDATE talks SET progress='running', state='generating_previews' WHERE id=?")->execute($talkid);

my $talk = SReview::Talk->new(talkid => $talkid);

=item pubdir

The directory in which to find the output of C<sreview-cut>, and in
which to write the previews

=cut

my $relname = $talk->relative_name;

convert($relname . "/pre");
convert($relname . "/main");
convert($relname . "/post");

$dbh->prepare("UPDATE talks SET progress='done' WHERE id=? AND state='generating_previews'")->execute($talkid);

=back

=head1 SEE ALSO

C<sreview-cut>, C<sreview-transcode>, C<sreview-skip>, C<sreview-config>

=cut