流媒体播放
本节介绍 mpv 的流媒体播放功能和协议支持。
支持的协议
mpv 支持多种流媒体协议:
HTTP/HTTPS
bash
# HTTP 流
mpv http://example.com/video.mp4
# HTTPS 流
mpv https://example.com/video.mp4RTSP/RTMP
bash
# RTSP 流
mpv rtsp://example.com/stream
# RTMP 流
mpv rtmp://example.com/live/streamHLS (HTTP Live Streaming)
bash
# HLS 流
mpv https://example.com/stream.m3u8
# 带选项的 HLS
mpv --hls-segment-threads=4 https://example.com/stream.m3u8DASH (Dynamic Adaptive Streaming over HTTP)
bash
# DASH 流
mpv https://example.com/manifest.mpdYouTube
bash
# YouTube 视频
mpv https://www.youtube.com/watch?v=VIDEO_ID
# YouTube 播放列表
mpv https://www.youtube.com/playlist?list=PLAYLIST_ID
# YouTube 直播
mpv https://www.youtube.com/watch?v=LIVE_VIDEO_ID其他平台
bash
# Bilibili
mpv https://www.bilibili.com/video/BV1xx411c7mD
# Twitch
mpv https://www.twitch.tv/username
# Vimeo
mpv https://vimeo.com/123456789流媒体配置
网络缓冲
bash
# 缓冲大小(字节)
demuxer-max-bytes=500MiB
# 缓冲时长(秒)
demuxer-max-back-buffer=500MiB
# 预读取
cache=yes连接设置
bash
# 连接超时(秒)
network-timeout=60
# 重试次数
stream-lavf-o=timeout=60
# 用户代理
user-agent="Mozilla/5.0"代理设置
bash
# HTTP 代理
http-proxy=http://proxy:8080
# SOCKS 代理
socks-proxy=socks5://proxy:1080YouTube 支持
YouTube 选项
bash
# 选择视频质量
ytdl-format=bestvideo+bestaudio
# 选择特定质量
ytdl-format=bestvideo[height<=720]+bestaudio
# 禁用 YouTube-DL
ytdl=noYouTube-DL 配置
bash
# 使用 youtube-dl
script-opts=ytdl_hook-ytdl_path=youtube-dl
# 使用 yt-dlp
script-opts=ytdl_hook-ytdl_path=yt-dlp
# 自定义选项
ytdl-raw-options=cookies-from-browser=chromeYouTube 质量选择
bash
# 最佳质量
ytdl-format=best
# 最佳视频 + 最佳音频
ytdl-format=bestvideo+bestaudio
# 720p 视频
ytdl-format=bestvideo[height<=720]+bestaudio
# 1080p 视频
ytdl-format=bestvideo[height<=1080]+bestaudio直播流
直播配置
bash
# 直播缓冲
cache=yes
demuxer-max-bytes=500MiB
# 直播延迟
network-timeout=60
# 直播同步
video-sync=audio直播平台
bash
# Twitch
mpv https://www.twitch.tv/username
# YouTube 直播
mpv https://www.youtube.com/watch?v=LIVE_VIDEO_ID
# Bilibili 直播
mpv https://live.bilibili.com/ROOM_ID流媒体缓存
缓存配置
bash
# 启用缓存
cache=yes
# 缓存大小
demuxer-max-bytes=150MiB
# 缓存目录
cache-dir=~/.cache/mpv
# 缓存文件
cache-file=TMP缓存策略
bash
# 预读取
demuxer-readahead-secs=20
# 缓存清理
cache-unlink-files=immediate流媒体协议选项
HTTP 选项
bash
# HTTP 超时
network-timeout=60
# HTTP 头
http-header-fields="Referer: https://example.com"
# HTTP Cookies
cookies=yes
cookies-file=~/.config/mpv/cookies.txtRTSP 选项
bash
# RTSP 传输
rtsp-transport=tcp
rtsp-transport=udp
# RTSP 端口
rtsp-port=554HLS 选项
bash
# HLS 线程数
hls-segment-threads=4
# HLS 优先级
hls-bitrate=max流媒体故障排除
常见问题
缓冲区溢出
bash# 增加缓冲区大小 demuxer-max-bytes=500MiB连接超时
bash# 增加超时时间 network-timeout=120视频卡顿
bash# 降低质量 ytdl-format=bestvideo[height<=720]+bestaudio
调试信息
bash
# 显示网络信息
mpv --msg-level=all=v https://example.com/video.mp4
# 显示缓冲信息
mpv --stats https://example.com/video.mp4