Hello. I have been given FFMPEG code to use by my job for encoding video for our site. I have been just using the one I was given for a while now until I noticed a few things and spoke to my boss. He said the goal was to make the video files as small as possible without an appreciable loss in quality. He had been given the code to use by someone else and says I am free to use any code I please as long as it works. I have also noticed that the code I am currently using uses the CPU instead of the GPU on my PC.
My question is, based on the code I am posting below, why are output videos at 60 frames per second? Why is FFMPEG not utilizing my graphics hardware, a GTX 1060?
ffmpeg -i "C:\Input Video.mp4" -c:v libx264 -c:a aac -b:a 128k -crf 30 -pix_fmt yuv420p "Output Video.mp4"
+ Reply to Thread
Results 1 to 12 of 12
https://git.videolan.org/git/ffmpeg/nv-codec-headers.git' - It is not a command and there is nothing at that URL as far as I understand. I am watching a video. I think I will figure it out. Any advice would be appreciated.
If you are on Win you need a precompiled version of ffmpeg from here
We also need to know what the bitrate of the video is that you are trying to reduce. Post the MediaInfo details of your video and we can then advise on a suitable syntax to reduce it.
Here is the definitive hw accel guide for ffmpeg. Personally, I would not do it for 'normal' bitrates, but thats just my opinion. It really only comes into the fore for mega high bitrates. (Someone will now come on and totally disagree). Read the docs and make your own mind up.
Last edited by codehound; 14th Oct 2021 at 04:19.
Based on the information we have at the moment, i dont think you need any special ffmpeg build or installing any additional software. All ffmpeg builds from zeranoe, gyandev and BtBn are shipped with Nvidia Hardware coding support as far as i know.
An example that encodes using the encoder chip built into your graphics card (NVENC) is:
ffmpeg -i "C:\Input Video.mp4" -c:v h264_nvenc -cq:v 19 -r 25 "OUTPUTFILE"
This will output 25fps because of the -r parameter.
Note that above we change from -crf to -cq... that is because -crf is not a valid option for the nvenc codecs, equivalent they have -cq. Also note that -crf 30 is not the same as cq 30, this is why i changed it to 19.
On a sidenote, the cpu based codec libx264 can produce much smaller files at the same quality compared to hardware encoders, so if we want to make a small file with good quality and we have the extra time needed, we use libx264 instead of hardware. Also, if you have an intel cpu, you might want to compare the output quality of the h264_nvenc codec with the h264_qsv (intel quicksync) codec. Compare the results to files generated by libx264 and then choose which encoder you use for the final result.
Last edited by emcodem; 14th Oct 2021 at 05:37.
Thank You for the response; I tried the test you suggested and the rendered file was way bigger; 2.5 GB vs 900 MB.
If this was the original code I was given
ffmpeg -i "C:\Input File" -c:v libx264 -c:a aac -b:a 128k -crf 30 -pix_fmt yuv420p "Output file.mp4"
then what is the 30 in that code? Where would I insert the ' -r 30 ' to reduce the frame rate from the original 60 to 30 FPS? Is that 30 in there for a reason right now, or is my code missing the -r ? I now see that CPU rendering is much smaller, which is more important for my purposes than faster. Do I just need to add -r in there in front of 30? Thank you.
Here is the information from one of the videos in that program.
For a 4h 6 min video with 1280x720 resolution the size is ok. There is nothing to change.
-crf 30 "is constant quality rate factor", think of it as level of quality. -crf 0 is lossless quality so HUGE filesize, -crf 51 is worst quality and extremely small filesize. -crf 30 is a nice trade-off between quality and filesize. Again, when encoding with nvidia -crf does not work, you need to use -cq 30 instead
-r is framerate. If you want to output 30 fps, just add -r 30 in the commandline (somewhere between the input file and output file).
ffmpeg -i "INPUTFILE" -c:v libx264 -c:a aac -b:a 128k -crf 30 -r 30 -pix_fmt yuv420p "OUTPUTFILE"
Agree with @ProWo says your file is already well compressed but also fully understand that there are usecases where one needs to squeeze the files even more and sacrifices quality.
After all, encoding with good quality to small filesize is a huge topic, you'd need to look into GOP settings and B-frames, 2-pass encoding and a lot more to get out most. Sorry i dont have an example for that because in all my h264 encodings usually only the processing speed matters and nothing else.
Maybe you better try using some tools with GUI and nice ready to use presets like handbrake or one of the ffmpeg-batch processors from the forum here.
So I reencoded at 30 FPS and it only saved me 80 Mb on the other way of doing it at 60 FPS. I guess I traveled the long way to figure out that the code I had to begin with was good. I also learned how to do a fast encode if I need to change formats really quick. Thanks!
Last edited by jagabo; 15th Oct 2021 at 17:25.