#!/usr/bin/perl # script to create mpg stream files from jpeg files in a directory # May 21 2006 # D. Scott Barninger # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public # License version 2 as published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this program; if not, write to the Free # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, # MA 02111-1307, USA. # check how we were called if ( ! $ARGV[0] ) { print "Usage: create_stream /path/ frames\n"; exit; } if ( ! $ARGV[1] ) { print "Usage: create_stream /path/ frames\n"; exit; } # full path with trailing / to directory containing jpg files my($filepath) = $ARGV[0]; # number of frames in the mpg stream my($frames) = $ARGV[1]; # make sure path has a trailing slash if ( substr($filepath,-1,1) ne "/" ) { print "Error: Path must include trailing slash.\n"; exit; } my @filelist = &get_files($filepath); my $oldfile; my $newfile; my $basename; my $count = 0; foreach $oldfile (@filelist) { $basename = $oldfile; $basename =~ s/.jpg//g; $newfile = "$basename.mpg"; print "Creating $newfile\n"; system("jpeg2yuv -n $frames -I p -f 29.97 -j $oldfile | mpeg2enc -f 8 -o $newfile"); $count++; } print "Created $count mpg files.\n\n"; # Get all the files in a path except . and .. sub get_files { ($path) = @_; my $file; my @list; opendir( DIR, $path ); my @files = sort { uc($a) cmp uc($b) } readdir(DIR); closedir DIR; foreach $file (@files) { if ($file eq "." || $file eq "..") { next; } else { push (@list, $file); } } return(@list); }