0

I am trying to record short video of my desktop and upload it to youtube. The problem is that every time when I upload it to youtube or even dropbox (as video), the quality is much worse.

My ffmpeg execution:

ffmpeg -f x11grab -s 1366x768 -r 30 -i :0.0 -codec:v libx264 -crf 10 -bf 20 -flags +cgop -pix_fmt yuv440p -movflags faststart help.mp4

based on:

ffmpeg -i <input file> -codec:v libx264 -crf 21 -bf 2 -flags +cgop -pix_fmt yuv420p -codec:a aac -strict -2 -b:a 384k -r:a 48000 -movflags faststart <output_name>.mp4

which I found here

Original file (.zip): https://www.dropbox.com/s/xlkr83rkqfxon23/help.mp4.zip?dl=0

File after upload to youtube: https://www.youtube.com/watch?v=ewEUgpXOpmg

As you can see, I loss quality after upload to youtube.

Could you help me?
How should I choose the appropriate parameters to record and upload high quality video?

migrated from stackoverflow.com Apr 2 '18 at 1:59

This question came from our site for professional and enthusiast programmers.

  • Your video has way more than enough bits for high quality video, but YouTube will re-encode whatever you give it. There is nothing you can do. – llogan Mar 22 '18 at 17:47
0

Try taking your recorded video and upscaling it.

I've heard that when YT's encoding system sees a supermegahighresolution video it treats it differently and works harder to make the lower resolution versions higher quality than 1080p/etc input. I've never explored this myself, YMMV, but it's worth a shot.

The only issue is that upscaling is a necessarily lossy process; perfect-pixel scaling looks terrible (see below). Unless YT's encoding system is amazing, I fully expect smoothing will be needed for the video to still look good when the (reencoded, scaled-back-down) 1080p/720p versions are watched.

So it's about striking a balance between the upscale>downscale process introducing the least possible amount of blur/lossiness. This is generally a trial-and-error problem that will require real-world input (specific to what you'll be showing on screen; for example, a majority of text).

(Also, I have no idea if you can remove/hide/etc certain video resolutions when uploading video to YT, but you'd almost certainly be hiding the 2K/4K uploaded version in this case.)

I fiddled with ffmpeg for a bit; the two bits of info that proved most useful were the scaling howto page and the scaler documentation.

Here's what I came up with:

ffmpeg -i help.mp4 -c:v libx264 -preset ultrafast -vf scale=iw*4:-1:flags=neighbor+bitexact+accurate_rnd+full_chroma_int+full_chroma_inp+print_info -y help4x.mp4

  • -c:v libx264 -preset ultrafast makes the encode go faster but use lots of disk (in this case 6.6MB out vs 1.7MB in). Upscaling seemed to need 1GB+ of RAM and all of my CPU regardless of encoding settings, so if you have more bandwidth than time, you may prefer the speedup. The H264 encoder has other speed/performance settings, see https://trac.ffmpeg.org/wiki/Encode/H.264

  • -vf scale=iw*4:-1 upscales the video 4x >:D - iw = input width, *4 (multiply by 4) is self-explanatory, -1 = "figure out width from height and keep aspect ratio."

  • flags=:

    • I've selected neighbor here to show you which is the one that doesn't do any blurring/smoothing, ie perfect pixel doubling/tripling/etc... and to let you know that it actually looks surprisingly bad scaled back down (I wasn't expecting that). experimental looked good, unsure if it was better than the default bicubic. I strongly recommend leafing through https://ffmpeg.org/ffmpeg-scaler.html, putting together a short test video that showcases what you actually want to record, and trying all of the encoders (possibly even uploading all the test videos). Whatever work you do here, I'm curious what results you get!

    • I found accurate_rnd+full_chroma_int+full_chroma_inp+print_info over at https://superuser.com/questions/782133/ffmpeg-upscaling-video and tossed them in. I have no idea what they do/if they help. :D

    • bitexact sounds nice. I have no idea what this also does.

    • print_info shows you which scaler you're using just under "Press [q] to stop".

-y enables overwriting. Otherwise ffmpeg nags you with a "overwrite (y/n)" every time.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.