summaryrefslogtreecommitdiff
path: root/splice.pl
blob: 8189cabffa305fa8c03c21088ec9408d7b9ed7a8 (plain)
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
#!/usr/bin/perl

use Getopt::Long;
use IO::Handle;

STDERR->autoflush(1);
STDOUT->autoflush(1);

my $module = "pix2pixhd";
my $dataset = "PLACEHOLDER";
my $sequence = "PLACEHOLDER";
my $folder_id = 0;
my $start_frame = 0;
my $end_frame = 0;
my $endpoint = undef;
GetOptions (
  "module=s" => \$module,
  "dataset=s"  => \$dataset,
  "sequence=s"  => \$sequence,
  "folder_id=i" => \$folder_id,
  "start_frame=i" => \$start_frame,
  "end_frame=i" => \$end_frame,
  "endpoint=s" => \$endpoint,
)
or die("Error in command line arguments\n");

if ($dataset eq 'PLACEHOLDER' or $sequence eq 'PLACEHOLDER' || ! -e "sequences/$sequence") {
  print "No dataset specified\n";
  exit(1);
}

if ($start_frame == 0 or !$end_frame == 0) {
  print "No frames specified\n";
  exit(1);
}

mkdir("./datasets/$dataset");
mkdir("./datasets/$dataset/train_A");
mkdir("./datasets/$dataset/train_B");
mkdir("./datasets/$dataset/test_A");
mkdir("./datasets/$dataset/test_B");
mkdir("./sequences/$dataset");

my $dataset_lines = `ls -1v sequences/$sequence/*.png`;
my @dataset_files = split("\n", $dataset_lines);

my $sequence_lines = `ls -1v sequences/$sequence/*.png`;
my @sequence_files = split('\n', $sequence_lines);

my $pwd = `pwd`;
chomp $pwd;
$pwd .= '/';
print $pwd . "\n";

my $i = scalar @dataset_files;
my $last_fn = undef;
for my $filename (@sequence_files) {
  if ($start_frame <= $i and $i <= $end_frame) {
    chomp $filename;
    print($pwd . $filename);
    system('ln', '-s', $pwd . $filename, sprintf('./datasets/$dataset/frame_%05d.png', $i));
    if (defined $last_fn) {
      system('ln', '-s', $pwd . $last_fn, sprintf('./datasets/$dataset/frame_%05d.png', $i));
      system('ln', '-s', $pwd . $filename, sprintf('./datasets/$dataset/frame_%05d.png', $i));
    }
    $last_fn = $filename;
    $i += 1;
  }
}

if (defined $endpoint) {
  print("upload to $endpoint\n");
  system("curl",
    "-X", "POST",
    "-F", "folder_id=$folder_id",
    "-F", "module=$module",
    "-F", "name=$dataset.mov",
    "-F", "url=https://s3.amazonaws.com/i.asdf.us/cortex/lens/data/$folder_id/$dataset.mov",
    "-F", "dataset=$dataset",
    "-F", "activity=splice",
    "-F", "generated=false",
    "-F", "processed=true",
    "-F", "datatype=video",
    $endpoint
  );
}

END {
  # chdir($parent_dir);
}