@cartman0208
I made some further modifications to the script.
Please test it to see if there are any issues.
Revised script:
Disclaimer for Blu-ray Compliance and Playback:
Example of Enhanced Aspect Ratio Handling:
I made some further modifications to the script.
Please test it to see if there are any issues.
Key Changes Explained
- Aspect Ratio Calculation and Analysis:
- What's New: The first script only calculates the aspect ratio based on the resolution. The second script extracts the aspect ratio directly from the video file using MediaInfo and then calculates the closest standard aspect ratio (4:3 or 16:9).
- Script Note: The second script includes a more accurate method for determining the video's aspect ratio, leading to more precise adjustments in resolution and padding.
- Automated Resolution and Aspect Ratio Selection:
- What's New: The first script compares two standard aspect ratios (1080p and 720p) based on the calculated aspect ratio. The second script, however, uses the actual aspect ratio from the video file to decide between two standard aspect ratios (4:3 and 16:9) and sets the target resolution accordingly.
- Script Note: The second script provides a more sophisticated approach to selecting the target resolution and aspect ratio, ensuring a better match with the original video's properties.
- Handling of Smaller Resolutions:
- What's New: The first script does not explicitly address smaller resolutions. The second script includes logic to handle smaller resolutions more effectively, especially when the aspect ratio is closer to 4:3.
- Script Note: The second script includes checks for smaller resolutions to avoid unnecessary padding, making it more efficient for a broader range of video sizes.
- Simplified and Streamlined Process:
- What's New: The second script streamlines the process by automating the selection of resolution and aspect ratio based on the video file's properties, whereas the first script relies more on predefined standard resolutions.
- Script Note: The second script enhances user experience by reducing manual inputs and automating key decisions, making the process more efficient and user-friendly.
- Drag-and-Drop Functionality:
- Both Scripts: Both scripts are designed with a drag-and-drop feature, where you can drag your video file onto the batch file for processing. This functionality remains consistent in both scripts.
- Both Scripts: Both scripts are designed with a drag-and-drop feature, where you can drag your video file onto the batch file for processing. This functionality remains consistent in both scripts.
- Overall Enhancement:
- What's New: The second script significantly improves the accuracy of determining the input video file's best resolution and aspect ratio. This leads to better output quality and a more reliable video processing experience.
- Script Note: The enhancements in the second script make it more versatile and suitable for a broader range of video files, especially in handling different aspect ratios and resolutions.
Revised script:
Code:
@echo off
REM Set the paths for MediaInfo and NVEncC
set MEDIAINFO_PATH=E:\rigaya\MediaInfo\MediaInfo.exe
set NVENCC_PATH=E:\rigaya\NVEncC\NVEncC64.exe
REM Use MediaInfo to get the resolution and aspect ratio of the input file and write them to temporary files
"%MEDIAINFO_PATH%" "--Inform=Video;%%Width%%x%%Height%%" %1 > "%~1.resolution.txt"
"%MEDIAINFO_PATH%" "--Inform=Video;%%DisplayAspectRatio/String%%" %1 > "%~1.aspectratio.txt"
REM Read the resolution from the temporary file
for /f "tokens=1,2 delims=x" %%A in ('type "%~1.resolution.txt"') do (
set Width=%%A
set Height=%%B
)
REM Read the aspect ratio from the temporary file
set /p AspectRatioString=<"%~1.aspectratio.txt"
REM Split the aspect ratio string into two parts (X and Y)
for /f "tokens=1,2 delims=:" %%A in ("%AspectRatioString%") do (
set AspectRatioX=%%A
set AspectRatioY=%%B
)
REM Convert the aspect ratio to a decimal
set /a AspectRatio=10000*%AspectRatioX%/%AspectRatioY%
REM Define standard aspect ratios
set /a AspectRatio4_3=10000*4/3
set /a AspectRatio16_9=10000*16/9
REM Calculate the difference in aspect ratios
set /a Diff4_3=%AspectRatio%-%AspectRatio4_3%
if %Diff4_3% LSS 0 set /a Diff4_3=-%Diff4_3%
set /a Diff16_9=%AspectRatio%-%AspectRatio16_9%
if %Diff16_9% LSS 0 set /a Diff16_9=-%Diff16_9%
REM Choose the closest standard aspect ratio
if %Diff4_3% LEQ %Diff16_9% (
REM For 4:3 aspect ratio
if %Width% LEQ 960 (
if %Height% LEQ 720 (
set TARGET_WIDTH=960
set TARGET_HEIGHT=720
) else (
set TARGET_WIDTH=1440
set TARGET_HEIGHT=1080
)
) else (
set TARGET_WIDTH=1440
set TARGET_HEIGHT=1080
)
set TARGET_ASPECT_RATIO=4:3
) else (
REM For 16:9 aspect ratio
if %Width% LEQ 1280 (
if %Height% LEQ 720 (
set TARGET_WIDTH=%Width%
set TARGET_HEIGHT=%Height%
) else (
set TARGET_WIDTH=1920
set TARGET_HEIGHT=1080
)
) else (
set TARGET_WIDTH=1920
set TARGET_HEIGHT=1080
)
set TARGET_ASPECT_RATIO=16:9
)
REM Calculate padding needed to adjust the video to the target resolution
set /a Width_ADJUST=(%TARGET_WIDTH%-%Width%)/2
set /a Height_ADJUST=(%TARGET_HEIGHT%-%Height%)/2
REM Delete the temporary files
del "%~1.resolution.txt" > NUL 2>&1
del "%~1.aspectratio.txt" > NUL 2>&1
REM Run NVEncC with the calculated parameters
"%NVENCC_PATH%" -i %1 --option-file "E:\rigaya\BluRay.txt" -o "%~1.out.m2ts" --vpp-pad %Width_ADJUST%,%Height_ADJUST%,%Width_ADJUST%,%Height_ADJUST%
REM Pause the script to view any messages before closing
PAUSE
Disclaimer for Blu-ray Compliance and Playback:
- Important Note: Users should verify that the processed video's final resolution and aspect ratio comply with Blu-ray standards and are suitable for playback on typical Blu-ray players and displays. While the script adjusts the video to common Blu-ray resolutions, it's crucial to consider how different aspect ratios will be displayed.
- 4:3 Aspect Ratio on 16:9 Displays: For videos in a 4:3 aspect ratio, Blu-ray players and most modern displays will automatically add black bars (pillarboxing) to the sides of the video when played back on a 16:9 screen. This ensures that the video maintains its original aspect ratio without distortion. The script does not need to add these bars; they are typically added during playback by the player or display device.
- Ensuring Playback Quality: Testing the processed video on the intended playback device or software is recommended to ensure that it displays correctly, especially for videos with non-standard aspect ratios or resolutions. This testing is crucial to confirm that the video meets Blu-ray standards and provides an optimal viewing experience.
Example of Enhanced Aspect Ratio Handling:
- First Script (Old Method):
- The first script calculates the aspect ratio solely based on the resolution of the video. It uses the formula: AspectRatioInput = 10000 * Width / Height.
- This method can be inaccurate for videos with non-square pixels or formatted to fit different aspect ratios. It assumes that the pixel aspect ratio is 1:1, which isn't always true.
- Second Script (Improved Method):
- The second script uses MediaInfo to extract the display aspect ratio from the video file directly. This is done using the command: "%MEDIAINFO_PATH%" "--Inform=Video;%%DisplayAspectRatio/String%%" %1 > "%~1.aspectratio.txt".
- It then reads this aspect ratio from the temporary file and splits it into two parts (X and Y) using a for loop: for /f "tokens=1,2 delims=:" %%A in ("%AspectRatioString%") do (set AspectRatioX=%%A set AspectRatioY=%%B).
- The script calculates the aspect ratio as a decimal value for easier comparison: set /a AspectRatio=10000*%AspectRatioX%/%AspectRatioY%.
- It then compares this extracted aspect ratio with standard aspect ratios (4:3 and 16:9) and selects the closest match. This approach is more accurate as it considers the actual display aspect ratio of the video, which can differ from the aspect ratio derived from resolution alone.
- The new method is more reliable for videos where the pixel aspect ratio is not 1:1, or the video has been formatted to fit a specific display aspect ratio.
- This improvement ensures that the script can handle a broader range of videos more accurately, especially those with non-standard aspect ratios or those that have been edited for specific display formats.