Index: libs/libmythtv/recordingprofile.cpp
===================================================================
--- libs/libmythtv/recordingprofile.cpp	(revision 14391)
+++ libs/libmythtv/recordingprofile.cpp	(working copy)
@@ -434,6 +434,20 @@
     };
 };
 
+class MPEG4AspectRatio: public CodecParam, public ComboBoxSetting {
+public:
+   MPEG4AspectRatio(const RecordingProfile& parent):
+        CodecParam(parent, "mpeg4aspectratio") {
+        setLabel(QObject::tr("Aspect Ratio"));
+        addSelection("Leave", "Leave");
+        addSelection("4:3", "4:3");
+        addSelection("16:9", "16:9");
+        setValue(0);
+        setHelpText(QObject::tr("Sets the aspect ratio of transcoded files"));
+    };
+};
+
+
 class EncodingThreadCount: public CodecParam, public SliderSetting {
 public:
     EncodingThreadCount(const RecordingProfile& parent):
@@ -581,6 +595,7 @@
         params->addChild(new MPEG4MinQuality(parent));
         params->addChild(new MPEG4QualDiff(parent));
         params->addChild(new MPEG4ScaleBitrate(parent));
+        params->addChild(new MPEG4AspectRatio(parent));
 
         HorizontalConfigurationGroup *hq;
         hq = new HorizontalConfigurationGroup(false, false);
Index: programs/mythtranscode/transcode.cpp
===================================================================
--- programs/mythtranscode/transcode.cpp	(revision 14391)
+++ programs/mythtranscode/transcode.cpp	(working copy)
@@ -388,8 +388,21 @@
     int newWidth = video_width;
     int newHeight = video_height;
 
+    
+    if (video_height == 1088) {
+       VERBOSE(VB_IMPORTANT, "Found video height of 1088.  This is unusual and "
+               "more than likely the video is actually 1080 so mythtranscode "
+               "will treat it as such.");
+    }
+    VERBOSE(VB_IMPORTANT, QString("Transcode: aspect ratio: %1").arg(video_aspect));
+    
+    /* this allows transcoders to have fixed aspect ratios */
+    float newAspect = video_aspect;
+    /* these elements control the on screen cropping */
+    int crop_top, crop_bottom, crop_left, crop_right;
+    crop_top = crop_bottom = crop_left = crop_right = 0;
+    
     kfa_table = new QPtrList<struct kfatable_entry>;
-
     if (fifodir == NULL)
     {
         if (!GetProfile(profileName, encodingType)) {
@@ -415,26 +428,66 @@
         }
         else if (profile.byName("transcoderesize")->getValue().toInt())
         {
+        	int actualHeight = (video_height == 1088 ? 1080 : video_height);
+        	
             nvp->SetVideoFilters(vidfilters);
             newWidth = profile.byName("width")->getValue().toInt();
             newHeight = profile.byName("height")->getValue().toInt();
 
             // If height or width are 0, then we need to calculate them
             if (newHeight == 0 && newWidth > 0)
-                newHeight = (int)(1.0 * newWidth * video_height / video_width);
+                newHeight = (int)(1.0 * newWidth * actualHeight / video_width);
             else if (newWidth == 0 && newHeight > 0)
-                newWidth = (int)(1.0 * newHeight * video_width / video_height);
+                newWidth = (int)(1.0 * newHeight * video_width / actualHeight);
             else if (newWidth == 0 && newHeight == 0)
             {
                 newHeight = 480;
-                newWidth = (int)(1.0 * 480 * video_width / video_height);
+                newWidth = (int)(1.0 * 480 * video_width / actualHeight);
                 if (newWidth > 640)
                 {
                     newWidth = 640;
-                    newHeight = (int)(1.0 * 640 * video_height / video_width);
+                    newHeight = (int)(1.0 * 640 * actualHeight / video_width);
                 }
             }
-
+            /* hack by Patrick Wagstrom to ensure that aspect ratios are enforced
+             * if this is set to 43 then we crop the picture to fit the aspect ratio */
+            if (vidsetting == "MPEG-4")
+            {
+               const Setting* setting = profile.byName("mpeg4aspectratio");
+               if (setting) {
+                    if (setting->getValue() == "4:3") {
+                        VERBOSE(VB_IMPORTANT, QString("Transcoder calls for a 4:3 aspect ratio"));
+                        newAspect = 1.333333333333;
+                    } else if (setting->getValue() == "16:9") {
+                        VERBOSE(VB_IMPORTANT, QString("Transcoder calls for a 16:9 aspect ratio"));
+                        newAspect = 1.777777777777;
+                    } else if (setting->getValue() == "Leave") {
+                        VERBOSE(VB_IMPORTANT, QString("Transcoder leaves aspect ratio unchanged"));
+                    } else {
+                        VERBOSE(VB_IMPORTANT, QString("Transcode: unable to get aspect ratio"));
+                    }
+                    /* support for cropping... */
+                    if (abs(newAspect - video_aspect) > 0.01) {
+                        if (abs(video_aspect - 1.77777) < 0.01) {
+                            /* working with 16:9 source -- assume the height is correct */
+                            crop_left = (int)(video_width - (video_height * newAspect))/2;
+                            crop_right = crop_left;
+                            newWidth = (int)(newHeight * newAspect);
+                            /* while we're at it, kill the noise on the top of th screen too */
+                            crop_top = crop_top + 8;
+                            VERBOSE(VB_IMPORTANT, QString("Transcode: removing top 8 pixels to get rid of garbage from Comcast"));                            
+                        } else if (abs(video_aspect - 1.33333) < 0.01) {
+                            /* working with 4:3 source -- assume the width is correct */
+                            crop_top = (int)(video_height - (video_width / newAspect))/2;
+                            crop_bottom = crop_top;
+                            newHeight = (int)(newWidth / newAspect);
+                        }
+                    }
+                } else {
+                    VERBOSE(VB_IMPORTANT, QString("Transcode: unable to get aspect ratio"));
+                }
+            }
+            
             if (encodingType.left(4).lower() == "mpeg")
             {
                 // make sure dimensions are valid for MPEG codecs
@@ -445,6 +498,9 @@
             VERBOSE(VB_IMPORTANT, QString("Resizing from %1x%2 to %3x%4")
                     .arg(video_width).arg(video_height)
                     .arg(newWidth).arg(newHeight));
+            VERBOSE(VB_IMPORTANT, QString("Crop Settings %1 %2 %3 %4")
+                    .arg(crop_left).arg(crop_right)
+                    .arg(crop_top).arg(crop_bottom));
         }
         else  // lossy and no resize
             nvp->SetVideoFilters(vidfilters);
@@ -469,7 +525,7 @@
             SetProfileOption(profile, "mpeg4qualdiff");
             SetProfileOption(profile, "mpeg4optionvhq");
             SetProfileOption(profile, "mpeg4option4mv");
-            nvr->SetupAVCodec();
+           nvr->SetupAVCodec();
         }
         else if (vidsetting == "RTjpeg")
         {
@@ -504,7 +560,8 @@
         nvr->AudioInit(true);
 
         nvr->SetFrameRate(video_frame_rate);
-        nvr->SetVideoAspect(video_aspect);
+        /* update the aspect to the new video aspect */
+        nvr->SetVideoAspect(newAspect);
         nvr->SetTranscoding(true);
 
         outRingBuffer = new RingBuffer(outputname, true, false);
@@ -785,9 +842,15 @@
                     avpicture_fill(&imageIn, lastDecode->buf, PIX_FMT_YUV420P,
                                    video_width, video_height);
                     avpicture_fill(&imageOut, frame.buf, PIX_FMT_YUV420P,
-                                   newWidth, newHeight);
-                    scontext = img_resample_init(newWidth, newHeight,
-                                                 video_width, video_height);
+                                   newWidth, newHeight);                    
+                    if (video_height == 1088 && crop_bottom < 8) {
+                    	crop_bottom = 8;
+                    }
+                    scontext = img_resample_full_init(newWidth, newHeight,
+                    		video_width, video_height,
+                    		crop_top, crop_bottom, crop_left, crop_right,
+                    		0,0,0,0);
+                    
                     img_resample(scontext, &imageOut, &imageIn);
                     img_resample_close(scontext);
                 }
@@ -806,10 +869,11 @@
                     (frame.timecode - lasttimecode - (int)vidFrameTime);
             }
 
-            if (video_aspect != nvp->GetVideoAspect())
+            if (newAspect != nvp->GetVideoAspect())
             {
-                video_aspect = nvp->GetVideoAspect();
-                nvr->SetNewVideoParams(video_aspect);
+                // used to check video aspect
+                // video_aspect = nvp->GetVideoAspect();
+                nvr->SetNewVideoParams(newAspect);
             }
 
             if (video_width != nvp->GetVideoWidth() || 
@@ -820,7 +884,7 @@
                 VERBOSE(VB_IMPORTANT, QString("Resizing from %1x%2 to %3x%4")
                         .arg(video_width).arg(video_height)
                         .arg(newWidth).arg(newHeight));
-            }
+           }
 
             if ((video_width == newWidth) && (video_height == newHeight))
             {
@@ -832,8 +896,16 @@
                                video_width, video_height);
                 avpicture_fill(&imageOut, frame.buf, PIX_FMT_YUV420P,
                                newWidth, newHeight);
-                scontext = img_resample_init(newWidth, newHeight,
-                                             video_width, video_height);
+                if (video_height != 1088) {
+                    scontext = img_resample_init(newWidth, newHeight,
+                                                 video_width, video_height);
+                }
+                else
+                {
+                    scontext = img_resample_full_init(newWidth, newHeight,
+                                                      video_width, video_height,
+                                                      0,8,0,0,0,0,0,0);
+                }
                 img_resample(scontext, &imageOut, &imageIn);
                 img_resample_close(scontext);
             }

