#!/usr/bin/perl $SIG{TERM} = $SIG{INT} = sub { exit 1 }; sub sanitize ($) { my $s = lc shift; $s =~ s/\.[^.]+$//g; $s =~ s/\W/_/g; $s =~ s/\s+/_/g; if (length($s) == 0) { print "fn is empty"; exit(1); } $s =~ s/_+/_/g; return $s; } my ($s) = @ARGV; if (not defined $s || $s !~ /^http/) { die "usage: ./get.pl http://...\n"; } mkdir("sequences/"); chdir("sequences/"); my $fn, $new_fn, $video_fn; if ($s =~ /(mov|mp4|webm|avi|mpe?g)$/i) { $s =~ s/^\s+//; $s =~ s/\s+$//; my $fn = `basename $s`; $clean_fn = $fn; $clean_fn =~ s/-/_/g; $clean_fn =~ s/^\s//; $clean_fn =~ s/\s$//; $clean_fn =~ s/\s/_/g; $clean_fn =~ s/_+/_/g; system('rm', $fn); system('rm', $clean_fn); print "downloading $clean_fn\n"; system('wget', '-O', $clean_fn, $s); $video_fn = $clean_fn; } else { print "youtube-dl $s\n"; my $yt = `youtube-dl -o "%(title)s.%(ext)s" $s`; print $yt; my @partz = split("\n", $yt); foreach $part (@partz) { print "$part\n"; if ($part =~ /\[download\] Destination\: ([^)]+)$/) { $video_fn = $1; print ">>> $video_fn\n"; } if ($part =~ /\[download\] (.*) has already been downloaded and merged/) { $video_fn = $1; print ">>> $video_fn\n"; } if ($part =~ /\[ffmpeg\] Merging formats into "(.*)"/) { $video_fn = $1; print ">>> $video_fn\n"; } } } if ($video_fn) { print "Video filename: $video_fn\n"; my $tag = sanitize($video_fn); print "creating dataset: $tag\n"; my @partz = split(/\./, $video_fn); my $ext = $partz[$#partz]; my $new_fn = $tag . '.' . $ext; system('mv', $video_fn, $new_fn); print "new video filename: $video_fn\n"; mkdir($tag); system('ffmpeg', '-i', $new_fn, "-filter:v", "scale=1024x512", "-vframes", 90000, $tag . '/frame_%05d.png'); print "created dataset: $tag\n"; } END { chdir('..'); }