Hello guys,
I use nvencc to convert 8K mp4 video files to a smaller size to use them as proxy in adobe premiere as the original files are too heavy and can't be edited smoothly. I have a RTX3070 TI Nvidia graphic card with a 12800HX intel CPU. For me the output quality has almost no importance as they are used as proxy and deleted. What I want to achieve is the FASTEST possible convert speed as I have tens of these files to work on everyday.
I found a script on a forum that I use (I drag and drop files and the proxy is made using nvencc) , But I want to use Staxrip (or any other gui software if there is a better one for this purpose ) so I can also crop the video files (remove half of the left part). (These are 3d SBS videos).
Can someone please help me find the best settings to achieve fastest encode? I tried many settings but the speed is too slow (around 40FPS) compared to 120~140 fps I get when using the script.
For reference here is a part of the script which I use :
if not exist "%ProxyDir%\%~n1_proxy.mp4" (
if /I not "%~x1" == ".avi" (
"%~dp0nvencc\NVEncC64.exe" -i "%~1" -o "%ProxyDir%\%~n1_proxy.mp4" --output-res 960x-2 -c h264 --preset quality --cqp 23:25:28 --aq-strength 10 --ref 1 --bframes 0 --gop-len 15 --lookahead 15 --qp-max 30 --aq --cabac --mv-precision q-pel --avsync cfr --colorprim auto --transfer auto --colormatrix auto --colorrange auto
) else (
"%~dp0nvencc\NVEncC64.exe" -i "%~1" -o "%ProxyDir%\%~n1_proxy.mp4" --output-res 960x-2 -c h264 --preset quality --cqp 23:25:28 --aq-strength 10 --ref 1 --bframes 0 --gop-len 15 --lookahead 15 --qp-max 30 --aq --cabac --mv-precision q-pel --avsync cfr
)
Try StreamFab Downloader and download from Netflix, Amazon, Youtube! Or Try DVDFab and copy Blu-rays!
+ Reply to Thread
Results 1 to 29 of 29
Thread
-
-
You can add crop to the NVEncC64 script
Code:--crop <int>,<int>,<int>,<int> crop pixels from left,top,right,bottom left crop is unavailable with avhw reader
-
-
Thanks for your replies. I really don't mind if the crop is done on left or right side. What I need is to be able to crop exactly half of the screen from whichever side. in the example below you see a screenshot of a video file. I have marked the left side with a red surrounding and the right side with a green one. I would like to remove one of them.
[Attachment 80749 - Click to enlarge]
I could not get the command to work as I don't know how to use it. I would love if it worked like this:
--crop <0>,<0>,<50%>,<0>
I'm totally ignorant on how all this work and this is why I am asking the question here. Unfortunately I need a "For dummies" kind of answer. -
In NVEnc, you can not use percentages when cropping.
You would need to provide the amount of pixels you want to crop.
For a video with a resolution of 3840x2160, the crop would be --crop 0,0,1920,0
As for the 8k video, it should have 7680x4320 pixels; correct me if I'm wrong.
To crop 50%, you would need to divide the 7680 by 2, which equals 3840.
In this scenario, the crop setting would be --crop 0,0,3840,0 to crop the right
or --crop 3840,0,0,0 to crop the left
Outtake from Rigayas NVEnc options list
--crop <int>,<int>,<int>,<int>
Number of pixels to cropped from left, top, right, bottom.Last edited by dietboby; 15th Jul 2024 at 19:10.
-
-
Why not use ffmpeg for this? You can crop relative to the video's width, eg, w=iw/2 (where iw is the input width).
https://ffmpeg.org/ffmpeg-filters.html#crop
Of course, it supports resizing too.
http://trac.ffmpeg.org/wiki/Scaling
And ffmpeg supports the nvenc encoder:
https://docs.nvidia.com/video-technologies/video-codec-sdk/11.1/ffmpeg-with-nvidia-gpu...celIntro#NVENC
You can easily convert a folder full of files using a batch file.
For example, this batch file will crop (keeping the left half), resize, and encode to h.264:
Code:ffmpeg -y -i "%~dpnx1" -pix_fmt yuv420p ^ -vf crop=iw/2:ih:0:0,scale=iw/2:ih/4 ^ -c:v h264_nvenc -preset fast -cq:v 23 -g 24 ^ -colorspace bt709 -color_range tv ^ -acodec copy -map 0 -c:s copy ^ "%~dpn1.h264.nvenc.mkv" pause
Last edited by jagabo; 16th Jul 2024 at 17:16.
-
wow! thanks a lot for your post and your advice. in fact your method is more practical as with your w=iw/2 command there is no need to calculate the crop amount for each media and enter it manually in the script each time. I don't mind using any encoder as long as I get the desired result in the fastest possible way. I just tried your script and it worked perfectly fine. But there is just one problem. When using my own script my laptop CPU load is at max 8 to 10% and the video decoder on the GPU is at 99%. The laptop remains cool (60 degrees centigrade). But when I use your script the CPU is working at 80 to 85% and the gpu is used only @25% and I reach 85 degrees. It seems that the video decoding (which seem to be the speed bottleneck as well ) is done by the CPU and not the GPU?! is there anyway to change the script, so it uses the GPU instead?
Edit:
Adding "-hwaccel cuda" to the script made it MUCH better. now cpu usage has fallen to 37% and the GPU is up to 75%
Can you think of anything else I can add to get the same result as with my script?
Last edited by rezpower; 16th Jul 2024 at 19:37.
-
Yes, adding "-hwaccel cuda" will get you GPU decoding an reduce CPU load. I usually don't use it because it slows down my processing.
You can a list of h264_nvenc options with:
Code:ffmpeg -? encoder=h264_nvenc
Code:ffmpeg -? encoder=h264_nvenc >help_h264_nvenc.txt
Last edited by jagabo; 16th Jul 2024 at 20:26.
-
Thanks a lot for your time jagabo,
I Learned a lot from you already and started playing around with different settings, which is enjoyable. -
You might want to use the setsar filter to "fix" the aspect ratio. And use Start to run the process at low priority if you want to use the computer while it's encoding:
Code:start /b /low "ffmpeg" ffmpeg -y -hwaccel cuda ^ -i "%~dpnx1" -pix_fmt yuv420p ^ -vf crop=iw/2:ih:0:0,scale=iw/4:ih/8,setsar=1:1 ^ -c:v h264_nvenc -preset fast -cq:v 23 -g 24 ^ -colorspace bt709 -color_range tv ^ -acodec copy -map 0 -c:s copy ^ "%~dpn1.h264.nvenc.mkv" pause
If you put that batch file in your Send To folder you can right click on a video and select Send To -> name.bat to process the video. Where name.bat is whatever you named the batch file. -
I have done a lot of testing and the above script works perfect with some 8K files converting at high fps and on some files the fps drops to 70 ~ 80!
The NVEncC64 script encodes all videos the same way and all of them are encoding at above 160fps. Also the NVEncC64 script uses 8 to 10% CPU while the ffmgeg one uses around 40% CPU and not using full capacity of the GPU (between 75 and 80%). I don't know if a setting in this script makes it slower then the NVEncC64 one or if it's ffmpeg itself! -
NVEncC64 may be doing the scaling and cropping with the GPU. When using ffmpeg the video is copied back and forth between CPU and GPU memory, slowing things down. If you can figure out how to crop and scale with the GPU all the video processing will take place in GPU memory, speeding things up and reducing CPU load.
-
You can use GPU crop and scale with some ffmpeg decoders, but they do not accept variables like "normal" ffmpeg filters such as iw, ih .
eg. if input video was h264 you would specify the video decoder, and -crop and/or -resize arguments as input options (ffmpeg "input options" must be specified before the -i )
something like this
Code:ffmpeg -c:v h264_cuvid -crop 0x0x3840x0 -i input.ext ....
Code:h264_cuvid AVOptions: -deint <int> .D.V....... Set deinterlacing mode (from 0 to 2) (default weave) weave 0 .D.V....... Weave deinterlacing (do nothing) bob 1 .D.V....... Bob deinterlacing adaptive 2 .D.V....... Adaptive deinterlacing -gpu <string> .D.V....... GPU to be used for decoding -surfaces <int> .D.V......P Maximum surfaces to be used for decoding (from -1 to INT_MAX) (default -1) -drop_second_field <boolean> .D.V....... Drop second field when deinterlacing (default false) -crop <string> .D.V....... Crop (top)x(bottom)x(left)x(right) -resize <string> .D.V....... Resize (width)x(height)
That was a copy/paste from the binary help file (NVEncC64 --help 1>help.txt) . The left crop comment must be left over from an older version, because yes left crop does work even when you specify -avhw on the recent versionLast edited by poisondeathray; 17th Jul 2024 at 21:49.
-
You can get a video's width and height in a batch file with ffprobe:
Code:ffprobe -v quiet -show_entries stream=width -of default=noprint_wrappers=1:nokey=1 -select_streams v:0 %1 > %1.txt set /p width= < %1.txt ffprobe -v quiet -show_entries stream=height -of default=noprint_wrappers=1:nokey=1 -select_streams v:0 %1 > %1.txt set /p height= < %1.txt del %1.txt REM at this point the environment variables "width" and "height" are set the width and height of the video: echo %width% x %height%
-
Thanks jagabo. I use MediaInfo to get the video information and it's very easy to use and practical.
For now I have to stick to my old nvencc script as it is the fastest way and the only inconvenience is that I have to enter crop size for each media. I don't even know if it's a good idea to crop! I wanted to crop the video so the decoder and encoder have both less work to do (half). But it seems this is not the case!?
@poisondeathray, thanks a lot for your input. All videos I need to convert are hevc. -
Here's a batch file that gets video width and height via MediaInfo and uses nvencc to crop to half width, resize to 1/8 width and 1/8 height, then encoded. Ie, a 7680x4320 video is cropped to 3840x4320 (keeping the left half), resized to 960x540, then encoded with settings taken from the nvencc command line in the first post. It runs at about 138 fps here. Video Decode of the source appears to be the limiting factor.
Code:"G:\Program Files\MediaInfoCLI\MediaInfo.exe" --inform=Video;%%Width%% "%~dpnx1" > "test.txt" set /p width= < "test.txt" "G:\Program Files\MediaInfoCLI\MediaInfo.exe" --inform=Video;%%Height%% "%~dpnx1" > "test.txt" set /p height= < "test.txt" del "test.txt" set /a hwidth=%width%/2 set /a ewidth=%width%/8 set /a eheight=%height%/8 REM start /b /low "nvencc" "G:\Program Files\NVEncC\NVEncC64.exe" -i "%~1" -o "%~dpn1.proxy.mkv" --crop 0,0,%hwidth%,0 --output-res %ewidth%x%eheight% -c h264 --preset quality --cqp 23:25:28 --aq-strength 10 --ref 1 --bframes 0 --gop-len 15 --lookahead 15 --qp-max 30 --aq --cabac --mv-precision q-pel --avsync cfr pause
-
Thanks a lot jagabo,
I can't wait to test this script. But unfortunately there is something wrong (I guess with mediainfo part) of the script.
When I drop the video file on the script mediainfo opens and stays open like this:
[Attachment 80852 - Click to enlarge]
If I close it, it will do the same again and it will open mediainfo for a second time and remain open the same way. After I close the second one the script will end with error:
C:\Users\Elitebook\Desktop>set /p height= 0<"test.txt"
C:\Users\Elitebook\Desktop>del "test.txt"
C:\Users\Elitebook\Desktop>set /a hwidth=/2
Missing operand.
C:\Users\Elitebook\Desktop>set /a ewidth=/8
Missing operand.
C:\Users\Elitebook\Desktop>set /a eheight=/8
Missing operand.
C:\Users\Elitebook\Desktop>REM start /b /low "nvencc"
C:\Users\Elitebook\Desktop>"D:\Software\Shared Programs Elitebook\!proxy generator\nvencc\NVEncC64.exe" -i "C:\Users\Elitebook\Desktop\2024-07-19 05-12-19.mp4" -o "C:\Users\Elitebook\Desktop\2024-07-19 05-12-19.proxy.mp4" --crop 0,0,,0 --output-res x -c h264 --preset quality --cqp 23:25:28 --aq-strength 10 --ref 1 --bframes 0 --gop-len 15 --lookahead 15 --qp-max 30 --aq --cabac --mv-precision q-pel --avsync cfr
Error: Invalid value "0,0,,0" for "--crop"
it seems that txt files generated by mediainfo are empty!? -
-
This is a very smart solution! It's now working and yes, the problem as you said was that I only had the GUI version of MediaInfo. The CLI is a different download and I got it from this link: https://mediaarea.net/download/binary/mediainfo/24.06/MediaInfo_CLI_24.06_Windows_x64.zip
There is now still ONE remaining problem: The aspect ratio is wrong! The aspect ratio on the video I just encoded for test was 2.000 and it is still 2 on the encoded one. If we cropped half of the video shouldn't the aspect ratio change accordingly? -
The sample images you posted in the first video had two 16:9 videos squeezed side-by-side into a single 16:9 frame. So the script I gave you restores the display aspect ratio -- it shows the frame as it would be seen on a 3D TV (minus the 3D, of course). If you want to keep the horizontally squeezed frame just change the horizontal resizing parameter:
Code:set /a ewidth=%width%/8
Code:set /a ewidth=%width%/16
Are you getting the encoding speed you want from this batch file? -
This is the full original script I was using. The part I pasted here on my first post was copied from this script. This script makes a proxy directory on desktop (or any place you choose) and puts the encodes inside that folder. It also changes windows power profile and prevents windows from shutdown and when the job is done it will shutdown windows, unless you cancel shutdown at prompt.
For this script to work, you need to run it from the same folder, where your NVEncC64.exe is located. Going to try and see if I can integrate the content of your batch file into this script.
Code:@echo off for /f "tokens=4 delims= " %%f in ('powercfg /getactivescheme') do ( set ACTIVE_SCHEME=%%f ) powercfg /setactive 6ff28809-1a19-42c9-871d-92674ac92e45 setlocal EnableExtensions DisableDelayedExpansion set "t0=%TIME%, %DATE%" set "RestoreFolder=" set "ProxyDir=%USERPROFILE%\Desktop\Proxy" if not exist "%ProxyDir%" mkdir "%ProxyDir%" rem Is the batch file started without any argument (or with first argument rem being an empty string)? Yes, process all video files in current directory. if "%~1" == "" goto AllFiles rem Is the batch file started not with a folder name as first argument? rem Yes, the first argument is most likely a file name and so just a rem single file should be processed by the batch file. if not exist "%~1\" goto SingleFile rem The batch file is started with a folder name as first argument. rem Make this folder the current directory using command PUSHD and rem if that is successfull process all video files in that folder. pushd "%~1" 2>nul if not errorlevel 1 set "RestoreFolder=1" & goto AllFiles echo ERROR: Failed to make "%~1" the current directory! echo/ pause exit /B 1 :AllFiles for %%i in (*.mp4 *.avi *.mov *.wmv *.ts *.m2ts *.mkv) do if not exist "%ProxyDir%\%%~ni_proxy.mp4" ( if /I not "%%~xi" == ".avi" ( "%~dp0nvencc\NVEncC64.exe" -i "%%i" -o "%ProxyDir%\%%~ni_proxy.mp4" --crop 0,0,3584,0 --output-res 960x-2 -c h264 --preset quality --cqp 23:25:28 --aq-strength 10 --ref 1 --bframes 0 --gop-len 15 --lookahead 15 --qp-max 30 --aq --cabac --mv-precision q-pel --avsync cfr --colorprim auto --transfer auto --colormatrix auto --colorrange auto ) else ( "%~dp0nvencc\NVEncC64.exe" -i "%%i" -o "%ProxyDir%\%%~ni_proxy.mp4" --crop 0,0,3584,0 --output-res 960x-2 -c h264 --preset quality --cqp 23:25:28 --aq-strength 10 --ref 1 --bframes 0 --gop-len 15 --lookahead 15 --qp-max 30 --aq --cabac --mv-precision q-pel ) ) if defined Restorefolder popd goto OutputInfo :SingleFile if exist "%~1" goto ProcessFile echo ERROR: Could not find "%~1"! echo/ pause exit /B 1 :ProcessFile if not exist "%ProxyDir%\%~n1_proxy.mp4" ( if /I not "%~x1" == ".avi" ( "%~dp0nvencc\NVEncC64.exe" -i "%~1" -o "%ProxyDir%\%~n1_proxy.mp4" --crop 0,0,3584,0 --output-res 960x-2 -c h264 --preset quality --cqp 23:25:28 --aq-strength 10 --ref 1 --bframes 0 --gop-len 15 --lookahead 15 --qp-max 30 --aq --cabac --mv-precision q-pel --avsync cfr --colorprim auto --transfer auto --colormatrix auto --colorrange auto ) else ( "%~dp0nvencc\NVEncC64.exe" -i "%~1" -o "%ProxyDir%\%~n1_proxy.mp4" --crop 0,0,3584,0 --output-res 960x-2 -c h264 --preset quality --cqp 23:25:28 --aq-strength 10 --ref 1 --bframes 0 --gop-len 15 --lookahead 15 --qp-max 30 --aq --cabac --mv-precision q-pel --avsync cfr ) ) :OutputInfo %SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe write-host -fore cyan ====================== Processing is FINISHED ======================= echo ---------------------------- echo Batch processing start time: %t0% echo Batch processing end time: %TIME%, %DATE% echo ---------------------------- endlocal @ECHO OFF powercfg /change standby-timeout-ac 20 :myLabel SHUTDOWN /S /F /T 600 SET /P continue="Your computer is about to shutdown in 10 min do you want to abort (y/n): " IF %continue% EQU y ( SHUTDOWN /A )
Last edited by rezpower; 21st Jul 2024 at 08:49.
-
YES! the speed is now perfect. It's using my max decoding capability and only 7% CPU
I will test your resizing parameter change and report back
Edit: I just tested the script with ewidth=%width%/16 and the aspect ratio problem is totally fixed!
Don't know how to thank you for all your precious help jagabo.Last edited by rezpower; 20th Jul 2024 at 22:36.
-
Hi jagabo,
I encoded few videos tonight and the script is working for some of them and on others I am getting invalid resolution error!
Here is an example:
Invalid resolution.: 453x453
Relosution of mod2 required.
in this example the original video's resolution is:
Width : 7260 pixel
Height : 3630 pixel
what do you think ?Last edited by rezpower; 21st Jul 2024 at 22:24.
-
I was going to point out that the script wouldn't work when the target frame size had odd values for the width or height. You would have to modify the calculations to always deliver an even value. I'm not at my usual computer now but off the top of my head I think this should work:
instead of:
Code:set /a ewidth=%width%/8
Code:set /a ewidth=%width%/16*2
I thought all the files you were converting were 7680x4320 so that wouldn't be an issue.Last edited by jagabo; 22nd Jul 2024 at 00:51.
-
I tried 16*2 , but still not working :
Invalid resolution.: 906x453
Relosution of mod2 required.
if we can not find a way to force a valid resolution, why not let the script only do the crop calculation , but set a costume fix resolution like: --output-res 960x-2 ?
After all the encoded file is only used as proxy in adobe premiere to make cuts and edits and the final render is going to be done on the original file.
I just tried this and it works.
Similar Threads
-
How to use NVencC as external encoder in VirtualDub 2 ?
By spapakons in forum Video ConversionReplies: 14Last Post: 2nd Aug 2024, 16:54 -
Frame order errors in StaxRip x265 encode
By BirdmanF1 in forum Video ConversionReplies: 7Last Post: 1st Apr 2021, 15:18 -
Staxrip won't encode my subtitles
By sNkClAuDiU in forum DVD RippingReplies: 2Last Post: 7th May 2020, 20:52 -
NVENC Staxrip Anime Encode High Noise Problem
By Ykefas in forum RestorationReplies: 3Last Post: 12th Aug 2019, 03:12