使用 FFMPEG 下载 HLS 视频时,它不会下载音频

Posted

技术标签:

【中文标题】使用 FFMPEG 下载 HLS 视频时,它不会下载音频【英文标题】:When downloading HLS video with FFMPEG it does not download the audio 【发布时间】:2021-08-03 00:10:24 【问题描述】:

我有一个问题,当我尝试使用 FFMPEG 下载 HLS 视频时,它会下载视频轨道,但找不到 AUDIO。在播放器中运行 HLS .m3u8 文件时,正常播放,音频和视频,但尝试下载时,显示错误消息,提示找不到音频。

我正在运行以下命令:

ffmpeg.exe -i "https://teste-etv.espiritismo.tv/437602.m3u8" -codec:a libmp3lame -b:a 96k teste-hls.mp3

尝试下载音频时显示以下错误:

[hls @ 0000021b5d9ad940] Skip ('#EXT-X-VERSION:3')
[hls @ 0000021b5d9ad940] Skip ('#EXT-X-INDEPENDENT-SEGMENTS')
[hls @ 0000021b5d9ad940] Opening 'https://appsetv.b-cdn.net/hls/437602/437602-1080p.m3u8' for reading
[hls @ 0000021b5d9ad940] Skip ('#EXT-X-VERSION:3')
[https @ 0000021b5e10ee00] Opening 'https://appsetv.b-cdn.net/hls/437602/437602-720p.m3u8' for reading
[hls @ 0000021b5d9ad940] Skip ('#EXT-X-VERSION:3')
[https @ 0000021b5e10ee00] Opening 'https://appsetv.b-cdn.net/hls/437602/437602-540p.m3u8' for reading
[hls @ 0000021b5d9ad940] Skip ('#EXT-X-VERSION:3')
[https @ 0000021b5e10ee00] Opening 'https://appsetv.b-cdn.net/hls/437602/437602-360p.m3u8' for reading
[hls @ 0000021b5d9ad940] Skip ('#EXT-X-VERSION:3')
[hls @ 0000021b5d9ad940] Opening 'https://appsetv.b-cdn.net/hls/437602/437602-1080p_00001.ts' for reading
[hls @ 0000021b5d9ad940] Opening 'https://appsetv.b-cdn.net/hls/437602/437602-1080p_00002.ts' for reading
[hls @ 0000021b5d9ad940] Opening 'https://appsetv.b-cdn.net/hls/437602/437602-720p_00001.ts' for reading
[hls @ 0000021b5d9ad940] Opening 'https://appsetv.b-cdn.net/hls/437602/437602-720p_00002.ts' for reading
[hls @ 0000021b5d9ad940] Opening 'https://appsetv.b-cdn.net/hls/437602/437602-540p_00001.ts' for reading
[hls @ 0000021b5d9ad940] Opening 'https://appsetv.b-cdn.net/hls/437602/437602-540p_00002.ts' for reading
[hls @ 0000021b5d9ad940] Opening 'https://appsetv.b-cdn.net/hls/437602/437602-360p_00001.ts' for reading
[hls @ 0000021b5d9ad940] Opening 'https://appsetv.b-cdn.net/hls/437602/437602-360p_00002.ts' for reading
[hls @ 0000021b5d9ad940] Could not find codec parameters for stream 1 (Audio: aac ([15][0][0][0] / 0x000F), 0 channels, fltp): unspecified sample rate
Consider increasing the value for the 'analyzeduration' and 'probesize' options
[hls @ 0000021b5d9ad940] Could not find codec parameters for stream 3 (Audio: aac ([15][0][0][0] / 0x000F), 0 channels, fltp): unspecified sample rate
Consider increasing the value for the 'analyzeduration' and 'probesize' options
[hls @ 0000021b5d9ad940] Could not find codec parameters for stream 5 (Audio: aac ([15][0][0][0] / 0x000F), 0 channels, fltp): unspecified sample rate
Consider increasing the value for the 'analyzeduration' and 'probesize' options
[hls @ 0000021b5d9ad940] Could not find codec parameters for stream 7 (Audio: aac ([15][0][0][0] / 0x000F), 0 channels, fltp): unspecified sample rate
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, hls, from 'https://appsetv.b-cdn.net/hls/437602/437602.m3u8':
  Duration: 00:01:41.00, start: 2.083333, bitrate: 0 kb/s
  Program 0
    Metadata:
      variant_bitrate : 2509173
    Stream #0:0: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 24 fps, 24 tbr, 90k tbn, 48 tbc
    Metadata:
      variant_bitrate : 2509173
    Stream #0:1: Audio: aac ([15][0][0][0] / 0x000F), 0 channels, fltp
    Metadata:
      variant_bitrate : 2509173
  Program 1
    Metadata:
      variant_bitrate : 1205957
    Stream #0:2: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 24 fps, 24 tbr, 90k tbn, 48 tbc
    Metadata:
      variant_bitrate : 1205957
    Stream #0:3: Audio: aac ([15][0][0][0] / 0x000F), 0 channels, fltp
    Metadata:
      variant_bitrate : 1205957
  Program 2
    Metadata:
      variant_bitrate : 1165600
    Stream #0:4: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p, 960x540 [SAR 1:1 DAR 16:9], 24 fps, 24 tbr, 90k tbn, 48 tbc
    Metadata:
      variant_bitrate : 1165600
    Stream #0:5: Audio: aac ([15][0][0][0] / 0x000F), 0 channels, fltp
    Metadata:
      variant_bitrate : 1165600
  Program 3
    Metadata:
      variant_bitrate : 656245
    Stream #0:6: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p, 640x360 [SAR 1:1 DAR 16:9], 24 fps, 24 tbr, 90k tbn, 48 tbc
    Metadata:
      variant_bitrate : 656245
    Stream #0:7: Audio: aac ([15][0][0][0] / 0x000F), 0 channels, fltp
    Metadata:
      variant_bitrate : 656245
Output #0, mp3, to 'teste-hls.mp3':
Output file #0 does not contain any stream

【问题讨论】:

【参考方案1】:

问题可以通过两种方式解决:

添加-map来映射音轨或添加参数-analyzeduration 5G(该命令增加了检查文件中ffmpeg的时间。)

例子:

-地图 0:1

ffmpeg -i https://teste-etv.espiritismo.tv/437602-1080p.m3u8 -map 0:1 -codec:a libmp3lame -b:a 96k teste-hls.mp3

-analyzeduration 5G

ffmpeg.exe -analyzeduration 5G -i https://teste-etv.espiritismo.tv/437602.m3u8 -codec:a libmp3lame -b:a 96k teste-hls-3.mp3

** 解决方案是通过邮件列表上的 ffmpeg 用户论坛的贡献找到的。

【讨论】:

以上是关于使用 FFMPEG 下载 HLS 视频时,它不会下载音频的主要内容,如果未能解决你的问题,请参考以下文章

FFmpeg基于HLS实现大视频分片下载播放[视频直播二]

hls流媒体视频防盗实现

使用FFmpeg进行HLS打包——FFmpeg简单学

将视频转换为 HLS(HTTP Live Streaming) 协议格式文件

Linux下使用FFmpeg将RTMP流转换为HLS

使用 ffmpeg 将 Mp4 转换为 HLS