Re: Patch: add "auto clip only" as a zoom/clip preset

Jörn Reder <[email protected]>
Newsgroups gmane.comp.video.dvdrip.user
Message-ID <[email protected]>
Marc Sherman wrote:

> One thing I was wondering about -- is 720:(480|576) a universal standard 
> for vob files, or should we actually query the real dimensions of the 
> vob file and calculate the proper export_par value? I've never seen a 
> DVD with non-standard size files, but my collection is small.

You are right, but I was too lazy in the first approach ;) There *are* 
different DVD resolutions possible, would be better to calculate the 
exact factor to be sure.

Attached you find a patch (against vanilla 0.98.8) accomplishing this. 
As well the --export_par parameter is now calculated during internal 
transcode command generation instead of adding it visibly to the 
transcode options field. You still can set --export_par there to overide
dvd::rip's opinion of the best value for it ;)

Regards,

Jörn

-- 
LINUX - Linux Is Not gnU linuX
dvdrip-0.98.8-anamorph2.patch.txt (text/plain, 10.8 KB)
?Index: lib/Video/DVDRip/Config.pm
===================================================================
RCS file: /home/cvsroot/dvdrip/lib/Video/DVDRip/Config.pm,v
retrieving revision 1.67.2.1
diff -u -r1.67.2.1 Config.pm
--- lib/Video/DVDRip/Config.pm	9 Aug 2007 21:34:30 -0000	1.67.2.1
+++ lib/Video/DVDRip/Config.pm	14 Jan 2008 21:51:08 -0000
@@ -306,6 +306,12 @@
             [ 0       => __"Don't grab subtitles" ],
         ],
     },
+    default_preset => {
+        label   => __"Default Clip & Zoom preset",
+        type    => "popup",
+        value   => "auto_medium_fast",
+        presets => [],
+    },
     preferred_lang => {
         label   => __ "Preferred language",
         type    => 'popup',
@@ -363,6 +369,7 @@
             default_container
             ogg_file_ext
             default_bpp
+            default_preset
             default_subtitle_grab
             workaround_nptl_bugs nptl_ld_assume_kernel
             )
@@ -373,13 +380,11 @@
 
 sub new {
     my $type             = shift;
-    my %config_parameter = %CONFIG_PARAMETER;
-    my @config_order     = @CONFIG_ORDER;
 
     my @presets = (
         Video::DVDRip::Preset->new(
             name              => "nopreset",
-            title             => __ "- No Modifications -",
+            title             => __ "- No Modifications (anamorph) -",
             tc_clip1_top      => 0,
             tc_clip1_bottom   => 0,
             tc_clip1_left     => 0,
@@ -394,6 +399,11 @@
             tc_fast_bisection => 0,
         ),
         Video::DVDRip::Preset->new(
+            name           => "auto_clip",
+            title          => __ "Autoadjust, Clipping only (anamorph)",
+            auto_clip      => 1,
+        ),
+        Video::DVDRip::Preset->new(
             name           => "auto_big",
             title          => __ "Autoadjust, Big Frame Size, HQ Resize",
             tc_fast_resize => 0,
@@ -629,6 +639,16 @@
         ),
     );
 
+    my $default_presets_lref = $CONFIG_PARAMETER{"default_preset"}->{presets};
+    
+    foreach my $preset ( @presets ) {
+        push @{$default_presets_lref}, 
+            [ $preset->name, $preset->title ];
+    }
+
+    my %config_parameter = %CONFIG_PARAMETER;
+    my @config_order     = @CONFIG_ORDER;
+
     my $self = {
         config  => \%config_parameter,
         order   => \@config_order,
Index: lib/Video/DVDRip/Preset.pm
===================================================================
RCS file: /home/cvsroot/dvdrip/lib/Video/DVDRip/Preset.pm,v
retrieving revision 1.11
diff -u -r1.11 Preset.pm
--- lib/Video/DVDRip/Preset.pm	16 Aug 2006 19:34:38 -0000	1.11
+++ lib/Video/DVDRip/Preset.pm	14 Jan 2008 21:51:08 -0000
@@ -19,6 +19,7 @@
 sub name			{ shift->{name}				}
 sub title			{ shift->{title}			}
 sub auto			{ shift->{auto}				}
+sub auto_clip			{ shift->{auto_clip}			}
 sub frame_size			{ shift->{frame_size}			}
 
 sub tc_clip1_top		{ shift->{tc_clip1_top}			}
@@ -36,6 +37,7 @@
 sub set_name			{ shift->{name}			= $_[1]	}
 sub set_title			{ shift->{title}		= $_[1]	}
 sub set_auto			{ shift->{auto}			= $_[1]	}
+sub set_auto_clip		{ shift->{auto_clip}		= $_[1]	}
 sub set_frame_size		{ shift->{frame_size}		= $_[1]	}
 sub set_tc_clip1_top		{ shift->{tc_clip1_top}		= $_[1]	}
 sub set_tc_clip1_bottom		{ shift->{tc_clip1_bottom}	= $_[1]	}
@@ -68,12 +70,13 @@
         'tc_clip2_top',  'tc_clip2_bottom',
         'tc_clip2_left', 'tc_clip2_right'
         };
-    my ( $auto, $frame_size ) = @par{ 'auto', 'frame_size' };
+    my ( $auto, $auto_clip, $frame_size ) = @par{ 'auto', 'auto_clip', 'frame_size' };
 
     my $self = {
         name            => $name,
         title           => $title,
         auto            => $auto,
+        auto_clip       => $auto_clip,
         frame_size      => $frame_size,
         tc_clip1_top    => $tc_clip1_top,
         tc_clip1_bottom => $tc_clip1_bottom,
Index: lib/Video/DVDRip/Title.pm
===================================================================
RCS file: /home/cvsroot/dvdrip/lib/Video/DVDRip/Title.pm,v
retrieving revision 1.180.2.5
diff -u -r1.180.2.5 Title.pm
--- lib/Video/DVDRip/Title.pm	5 Aug 2007 16:59:15 -0000	1.180.2.5
+++ lib/Video/DVDRip/Title.pm	14 Jan 2008 21:51:08 -0000
@@ -680,6 +680,15 @@
     return $self->tc_container eq 'vcd';
 }
 
+sub is_resized {
+    my $self = shift;
+    
+    my $clip_size = $self->preview_label(type => "clip1", size_only => 1);
+    my $zoom_size = $self->preview_label(type => "zoom",  size_only => 1);
+    
+    return $clip_size ne $zoom_size;
+}
+
 sub has_vbr_audio {
     my $self = shift;
 
@@ -940,7 +949,7 @@
 sub preview_label {
     my $self = shift;
     my %par = @_;
-    my ($type, $details) = @par{'type','details'};
+    my ($type, $details, $size_only) = @par{'type','details','size_only'};
 
     my ( $width, $height, $warn_width, $warn_height, $text, $ratio,
         $phys_ratio );
@@ -1022,6 +1031,7 @@
         );
     }
 
+    return "${width}x${height}" if $size_only;
     return $text;
 }
 
@@ -1107,21 +1117,24 @@
 
     $self->set_last_applied_preset( $preset->name );
 
-    if ( $preset->auto ) {
+    if ( $preset->auto_clip ) {
+        $self->auto_adjust_clip_only;
+    }
+    elsif ( $preset->auto ) {
         $self->auto_adjust_clip_zoom(
             frame_size  => $preset->frame_size,
             fast_resize => $preset->tc_fast_resize,
         );
-        return 1;
     }
-
-    my $attributes = $preset->attributes;
-    my $set_method;
-    foreach my $attr ( @{$attributes} ) {
-        $set_method = "set_$attr";
-        $self->$set_method( $preset->$attr() );
+    else {
+        my $attributes = $preset->attributes;
+        my $set_method;
+        foreach my $attr ( @{$attributes} ) {
+            $set_method = "set_$attr";
+            $self->$set_method( $preset->$attr() );
+        }
     }
-
+    
     1;
 }
 
@@ -1236,6 +1249,51 @@
     return ( $clip2_width, $clip2_height, $zoom_ratio );
 }
 
+sub calc_export_par {
+    my $self = shift;
+
+    my $width  = $self->width;
+    my $height = $self->height;
+    
+    my $source_aspect = $width/$height;
+    my $target_aspect = $self->aspect_ratio;
+    my ($w, $h) = split(":", $target_aspect);
+    $target_aspect = $w/$h;
+    
+    my $export_par = sprintf("%d,100", 100 * $target_aspect / $source_aspect);
+
+    return $export_par;
+}
+
+sub auto_adjust_clip_only {
+    my $self = shift;
+
+    $self->set_tc_fast_resize(1);
+
+    my $result = $self->get_zoom_parameters(
+        target_width        => undef,
+        target_height       => undef,
+        fast_resize_align   => 16,
+        result_align        => 16,
+        result_align_clip2  => 1,
+        auto_clip           => 1,
+        use_clip1           => 0,
+    );
+
+    $self->set_tc_zoom_width( undef );
+    $self->set_tc_zoom_height( undef );
+    $self->set_tc_clip1_left( 0 );
+    $self->set_tc_clip1_right( 0 );
+    $self->set_tc_clip1_top( 0 );
+    $self->set_tc_clip1_bottom( 0 );
+    $self->set_tc_clip2_left( $result->{clip2_left} );
+    $self->set_tc_clip2_right( $result->{clip2_right} );
+    $self->set_tc_clip2_top( $result->{clip2_top} );
+    $self->set_tc_clip2_bottom( $result->{clip2_bottom} );
+
+    1;
+}
+
 sub auto_adjust_clip_zoom {
     my $self = shift;
     my %par  = @_;
@@ -2060,7 +2118,7 @@
         $self->set_tc_container('vcd');
     }
 
-    $self->set_preset("auto_medium_fast")
+    $self->set_preset($self->config("default_preset"))
         unless $self->last_applied_preset;
 
     my $subtitle_langs = $self->get_subtitle_languages;
@@ -2476,44 +2534,50 @@
         if $clip2 =~ /^-?\d+,-?\d+,-?\d+,-?\d+$/
         and $clip2 ne '0,0,0,0';
 
-    if ( $self->tc_fast_bisection ) {
-        $command .= " -r 2,2";
-
-    }
-    elsif ( not $self->tc_fast_resize ) {
-        my $zoom = $self->tc_zoom_width . "x" . $self->tc_zoom_height;
-        $command .= " -Z $zoom"
-            if $zoom =~ /^\d+x\d+$/;
-
+    if ( not $self->is_resized ) {
+        my $export_par = $self->calc_export_par;
+        $command .= " --export_par $export_par";
     }
     else {
-        my $multiple_of = 8;
-
-        my ( $width_n, $height_n, $err_div32, $err_shrink_expand )
-            = $self->get_fast_resize_options;
+        if ( $self->tc_fast_bisection ) {
+            $command .= " -r 2,2";
 
-        if ($err_div32) {
-            croak __x(
-                "When using fast resize: Clip1 and Zoom size must be divisible by {multiple_of}",
-                multiple_of => $multiple_of
-            );
         }
+        elsif ( not $self->tc_fast_resize ) {
+            my $zoom = $self->tc_zoom_width . "x" . $self->tc_zoom_height;
+            $command .= " -Z $zoom"
+                if $zoom =~ /^\d+x\d+$/;
 
-        if ($err_shrink_expand) {
-            croak __
-                "When using fast resize: Width and height must both shrink or expand";
         }
+        else {
+            my $multiple_of = 8;
+
+            my ( $width_n, $height_n, $err_div32, $err_shrink_expand )
+                = $self->get_fast_resize_options;
+
+            if ($err_div32) {
+                croak __x(
+                    "When using fast resize: Clip1 and Zoom size must be divisible by {multiple_of}",
+                    multiple_of => $multiple_of
+                );
+            }
+
+            if ($err_shrink_expand) {
+                croak __
+                    "When using fast resize: Width and height must both shrink or expand";
+            }
 
-        if ( $width_n * $height_n >= 0 ) {
-            if ( $width_n > 0 or $height_n > 0 ) {
-                $command .= " -X $height_n,$width_n";
-                $command .= ",$multiple_of" if $multiple_of != 32;
-            }
-            elsif ( $width_n < 0 or $height_n < 0 ) {
-                $width_n  = abs($width_n);
-                $height_n = abs($height_n);
-                $command .= " -B $height_n,$width_n";
-                $command .= ",$multiple_of" if $multiple_of != 32;
+            if ( $width_n * $height_n >= 0 ) {
+                if ( $width_n > 0 or $height_n > 0 ) {
+                    $command .= " -X $height_n,$width_n";
+                    $command .= ",$multiple_of" if $multiple_of != 32;
+                }
+                elsif ( $width_n < 0 or $height_n < 0 ) {
+                    $width_n  = abs($width_n);
+                    $height_n = abs($height_n);
+                    $command .= " -B $height_n,$width_n";
+                    $command .= ",$multiple_of" if $multiple_of != 32;
+                }
             }
         }
     }
@@ -4038,7 +4102,7 @@
     croak "msg:" . __ "No subtitle selected" if not $subtitle;
 
     my $clip2_bottom = $self->tc_clip2_bottom;
-    my $zoom_height  = $self->tc_zoom_height;
+    my $zoom_height  = $self->tc_zoom_height || $self->height;
     my $pre_zoom_height
         = $self->height - $self->tc_clip1_top - $self->tc_clip1_bottom;
     my $scale = $pre_zoom_height / $zoom_height;
signature.asc (application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQBHi9tc2hNi0Chc9HMRA05MAJ96s7WxanJk0cOa0kzuomlhjCqFVwCeItto
OsxFA9xeUnsE/6SXsj3jCDI=
=9U8S
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.