CS185c
Chris Pollett
Apr 8, 2019
public final class ResourceManager {
private static final int NUM_IMAGES = 100;
private Image[] image = new Image[NUM_IMAGES];
private static final ResourceManager RMANAGER = new ResourceManager();
private ResourceManager() {} // private so can't call externally
public static ResourceManager getInstance() {
return RMANAGER;
}
public Image getImageByName(String name) {
// check if already loaded image in image array
// if yes, return image, if no, load and return
}
}
ResourceManager rm = ResourceManager.getInstance();
Image im = rm.getImageByName("bob.png");
brew install ffmpeg
ffmpeg -i movie.avi some_conversion_parameters movie.mp4some_conversion_parameters can be blank or you can set some parameter on the conversion. Example parameters might be:
-vcodec h264 -acodec aac -b:a 192k -crf 28 -pix_fmt yuv420p -strict -2 -preset veryfast
ffmpeg -i movie.mp4 my_image.pngWe can use the -ss flag to specify some number of seconds into the video.
ffmpeg -ss 00:00:45 -i orginalfile.mp4 -t 00:00:10 -vcodec copy -acodec copy newfile.mp4The above extracts 10 seconds from the original file starting at the 45 second mark.
/some/path/file1.mp4 /some/path/file2.mp4 ...Then we can run the command:
ffmpeg -f concat -safe 0 -i list.txt -c copy output.mp4
ffmpeg -i movie.mp4 -vf scale=some_width:some_height -q:v 1 \ out_movie.pngFor example, -vf scale=4096:-1 would preserve the aspect ratio and make the width be 4096. Here -q:v 1 says preserve quality.
ffmpeg -i movie.mp4 -vf vflip -c:a copy out_movie.mp4Here -c:a copy says to just copy the audio.
<?php
$flip = false;
$front = true;
$back = false;
$lenscorrection = false;
$letterbox = false;
foreach ($argv as $index => $arg) {
if (in_array($arg, ['--flip', '--front', '--back', '--lenscorrection',
'--letterbox'])) {
$cmd_switch = ltrim($arg, "-");
$$cmd_switch = true;
unset($argv[$index]);
}
}
$argv = array_values($argv);
if (count($argv) < 4) {
echo <<< EOD
To use:
This program should be run from the command line with a line like:
php vr180tool.php [option list] left_eye_file right_eye_file output_file
Here [option list] can be any sequence of the following options
--flip //flip images upside down
--front // make 180 3d from just front camera results
--back // make 180 3d from just back camera results
--lenscorrection // apply fisheye len correction
--letterbox // apply letterbox to top and bottom of video
Here left_eye_file, right_eye_file, output_file should be a file that ffmpeg
can manipulate. For the Insta 360 One camera, left_eye_file and right_eye_file
would typically be .insv files for the two different perspectives needed to
make a stereoscopic 3d movie.
EOD;
exit();
}
$lens_correction = "lenscorrection=cx=0.5:cy=0.5:k1=-0.34:k2=-0.045";
$left_correction = ($lenscorrection) ? "[lensleft];[lensleft]$lens_correction" :
"";
$right_correction = ($lenscorrection) ?
"[lensright];[lensright]$lens_correction" : "";
$flip_cmd = ($flip) ? "[to_flip];[to_flip]vflip" : "";
$box = ($letterbox) ? '[stacked];' .
'[stacked]scale=(iw*sar)*min(2560/(iw*sar)\,1440/ih):'.
'ih*min(2560/(iw*sar)\,1440/ih), pad=2560:1440:'.
'(2560-iw*min(2560/iw\,1440/ih))/2:(1440-ih*min(2560/iw\,1440/ih))/2' :
"";
list(, $left_mov, $right_mov, $output) = $argv;
$is_dir = false;
$is_file = false;
foreach([$left_mov, $right_mov] as $mov) {
if (!file_exists($mov)) {
echo "File: $mov does not exist!\n";
exit();
}
if (is_dir($mov) || is_link($mov)) {
$is_dir = true;
}
if (is_file($mov)) {
$is_file = true;
}
if ($is_dir && $is_file) {
echo "Inputs must be both files or both folders\n";
exit();
}
}
if ($is_file) {
$movs = [0 => [$left_mov, $right_mov, $output]];
} else {
if (!file_exists($output)) {
mkdir($output);
}
if (is_file($output)) {
echo "If inputs are folders, output must be folder\n";
exit();
}
$pre_left_movs = glob("$left_mov/*.{insv,INSV,mp4,MP4,m4v,M4V}",
GLOB_BRACE);
$movs = [];
foreach ($pre_left_movs as $mov) {
$pre_right_mov = str_replace($left_mov, $right_mov, $mov);
if (file_exists($pre_right_mov)) {
$path_info = pathinfo($mov);
$movs[] = [$mov, $pre_right_mov, "$output/" .
$path_info['filename'] . ".mp4"];
}
}
}
echo "Making 180 degree 3D Output \n";
foreach ($movs as $mov) {
list($left_mov, $right_mov, $output) = $mov;
echo "Making movie from $left_mov and $right_mov with command:\n";
if ($back) {
$ffmpeg =
"ffmpeg -i \"$right_mov\" -i \"$left_mov\" -filter_complex ".
"\"[0]crop=1920:1920:0:0{$left_correction}[cropl];" .
"[1]crop=1920:1920:0:0{$right_correction}[cropr];" .
"[cropl][cropr]hstack$flip_cmd$box\" \"$output\"";
} else {
$ffmpeg =
"ffmpeg -i \"$right_mov\" -i \"$left_mov\" -filter_complex ".
"\"[0]crop=1920:1920:1920:0{$left_correction}[cropl];" .
"[1]crop=1920:1920:1920:0{$right_correction}[cropr];" .
"[cropl][cropr]hstack$flip_cmd$box\" \"$output\"";
}
echo $ffmpeg . "\n";
exec($ffmpeg);
}
$ffmpeg =
"ffmpeg -i \"$right_mov\" -i \"$left_mov\" -filter_complex ".
"\"[0]crop=1920:1920:0:0{$left_correction}[cropl];" .
"[1]crop=1920:1920:0:0{$right_correction}[cropr];" .
"[cropl][cropr]hstack$flip_cmd$box\" \"$output\"";
exec($ffmpeg);
[0]crop=1920:1920:0:0[lens_left];[lens_left]lenscorrection=cx=0.5:cy=0.5:k1=-0.34:k2=-0.045[out_left]; [0]crop=1920:1920:1920:0[lens_right];[lens_right]lenscorrection=cx=0.5:cy=0.5:k1=-0.34:k2=-0.045[out_right]; [out_left][out_right]hstack
Which of the following statements is true?