Posted: . At: 9:42 AM. This was 2 years ago. Post ID: 15717
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


How to get the best quality when creating a webm with FFmpeg.


Rip a Youtube video to a good quality Webm with FFmpeg

This very useful command will get a Youtube video and rip a certain timeframe from the video to a good quality WebM file. Create a Webm with FFmpeg.

┌──[jason@11000000.10101000.00000001.00000011][~/Videos]
└──╼  ╼ $ ffmpeg -ss 00:00:55 -to 00:01:05 -i `yt-dlp -g -f bestvideo GbPK2VCarvU` -threads 0 -vf scale=960:720 -g 999 -c:v libvpx -b:v 2M -crf 45 -qmin 35 -qmax 63 -y -an -sn videoclip.webm

This requires yt-dlp, this is a fork() of Youtube DL, download it from the Github link below.

https://github.com/yt-dlp/yt-dlp. Put the binary in /usr/local/bin and use chmod to 755. This will work fine.

The “-threads 0” parameter disables multithreaded video encoding, which can help compression at the cost of speed, due to not splitting frames into independently processed sections (worse intraframe compression).

The “-vf scale=1440×1080”, parameter trims some pixels off while still looking basically like 1080p. Adjust this depending upon the video aspect ratio and resolution.

“-g 999”, sets the GOP length limit to 999 frames, higher values means still sections will be compressed better, and this also reduces that “pulsing” you typically see in low-quality images every second or two, the downside is less efficient seeking when playing the video back (obviously not an issue here).

“-b:v 2M -crf 45 -qmin 35 -qmax 63” quality settings, bitrate set higher than I want it to ever hit, basically this is the upper bound, FFmpeg sets this very low by default so this is important when crf encoding with libvpx, crf is the average quality level, qmin the lower bound and qmax the upper bound, higher value is lower quality, 63 is the maximum, tweak until you find a quality or filesize you like, 45 is very low quality. I usually do more like 35 for “ok” quality, or 25 for “good” quality (relative to what you can expect here).

This version of the script gives even better quality, tweaking the -qmax parameter is the key to getting much better quality when encoding.

┌──(john㉿DESKTOP-PF01IEE)-[/mnt/c/Users/Intel i5/Videos]
└─$ ffmpeg -ss 00:05:55 -to 00:06:05 -i `yt-dlp -g -f bestvideo mXZCKLD-DeA` -threads 0 -vf scale=960:720 -g 999 -c:v libvpx -b:v 2M -crf 45 -qmin 35 -qmax 45 -y -an -sn videoclip.webm

To add noise to a video, you may use this simple tip to make random blocky noise.

┌──(john㉿DESKTOP-PF01IEE)-[/mnt/c/Users/Intel i5/Videos]
└─$ ffmpeg -i 640x360_MP4_851662782531587016.mp4 -bsf:v noise -c:v mpeg2video -q:v 2 -c:a copy macroblock.ts

The above process creates a damaged file, but it may then be repaired easily using this process below. This is very interesting and useful.

┌──(john㉿DESKTOP-PF01IEE)-[/mnt/c/Users/Intel i5/Videos]
└─$ ffmpeg -i macroblock.ts -codec:v libx264 -pix_fmt yuv420p output.mp4

These tips should be very useful when you wish to rip a video clip from a Youtube video. This is amazing. Youtube-dl still works on modern Youtube in 2022 and this is very useful. Even if you use this in Windows Services for Linux it still operates as it should, all you need to ensure is that you have Python3 installed for the script to operate, then you are fine.

How to rip the audio from a Youtube video using Youtube-dl. This works as advertised and is most useful for saving music or Podcasts.

A much better way to save audio from Youtube with youtube-dl.
https://securitronlinux.com/debian-testing/a-much-better-way-to-save-audio-from-youtube-with-youtube-dl/.

This is an example of this one-liner. This is to save a copy of a Youtube video as an MP3 file.

┌──(john㉿DESKTOP-PF01IEE)-[/mnt/c/Users/Intel i5/Videos]
└─$ yt-dlp -f 140 https://www.youtube.com/watch?v=_35FCj8PEoA --embed-thumbnail --extract-audio --audio-format mp3
[youtube] _35FCj8PEoA: Downloading webpage
[youtube] _35FCj8PEoA: Downloading android player API JSON
[info] _35FCj8PEoA: Downloading 1 format(s): 140
[info] Downloading video thumbnail 41 ...
[info] Writing video thumbnail 41 to: Dark Ambient Lo-Fi Music _ 1 Hour [_35FCj8PEoA].webp
[download] Destination: Dark Ambient Lo-Fi Music _ 1 Hour [_35FCj8PEoA].m4a
[download] 100% of 55.62MiB in 00:24
[FixupM4a] Correcting container of "Dark Ambient Lo-Fi Music _ 1 Hour [_35FCj8PEoA].m4a"
[ExtractAudio] Destination: Dark Ambient Lo-Fi Music _ 1 Hour [_35FCj8PEoA].mp3
Deleting original file Dark Ambient Lo-Fi Music _ 1 Hour [_35FCj8PEoA].m4a (pass -k to keep)
[ThumbnailsConvertor] Converting thumbnail "Dark Ambient Lo-Fi Music _ 1 Hour [_35FCj8PEoA].webp" to png
[EmbedThumbnail] ffmpeg: Adding thumbnail to "Dark Ambient Lo-Fi Music _ 1 Hour [_35FCj8PEoA].mp3"
Deleting original file Dark Ambient Lo-Fi Music _ 1 Hour [_35FCj8PEoA].png (pass -k to keep)
Deleting original file Dark Ambient Lo-Fi Music _ 1 Hour [_35FCj8PEoA].webp (pass -k to keep)

The file is automatically named and also contains the thumbnail, so this is therefore the best way to rip music from Youtube.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.