VideoHelp Forum

+ Reply to Thread
Results 1 to 12 of 12
Thread
  1. Member
    Join Date
    Oct 2021
    Location
    'Merica
    Search Comp PM
    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"

    Thank You.
    Quote Quote  
  2. Member
    Join Date
    Feb 2006
    Location
    United States
    Search Comp PM
    Originally Posted by Bitrageous View Post
    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"

    Thank You.
    are you on Linux or windows ??
    see this setup guide - https://docs.nvidia.com/video-technologies/video-codec-sdk/ffmpeg-with-nvidia-gpu/
    Quote Quote  
  3. Member
    Join Date
    Oct 2021
    Location
    'Merica
    Search Comp PM
    Windows 10
    Quote Quote  
  4. Member
    Join Date
    Oct 2021
    Location
    'Merica
    Search Comp PM
    Originally Posted by october262 View Post
    Originally Posted by Bitrageous View Post
    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"

    Thank You.
    are you on Linux or windows ??
    see this setup guide - https://docs.nvidia.com/video-technologies/video-codec-sdk/ffmpeg-with-nvidia-gpu/
    So I installed mysys2 and now I am stuck on the instruction to 'git clone 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.
    Quote Quote  
  5. If you are on Win you need a precompiled version of ffmpeg from here
    https://www.gyan.dev/ffmpeg/builds/

    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.
    https://trac.ffmpeg.org/wiki/HWAccelIntro
    Last edited by codehound; 14th Oct 2021 at 04:19.
    Quote Quote  
  6. 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.

    Originally Posted by Bitrageous View Post
    Why is FFMPEG not utilizing my graphics hardware, a GTX 1060?
    That is because you are instructing it to encode with a CPU based codec, libx264.

    Originally Posted by Bitrageous View Post
    why are output videos at 60 frames per second?
    Because you are not instructing it to output a specific framerate, so it will copy the framerate of the input file. Parameter for forcing a framerate is -r

    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.
    Quote Quote  
  7. Member
    Join Date
    Oct 2021
    Location
    'Merica
    Search Comp PM
    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.
    Quote Quote  
  8. Member
    Join Date
    Oct 2021
    Location
    'Merica
    Search Comp PM
    Here is the information from one of the videos in that program.
    Image Attached Thumbnails Click image for larger version

Name:	bitrate info.jpg
Views:	13
Size:	38.5 KB
ID:	61286  

    Quote Quote  
  9. For a 4h 6 min video with 1280x720 resolution the size is ok. There is nothing to change.
    Quote Quote  
  10. Originally Posted by Bitrageous View Post

    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.
    https://slhck.info/video/2017/02/24/crf-guide.html

    -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).

    Example:
    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.
    Quote Quote  
  11. Member
    Join Date
    Oct 2021
    Location
    'Merica
    Search Comp PM
    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!
    Quote Quote  
  12. Originally Posted by Bitrageous View Post
    So I reencoded at 30 FPS and it only saved me 80 Mb on the other way of doing it at 60 FPS.
    With libx264? That's no surprise then. x264 is frame rate aware. It knows that the changes from frame to frame are smaller and less visible at 60 fps than at 30 fps so it uses fewer bits per frame. And if your source was really 30 fps with duplicate frames to make 60 fps -- then those duplicate frames require very little bitrate (the codec just says "repeat the last frame again" for each.

    Originally Posted by Bitrageous View Post
    I guess I traveled the long way to figure out that the code I had to begin with was good.
    There was nothing special about those settings. About the only difference from the default was -crf 30 instead of -crf 23.
    Last edited by jagabo; 15th Oct 2021 at 17:25.
    Quote Quote