Media_extractor.play_media unable to play youtube at 4K

I’m trying to force the media_extractor to play a youtube video in 4k.

In the documentation, it says that the default_query is automatically set to ‘best’ which should give you the best video and audio, but it’s not streaming at 4k.

I was able to force it to 4k in the configuration by specifying the following, but it removes the audio:

configuration.yaml:

media_extractor:
  default_query: bestvideo[height=2160]

script:

service: media_extractor.play_media
data:
  media_content_id: >-
    https://www.youtube.com/watch?v=478TeAxm12g
  media_content_type: video/youtube
entity_id: media_player.studio_tv

The documentation for the youtube_dl that powers the media extractor says you should be able to combine bestvideo and best audio from the command line like this to get video and audio:

youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best'

In my case, I need to force the youtube-dl to use 4k and I don’t care what the audio format is as long as it streams, so I tried this in my configuration.yaml

media_extractor:
  default_query: bestvideo[height=2160]+bestaudio

I get the following error:

Error executing script. Unexpected error for call_service at pos 1: 'url'

Any help would be amazing

1 Like