21

I'm trying to download video from a m3u8 playlist using ffmpeg but I do not know how to choose the resolution to download. Currently the command is downloading the highest version

the command I am using is:

/home/user/bin/ffmpeg -user_agent "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:49.0) Gecko/20100101 Firefox/49.0" -i "https://sitevideo.com/list.m3u8" -c copy "/home/file/video.ts"

My list is this

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-STREAM-INF:BANDWIDTH=400000,NAME="low"
size1.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=800000,NAME="med"
size2.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=1900000,NAME="best"
size3.m3u8
Bruno Andrade
  • 565
  • 1
  • 3
  • 17

3 Answers3

22

You have to use the -map option.

ffmpeg ... -i "https://sitevideo.com/list.m3u8" -map p:1 -c copy "/home/file/video.ts"

p:1 refers to the 2nd program (variant playlist, in this case)..

Gyan
  • 85,394
  • 9
  • 169
  • 201
  • hi here is my command can you please tell me how can I chose resolution to download in android String cmd="-i " + url + " -acodec copy -bsf:a aac_adtstoasc " + "-vcodec copy "+ dir.getAbsolutePath()+"/test.mp4"; – Tara May 14 '18 at 12:51
  • @Gyan In the map option, is there a way I can specify the index such that it would chose always choose the 2nd last variant? For example suppose the playlist may have arbitrary number of variants (ex: 5 or 8) but I don't really know how many variants it has. However, I always want to map to the 2nd last variant. – Zythyr Jul 22 '20 at 04:12
  • Referring to my above question the reason I want to use the 2nd lasat variant is because each variant is increasing bitrate quality for the media but I always want to choose the 2nd best available instead of the best. – Zythyr Jul 22 '20 at 04:26
14

If you don't put the map command it will take the best quality by default.

Zibri
  • 9,096
  • 3
  • 52
  • 44
  • 2
    I am experiencing some situations where I believe this is not the case. Is there any documentation for this? Interested to know exactly what is "best". – Josh Stodola May 20 '19 at 12:28
  • best means that the speed changes depending on your network badwidth (probably when the player is too much behind and starts losing frames) – Zibri May 21 '19 at 09:56
  • 1
    @Zibri I think it selects the one with the highest resolution. See the stream selection section in the manual: It will select that stream based upon the following criteria: · for video, it is the stream with the highest resolution – Yağmur Oymak Jul 05 '19 at 12:10
  • 1
    @YağmurOymak nope. It starts with one (sometime even the lower one) then adapts to the best for the actual bandwidth. – Zibri Jul 07 '19 at 08:20
  • Zibri, not in ffmpeg. It's as @YagmurOymak says. – Gyan Mar 19 '20 at 17:17
  • 1
    See [Automatic stream selection](https://ffmpeg.org/ffmpeg.html#Automatic-stream-selection) – Yuval Apr 02 '20 at 14:10
3

Alternative variation of -map option:

ffmpeg -i <URL> -map m:variant_bitrate:800000 ...

That version selects the entry with BANDWIDTH=800000 from the list.m3u8 file. That's also visible at the beginning of ffmpeg output, e.g.:

Input #0, hls, from 'http...m3u8':
  ...
  Program 1
    Metadata:
      variant_bitrate : 800000

Documentation

blacktide
  • 10,654
  • 8
  • 33
  • 53
Martin
  • 31
  • 1