Ticket #2581: aspectRatio-0.21-fixes.patch
File aspectRatio-0.21-fixes.patch, 11.3 KB (added by , 16 years ago) |
---|
-
libs/libmythtv/recordingprofile.cpp
634 634 }; 635 635 }; 636 636 637 class MPEG4AspectRatio: public ComboBoxSetting, public CodecParamStorage { 638 public: 639 MPEG4AspectRatio(const RecordingProfile& parent): 640 ComboBoxSetting(this), 641 CodecParamStorage(this, parent, "mpeg4aspectratio") { 642 setLabel(QObject::tr("Aspect Ratio")); 643 addSelection("Leave", "Leave"); 644 addSelection("4:3", "4:3"); 645 addSelection("16:9", "16:9"); 646 setValue(0); 647 setHelpText(QObject::tr("Sets the aspect ratio of transcoded files")); 648 }; 649 }; 650 637 651 class EncodingThreadCount : public SliderSetting, public CodecParamStorage 638 652 { 639 653 public: … … 800 814 params->addChild(new MPEG4MinQuality(parent)); 801 815 params->addChild(new MPEG4QualDiff(parent)); 802 816 params->addChild(new ScaleBitrate(parent)); 817 params->addChild(new MPEG4AspectRatio(parent)); 803 818 804 819 HorizontalConfigurationGroup *hq; 805 820 hq = new HorizontalConfigurationGroup(false, false); -
programs/mythtranscode/transcode.cpp
472 472 int video_width = buf_size.width(); 473 473 int video_height = buf_size.height(); 474 474 475 float video_aspect = nvp->GetVideoAspect(); 476 float video_frame_rate = nvp->GetFrameRate(); 477 int newWidth = video_width; 478 int newHeight = video_height; 479 480 475 481 if (video_height == 1088) { 476 482 VERBOSE(VB_IMPORTANT, "Found video height of 1088. This is unusual and " 477 483 "more than likely the video is actually 1080 so mythtranscode " 478 484 "will treat it as such."); 479 485 } 480 481 float video_aspect = nvp->GetVideoAspect(); 482 float video_frame_rate = nvp->GetFrameRate(); 483 int newWidth = video_width; 484 int newHeight = video_height; 485 486 VERBOSE(VB_IMPORTANT, QString("Transcode: current aspect ratio: %1").arg(video_aspect)); 487 488 /* this allows transcoders to have fixed aspect ratios */ 489 float newAspect = video_aspect; 490 /* these elements control the on screen cropping */ 491 int crop_top, crop_bottom, crop_left, crop_right; 492 crop_top = crop_bottom = crop_left = crop_right = 0; 493 486 494 kfa_table = new QPtrList<struct kfatable_entry>; 487 488 495 if (fifodir == NULL) 489 496 { 490 497 if (!GetProfile(profileName, encodingType, video_height, … … 532 539 newHeight = (int)(1.0 * 640 * actualHeight / video_width); 533 540 } 534 541 } 542 /* hack by Patrick Wagstrom to ensure that aspect ratios are enforced 543 * if this is set to 43 then we crop the picture to fit the aspect ratio */ 544 if (vidsetting == "MPEG-4") 545 { 546 const Setting* setting = profile.byName("mpeg4aspectratio"); 547 if (setting) { 548 if (setting->getValue() == "4:3") { 549 VERBOSE(VB_IMPORTANT, QString("Transcoder calls for a 4:3 aspect ratio")); 550 newAspect = 1.333333333333; 551 } else if (setting->getValue() == "16:9") { 552 VERBOSE(VB_IMPORTANT, QString("Transcoder calls for a 16:9 aspect ratio")); 553 newAspect = 1.777777777777; 554 } else if (setting->getValue() == "Leave") { 555 VERBOSE(VB_IMPORTANT, QString("Transcoder leaves aspect ratio unchanged")); 556 } else { 557 VERBOSE(VB_IMPORTANT, QString("Transcode: unable to get aspect ratio")); 558 } 559 /* support for cropping... */ 560 if (abs(newAspect - video_aspect) > 0.01) { 561 /* calculate the actual pixel ratio for videos, needed 562 * when encoded without square pixels, such as 720x480 563 * NTSC captures */ 564 float pixelRatio = float(video_width)/float(video_height)/video_aspect; 565 /* scale the aspect ratio by the pixel ratio for the new sizes */ 566 float newAspectScaling = newAspect * pixelRatio; 567 if (abs(video_aspect - 1.77777) < 0.01) { 568 /* working with 16:9 source -- assume the height is correct */ 569 newWidth = (int)(newHeight * newAspectScaling); 570 crop_left = (int)(video_width - video_height*newAspectScaling)/2; 571 crop_right = crop_left; 572 /* while we're at it, kill the noise on the top of th screen too */ 573 crop_top = crop_top + 8; 574 VERBOSE(VB_IMPORTANT, QString("Transcode: removing top 8 pixels to get rid of garbage from Comcast")); 575 } else if (abs(video_aspect - 1.33333) < 0.01) { 576 /* working with 4:3 source -- assume the width is correct */ 577 newHeight = (int)(newWidth / newAspectScaling); 578 crop_top = (int)(video_height - video_width/newAspectScaling)/2; 579 crop_bottom = crop_top; 580 } else { 581 VERBOSE(VB_IMPORTANT, QString("Transcode: got a video with unknown aspect ratio %1").arg(video_aspect)); 582 } 583 } 584 } else { 585 VERBOSE(VB_IMPORTANT, QString("Transcode: unable to get aspect ratio")); 586 } 587 } 535 588 536 589 if (encodingType.left(4).lower() == "mpeg") 537 590 { … … 543 596 VERBOSE(VB_IMPORTANT, QString("Resizing from %1x%2 to %3x%4") 544 597 .arg(video_width).arg(video_height) 545 598 .arg(newWidth).arg(newHeight)); 599 VERBOSE(VB_IMPORTANT, QString("Crop Settings %1 %2 %3 %4") 600 .arg(crop_left).arg(crop_right) 601 .arg(crop_top).arg(crop_bottom)); 546 602 } 547 603 else // lossy and no resize 548 604 nvp->SetVideoFilters(vidfilters); … … 557 613 nvr->SetOption("vbiformat", gContext->GetSetting("VbiFormat")); 558 614 559 615 nvr->SetFrameRate(video_frame_rate); 560 nvr->SetVideoAspect(video_aspect); 616 /* update the aspect to the new video aspect */ 617 VERBOSE(VB_IMPORTANT, QString("Container Aspect Ratio Set to: %1").arg(newAspect)); 618 619 nvr->SetVideoAspect(newAspect); 561 620 nvr->SetTranscoding(true); 562 621 563 622 if (vidsetting == "MPEG-4") … … 859 918 if (! nvp->WriteStoredData(outRingBuffer, (did_ff == 0), 860 919 timecodeOffset)) 861 920 { 921 // TODO: check to make sure this doesn't blow out the new aspect ratio 862 922 if (video_aspect != nvp->GetVideoAspect()) 863 923 { 864 924 video_aspect = nvp->GetVideoAspect(); 925 926 VERBOSE(VB_IMPORTANT, QString("Overriding container aspect from %1 to %2").arg(newAspect).arg(video_aspect)); 865 927 nvr->SetNewVideoParams(video_aspect); 866 928 } 867 929 … … 897 959 video_width, video_height); 898 960 avpicture_fill(&imageOut, frame.buf, PIX_FMT_YUV420P, 899 961 newWidth, newHeight); 900 if (video_height != 1088) { 901 scontext = img_resample_init(newWidth, newHeight, 902 video_width, video_height); 903 } else { 904 scontext = img_resample_full_init(newWidth, newHeight, 905 video_width, video_height, 906 0,8,0,0,0,0,0,0); 962 if (video_height == 1088 && crop_bottom < 8) { 963 crop_bottom = 8; 907 964 } 965 // FIXME: Debugging code 966 VERBOSE(VB_IMPORTANT, QString("B Crop Settings %1 %2 %3 %4") 967 .arg(crop_left).arg(crop_right) 968 .arg(crop_top).arg(crop_bottom)); 969 970 scontext = img_resample_full_init(newWidth, newHeight, 971 video_width, video_height, 972 crop_top, crop_bottom, 973 crop_left, crop_right, 974 0,0,0,0); 908 975 img_resample(scontext, &imageOut, &imageIn); 909 976 img_resample_close(scontext); 910 977 } … … 923 990 (frame.timecode - lasttimecode - (int)vidFrameTime); 924 991 } 925 992 926 if ( video_aspect != nvp->GetVideoAspect())993 if (newAspect != nvp->GetVideoAspect()) 927 994 { 928 video_aspect = nvp->GetVideoAspect(); 929 nvr->SetNewVideoParams(video_aspect); 995 // used to check video aspect 996 // video_aspect = nvp->GetVideoAspect(); 997 nvr->SetNewVideoParams(newAspect); 930 998 } 931 999 932 1000 … … 955 1023 avpicture_fill(&imageOut, frame.buf, PIX_FMT_YUV420P, 956 1024 newWidth, newHeight); 957 1025 if (video_height != 1088) { 958 scontext = img_resample_init(newWidth, newHeight, 959 video_width, video_height); 1026 // FIXME: Debugging code 1027 /* VERBOSE(VB_IMPORTANT, QString("XY: Crop Settings %1 %2 %3 %4") 1028 .arg(crop_left).arg(crop_right) 1029 .arg(crop_top).arg(crop_bottom)); */ 1030 scontext = img_resample_full_init(newWidth, newHeight, 1031 video_width, video_height, 1032 crop_top, crop_bottom, 1033 crop_left, crop_right, 1034 0,0,0,0); 960 1035 } 961 1036 else 962 1037 { 1038 // FIXME: Debugging code 1039 /* VERBOSE(VB_IMPORTANT, QString("XX: Crop Settings %1 %2 %3 %4") 1040 .arg(crop_left).arg(crop_right) 1041 .arg(crop_top).arg(crop_bottom)); */ 1042 /* scontext = img_resample_full_init(newWidth, newHeight, 1043 video_width, video_height, 1044 crop_top, crop_bottom, 1045 crop_left, crop_right, 1046 0,0,0,0); */ 963 1047 scontext = img_resample_full_init(newWidth, newHeight, 964 1048 video_width, video_height, 965 1049 0,8,0,0,0,0,0,0);