Tag Archives: youtube-dl

Download Bilibili 4K Videos. The Hard Way


  • Google Chrome installed
  • Get cookies.txt extension installed
  • youtube-dl installed
  • FFmpeg installed
  • Active bilibili membership (to get 4K streaming perk)
  • Basic JSON and Bash knowledge


  • Open the video page you want to download with Google Chrome
  • Open Web Inspector and refresh the page
  • Change video quality to some lower ones (like 480p) and change back to 4K
  • Search for player/playurl in Inspector
  • You should get a JSON payload returned:

Then select one of the most recent requests with accept_quality that has 120 in array:

Then select down to the data.dash.video[0].baseUrl and data.dash.audio[0].baseUrl. Remember these URLs:

Open Get cookies.txt extension and download your current cookies.

Download video and audio with youtube-dl:

youtube-dl --cookies bilibili.com_cookies.txt --referer 'https://www.bilibili.com/video/BV1d5411g7g2' 'https://xxx.mcdn.bilivideo.cn:4483/upgcxcode/12/67/336676712/336676712-1-30232.m4s...'

Then you will get two files like the following:

  • 20210510 336676712-1-30280 [336676712-1-30280].m4s
  • 20210510 336676712-1-30120 [336676712-1-30120].m4s

Rename the video extension to mp4 and audio to m4a. Play them to check if everything works.

Combine these two with FFmpeg:

ffmpeg -i 20210510\ 336676712-1-30120\ \[336676712-1-30120\].mp4 -i 20210510\ 336676712-1-30280\ \[336676712-1-30280\].m4a -c copy output-combined.mp4

Download 4k or 1080p Videos via youtube-dl

$ youtube-dl https://youtu.be/LB_X_GgNXMM -F


youtube: LB_X_GgNXMM: Downloading webpage
youtube: LB_X_GgNXMM: Downloading video info webpage
[info] Available formats for LB_X_GgNXMM:
format code  extension  resolution note
249          webm       audio only DASH audio   56k , opus @ 50k, 201.84KiB
250          webm       audio only DASH audio   71k , opus @ 70k, 267.21KiB
140          m4a        audio only DASH audio  127k , m4a_dash container, mp4a.40.2@128k, 547.96KiB
171          webm       audio only DASH audio  131k , vorbis@128k, 547.52KiB
251          webm       audio only DASH audio  135k , opus @160k, 534.35KiB
160          mp4        256x144    144p   69k , avc1.4d400c, 24fps, video only, 221.40KiB
278          webm       256x144    144p   95k , webm container, vp9, 24fps, video only, 387.03KiB
242          webm       426x240    240p  186k , vp9, 24fps, video only, 623.64KiB
133          mp4        426x240    240p  213k , avc1.4d4015, 24fps, video only, 618.98KiB
243          webm       640x360    360p  416k , vp9, 24fps, video only, 1.29MiB
134          mp4        640x360    360p  440k , avc1.4d401e, 24fps, video only, 1.26MiB
135          mp4        854x480    480p  714k , avc1.4d401e, 24fps, video only, 2.08MiB
244          webm       854x480    480p  724k , vp9, 24fps, video only, 2.22MiB
136          mp4        1280x720   720p 1001k , avc1.4d401f, 24fps, video only, 3.06MiB
247          webm       1280x720   720p 1122k , vp9, 24fps, video only, 3.39MiB
137          mp4        1920x1080  1080p 1679k , avc1.640028, 24fps, video only, 4.86MiB
248          webm       1920x1080  1080p 1998k , vp9, 24fps, video only, 5.13MiB
17           3gp        176x144    small , mp4v.20.3, mp4a.40.2@ 24k, 348.19KiB
36           3gp        320x180    small , mp4v.20.3, mp4a.40.2, 962.59KiB
18           mp4        640x360    medium , avc1.42001E, mp4a.40.2@ 96k, 2.11MiB
43           webm       640x360    medium , vp8.0, vorbis@128k, 3.46MiB
22           mp4        1280x720   hd720 , avc1.64001F, mp4a.40.2@192k (best)
$ youtube-dl https://youtu.be/LB_X_GgNXMM -f 137+140