summaryrefslogtreecommitdiff
path: root/PLUGINS/src/pictures/pic2mpg
diff options
context:
space:
mode:
authorKlaus Schmidinger <kls (at) cadsoft (dot) de>2008-01-13 18:00:00 +0100
committerKlaus Schmidinger <kls (at) cadsoft (dot) de>2008-01-13 18:00:00 +0100
commitfc4c8740a72e6c7cea5a001e19fdacb63c3cc538 (patch)
tree6ab0ae16b8d588e34d86f8a1a69c101ce8ba2809 /PLUGINS/src/pictures/pic2mpg
parent29b2d48bb53df75f1cb978e72bc709a6658d6e5c (diff)
downloadvdr-patch-lnbsharing-fc4c8740a72e6c7cea5a001e19fdacb63c3cc538.tar.gz
vdr-patch-lnbsharing-fc4c8740a72e6c7cea5a001e19fdacb63c3cc538.tar.bz2
Version 1.5.13vdr-1.5.13
- Fixed the declaration of cSubtitleObject::Decode8BppCodeString() (thanks to Gregoire Favre). - The new setup option "Miscellaneous/Emergency exit" can be used to turn off the automatic restart of VDR in case a recording fails for some reason. - The kInfo key is now propagated to any open menu, so that it can react to it in a context sensitive manner (suggested by Andreas Brugger). If there is no menu open it will show the info of the current broadcast or replay. - cTimeMs now uses the monotonic clock, if available (thanks to Petri Hintukainen). - Fixed cVector::Clear() and cStringList::Clear(). - Added cString::Truncate(). - Fixed the "i18n:" target in the "newplugin" script, so that it can create the initial *.pot file. - Fixed handling the '-l' option. - Fixed error handling in cCuttingThread::Action() (thanks to Udo Richter). - Fixed a loss of the date display in the "classic" skin's main menu (reported by Andreas Brugger). - Added a missing setting of lastFreeMB in cMenuMain::Update() (reported by Andreas Brugger). - Added '-Wno-parentheses' to the compiler options in order to avoid silly compiler warnings for expressions like 'a || b && c', where GCC 4.3 wants to force the programmer to write 'a || (b && c)', while everybody knows that '&&' links stronger than '||' (reported by Tobias Grimm). - Updated the Hungarian language texts (thanks to István Füley). - Fixed displaying weekday names in the Schedule menu if the system uses UTF-8 (reported by Jiri Dobry). - The new plugin "pictures" implements a simple picture viewer. See PLUGINS/src/pictures/README for details. - The automatic shutdown is now suppressed if the remote control is currently disabled (suggested by Helmut Auer, implemented by Udo Richter). - Added a section about "Logging" to PLUGINS.html (suggested by Torsten Kunkel). - Enhanced the SVDRP command CLRE to allow clearing the EPG data of a particular channel (thanks to Benjamin Hess).
Diffstat (limited to 'PLUGINS/src/pictures/pic2mpg')
-rwxr-xr-xPLUGINS/src/pictures/pic2mpg176
1 files changed, 176 insertions, 0 deletions
diff --git a/PLUGINS/src/pictures/pic2mpg b/PLUGINS/src/pictures/pic2mpg
new file mode 100755
index 0000000..5791685
--- /dev/null
+++ b/PLUGINS/src/pictures/pic2mpg
@@ -0,0 +1,176 @@
+#!/usr/bin/perl
+
+# pic2mpg: Convert picture files to MPEG still frames
+#
+# Converts either a single picture file or all files in a
+# given directory (recursively) to MPEG still frames.
+#
+# See the README file for copyright information and how to reach the author.
+#
+# $Id: pic2mpg 1.1 2008/01/13 11:09:12 kls Exp $
+
+## TODO implement HDTV (1920 x 1080)
+
+use File::Path;
+use Getopt::Std;
+use Image::Size;
+
+$Usage = qq{
+Usage: $0 [options] picture-dir mpeg-dir
+ $0 [options] picture-file mpeg-file
+
+Options: -a Aspect ratio 4:3 (default is 16:9)
+ -h print Help
+ -f Force conversion
+ -n NTSC (default is PAL)
+ -v num Verbose (0=none, 1=list files, 2=detailed)
+ -x percent X overscan in percent
+ -y percent Y overscan in percent
+};
+
+getopts("ahfnv:x:y:") || die $Usage;
+
+die $Usage if $opt_h;
+
+$Aspect = $opt_a;
+$Force = $opt_f;
+$NTSC = $opt_n;
+$Verbose = $opt_v;
+$OverscanX = $opt_x;
+$OverscanY = $opt_y;
+
+$ListFiles = $Verbose >= 1;
+$Detailed = $Verbose >= 2;
+
+# Screen size:
+
+$SW = $NTSC ? 720 : 720;
+$SH = $NTSC ? 480 : 576;
+
+$ScreenRatio = $Aspect ? 4 / 3 : 16 / 9;
+
+# Converter programs:
+
+%PNMCONV = (
+ bmp => "bmptopnm",
+ gif => "giftopnm",
+ jpeg => "jpegtopnm",
+ jpg => "jpegtopnm",
+ png => "pngtopnm",
+ pnm => "cat",
+ tif => "tifftopnm",
+ tiff => "tifftopnm",
+ );
+
+# Command options:
+
+die "$0: missing parameter\n" unless $ARGV[0] && $ARGV[1];
+die "$0: file or directory not found: $ARGV[0]\n" unless -e $ARGV[0];
+die "$0: source and destination must be different\n" if $ARGV[0] eq $ARGV[1];
+
+$verbose1 = $Detailed ? "--verbose" : "";
+$verbose2 = $Detailed ? "-v 2" : "-v 0";
+$system1 = $NTSC ? "" : "--pal";
+$system2 = $NTSC ? "n" : "p";
+$framerate = $NTSC ? "30000:1001" : "25:1";
+$aspect = $Aspect ? "2" : "3";
+
+# Convert a single file:
+
+if (-f $ARGV[0]) {
+ die "$0: mixed file and directory ('$ARGV[0]' <-> '$ARGV[1]')\n" unless !-e $ARGV[1] || -f $ARGV[1];
+ ConvertFile($ARGV[0], $ARGV[1]);
+ exit;
+ }
+
+die "$0: mixed directory and file ('$ARGV[0]' <-> '$ARGV[1]')\n" unless !-e $ARGV[1] || -d $ARGV[1];
+
+$PICDIR = $ARGV[0];
+$MPGDIR = $ARGV[1];
+
+# Convert pictures to mpegs:
+
+chdir($PICDIR) || die "$PICDIR: $!\n";
+
+@Pictures = `find -type f`;
+chomp(@Pictures);
+
+for $pic (@Pictures) {
+ my $mpg = "$MPGDIR/$pic.mpg";
+ if ($Force || !-e $mpg || -M $mpg > -M $pic) {
+ (my $dir = $mpg) =~ s/\/[^\/]*$//;
+ mkpath($dir);
+ ConvertFile($pic, $mpg);
+ }
+ }
+
+# Remove mpegs without pictures:
+
+chdir($MPGDIR) || die "$MPGDIR: $!\n";
+
+@Mpegs = `find -type f`;
+chomp(@Mpegs);
+
+for $mpg (@Mpegs) {
+ my $pic = "$PICDIR/$mpg";
+ $pic =~ s/\.mpg$//;
+ if (!-e $pic) {
+ print "removing $mpg\n";
+ unlink($mpg);
+ }
+ }
+
+# Remove empty directories:
+
+chdir($MPGDIR) || die "$MPGDIR: $!\n";
+
+for ($i = 0; $i < 10; $i++) { # dirs might become empty when removing empty subdirs
+ @Dirs = `find -type d -empty`;
+ chomp(@Dirs);
+ last unless @Dirs;
+
+ for $dir (@Dirs) {
+ $dir = EscapeMeta($dir);
+ print "removing $dir\n";
+ !system("rm -rf $dir") || die "$dir: $!\n";
+ }
+ }
+
+# Actual file conversion:
+
+sub ConvertFile
+{
+ my ($Pict, $Mpeg) = @_;
+ (my $Type) = $Pict =~ /\.([^\.]*)$/;
+ die "unknown file type '$Type': '$Pict'\n" unless defined $PNMCONV{$Type};
+ my ($w, $h) = imgsize($Pict);
+ print "image size is $w x $h\n" if ($Detailed);
+ if ($w / $h <= $ScreenRatio) {
+ $w = $h * $ScreenRatio;
+ }
+ else {
+ $h = $w / $ScreenRatio;
+ }
+ my $ScaleW = $SW / $w * (100 - 2 * $OverscanX) / 100;
+ my $ScaleH = $SH / $h * (100 - 2 * $OverscanY) / 100;
+ $Pict = EscapeMeta($Pict);
+ $Mpeg = EscapeMeta($Mpeg);
+ print "$Pict -> $Mpeg\n" if $ListFiles;
+ my $Cmd = "$PNMCONV{$Type} $Pict 2> /dev/null |"
+ . "pnmscale $verbose1 --xscale=$ScaleW --yscale=$ScaleH |"
+ . "pnmpad $verbose1 --black --width $SW --height $SH |"
+ . "ppmntsc $verbose1 $system1 |"
+ . "ppmtoy4m $verbose2 -F $framerate -I p -S 420mpeg2 |"
+ . "mpeg2enc $verbose2 -f 3 -b 12500 -a $aspect -q 1 -n $system2 -o $Mpeg";
+ !system($Cmd) || die "$Cmd: $!\n";
+ $Cmd = "touch -r $Pict $Mpeg";
+ !system($Cmd) || die "$Cmd: $!\n";
+}
+
+sub EscapeMeta
+{
+ my $META = ' !"#$%&\'()*;<>?[\\]`{|}~';
+ my $s = shift;
+ $s =~ s/([$META])/\\$1/g;
+ return $s;
+}