How to force command line VLC to stream youtube videos of specific quality?

I want to stream youtube videos from command line using VLC media player. I was able to stream youtube videos using this command

cvlc https://www.youtube.com/watch?v=m2Oo4kBHBNU

The problem is that when ever VLC streams videos it uses highest quality video format available (480 and higher). I dont have a uniform interned download speed, some times I can play youtube video of 360 (my highest quality) and other times I can play a youtube video of 240 only.

Because VLC currently streams with highest quality (480 and above according to video) I cant stream using cvlc https://www.youtube.com/watch?v=m2Oo4kBHBNU this command. How should I force commandline VLC to play video of specific quality?


Solution 1:

You can set the required input video settings in VLC for your YouTube clip in either of two ways:

  1. Locally using the command line
  2. Globally using the GUI

Details of both options below:

  1. Altering input video locally using the command-line:

    You can request a specific video size from youtube from the commandline by using the --preferred-resolution option. This has the bonus of not changing vlc global settings, so settings specified in this manner are not saved. Settings for this are (seen in cvlc -h):

    1. -1 (The default, this selects best available video quality)
    2. 1080 (This selects Full HD: 1080p)
    3. 720 (This selects HD: 720p)
    4. 576 (This selects Standard Definition: 576 or 480 lines)
    5. 360 (This selects Low Definition: 360 lines)
    6. 240 (This selects Very Low Definition: 240 lines)

    So for your clip the following works nicely:

    cvlc --preferred-resolution 240 https://www.youtube.com/watch?v=m2Oo4kBHBNU 
    
  2. Altering input video globally using the GUI:

    You can also alter the input video settings globally from the GUI preferences as shown in the screenshot below:

    screenshot

    These settings are saved for subsequent vlc usage and will be saved in your vlc configuration file: ~/.config/vlc/vlcrc. As an example: this is added for a preferred resolution of 240:

    # Preferred video resolution (integer)
    preferred-resolution=240
    

You have to love vlc :)