5

I want to use a format selector that is something like -f bestvideo+best audio whose extension is compatible with the video extension so that they don't need to be muxed into an mkv (WARNING: Requested formats are incompatible for merge and will be merged into mkv.).

Note: I know about -f best and I don't want that. I want the best possible qualities of both audio and video while ensuring that they are compatible. How to do that?

  • 1
    Perhaps this question and answer would be helpful: askubuntu.com/q/806258/57576 – andrew.46 Aug 4 '16 at 5:01
  • @andrew.46 Thanks for trying to help, but the link wasn't much help. It describes the scenario when you're targeting a specific extension set. Whereas in my case, I am flexible with my extensions - I just want them to be compatible. For example, a webm video and an opus audio file, which result in a .webm file are perfectly okay for me. – The Peaceful Coder Aug 4 '16 at 5:09
12

You can download the best video and audio by using:

youtube-dl -f bestvideo+bestaudio "link to youtube video"

If that gives you an error, try the following instead:

youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio' --merge-output-format mp4 "link to youtube video"

Here you download the best video and audio seperately and then merge into a, in this case mp4 file. You can change the output format on the merged video as well.

Good luck!

  • Thanks! But I already know that. As I explained in my comment, I don't want to limit my selection format to a particular one. So, using -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio' may not download the best video if it is of the webm extension. Anyways, +1 for trying to help. – The Peaceful Coder Aug 4 '16 at 7:25
1

old question, but first answer on google, so:

with defining the following function, it worked for me (also possible to place it in ~/.bashrc):

youtube-dl_video_and_audio_best_no_mkv_merge () {
  video_type=$(youtube-dl -F "$@" | grep "video only" | awk '{print $2}' | tail -n 1)
  case $video_type in
    mp4)
      youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]' "$@";;
    webm)
      youtube-dl -f 'bestvideo[ext=webm]+bestaudio[ext=webm]' "$@";;
    *)
      echo "new best videoformat detected, please check it out! -> aborted";;
  esac
}

now you can download with

youtube-dl_video_and_audio_best_no_mkv_merge "https://www.youtube.com/watch?v=*******" "https://https://www.youtube.com/watch?v=********"

source: own creation

  • 2
    Note that the function name is not technically valid, specifically the dashes and plus sign. So you might have problems using the function, especially exporting it. I would recommend to make this into a script (since it doesn't need to be a function), and change the name to something like youtube-dl_video_and_audio_best_no_mkv_merge. – wjandrea Oct 17 '17 at 16:18
  • @wjandrea: Dashes in shell function names are valid (as they are for commands in general). I don't know about exported functions though. – David Foerster Oct 17 '17 at 21:04
  • @DavidFoerster Yes, Bash accepts invalid function names, but can't export them. If you try, you get an error, not a valid identifier – wjandrea Oct 17 '17 at 21:11

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.