mpv-player / mpv

🎥 Command line video player
https://mpv.io
Other
26.84k stars 2.85k forks source link

Streaming video #12490

Open Kectai opened 9 months ago

Kectai commented 9 months ago

Important Information

Provide following Information:

If you're not using git master or the latest release, update. Releases are listed here: https://github.com/mpv-player/mpv/releases

Reproduction steps

Try to reproduce your issue with --no-config first. If it isn't reproducible with --no-config try to first find out which option or script causes your issue.

Describe the reproduction steps as precise as possible. It's very likely that the bug you experience wasn't reproduced by the developer because the workflow differs from your own.

Expected behavior

mpegts should be detected

Actual behavior

matroska,webm I'm not sure if this is a problem caused by mpv or ffmpeg.

Log file

Make a log file made with -v -v or --log-file=output.txt. If you use the Bundle from a version later than 0.32 a default log is created for your last run at ~/Library/Logs/mpv.log. You can jump to that file via the Help > Show log File… menu. Paste the log to https://0x0.st/ or attach it to the github issue, and replace this text with a link to it.

In the case of a crash please provide the macOS Crash Report (Backtrace).

The issue will be closed for ignoring the issue template.

(I replaced the URL with a blank string)

[cplayer] Command line options: '' '-v'
[cplayer] mpv 0.36.0 Copyright © 2000-2023 mpv/MPlayer/mplayer2 projects
[cplayer]  built on Sun Jul 23 05:10:36 2023
[cplayer] FFmpeg version: 6.0
[cplayer] FFmpeg library versions:
[cplayer]    libavutil       58.2.100
[cplayer]    libavcodec      60.3.100
[cplayer]    libavformat     60.3.100
[cplayer]    libswscale      7.1.100
[cplayer]    libavfilter     9.3.100
[cplayer]    libswresample   4.10.100
[cplayer]
[cplayer] Configuration: -Dhtml-build=enabled -Djavascript=enabled -Dlibmpv=true -Dlua=luajit -Dlibarchive=enabled -Duchardet=enabled -Dprefix=/opt/homebrew/Cellar/mpv/0.36.0 -Ddatadir=/opt/homebrew/Cellar/mpv/0.36.0/share/mpv -Dlibdir=/opt/homebrew/Cellar/mpv/0.36.0/lib -Dmandir=/opt/homebrew/Cellar/mpv/0.36.0/share/man -Dsysconfdir=/opt/homebrew/etc/mpv -Dbuildtype=release -Dwrap_mode=nofallback
[cplayer] List of enabled features: av-channel-layout avif_muxer bsd-fstatfs build-date cocoa coreaudio cplugins darwin ffmpeg gl gl-cocoa glob glob-posix gpl html-build iconv javascript jpeg jpegxl lcms2 libarchive libass libavdevice libbluray libdl libm luajit macos-cocoa-cb macos-media-player macos-touchbar manpage-build osx-thread-name posix posix_shm rubberband rubberband-3 stdatomic threads uchardet vapoursynth vector videotoolbox-gl zimg zimg-st428 zlib
[cplayer] Reading config file /opt/homebrew/etc/mpv/mpv/encoding-profiles.conf
[bdmv/bluray] Opening /opt/homebrew/etc/mpv/mpv/encoding-profiles.conf
[file] Opening /opt/homebrew/etc/mpv/mpv/encoding-profiles.conf
[cplayer] Applying profile 'default'...
[cplayer] Setting option 'v' = '' (flags = 8)
[osx/cocoacb] Created CGL pixel format with attributes: kCGLPFAOpenGLProfile, kCGLOGLPVersion_3_2_Core, kCGLPFAAccelerated, kCGLPFADoubleBuffer, kCGLPFAColorSize, 64, kCGLPFAColorFloat, kCGLPFABackingStore, kCGLPFAAllowOfflineRenderers, kCGLPFASupportsAutomaticGraphicsSwitching, 0
[libmpv_render] GL_VERSION='4.1 Metal - 83.1'
[libmpv_render] Detected desktop OpenGL 4.1.
[libmpv_render] GL_VENDOR='Apple'
[libmpv_render] GL_RENDERER='Apple M1 Pro'
[libmpv_render] GL_SHADING_LANGUAGE_VERSION='4.10'
[libmpv_render] Loaded extension GL_APPLE_rgb_422.
[libmpv_render] GL_*_swap_control extension missing.
[libmpv_render] Testing FBO format rgba16f
[libmpv_render] Using FBO format rgba16f.
[libmpv_render] Disabling HDR peak computation (one or more of the following is not supported: compute shaders=0, SSBO=0).
[libmpv_render] No advanced processing required. Enabling dumb mode.
[libmpv_render] Loading hwdec driver 'videotoolbox'
[cplayer] Waiting for scripts...
[osd/libass] libass API version: 0x1701000
[osd/libass] libass source: tarball: 0.17.1
[osd/libass] Shaper: FriBidi 1.0.12 (SIMPLE) HarfBuzz-ng 8.2.1 (COMPLEX)
[osd/libass] Setting up fonts...
[osd/libass] Using font provider coretext
[osd/libass] Done.
[cplayer] Set property: shared-script-properties -> 1
[cplayer] Set property: user-data/osc/visibility="auto" -> 1
[cplayer] Set property: shared-script-properties -> 1
[cplayer] Set property: user-data/osc/margins={"t":0,"b":0,"l":0,"r":0} -> 1
[cplayer] Done loading scripts.
[cplayer] Running hook: ytdl_hook/on_load
[ytdl_hook] ytdl:// hook
[ytdl_hook] not a ytdl:// url
[cplayer] Set property: shared-script-properties -> 1
[ffmpeg] Opening
[cplayer] Set property: user-data/osc/margins={"t":0,"b":0,"l":0,"r":0} -> 1
[cplayer] Set property: shared-script-properties -> 1
[cplayer] Set property: user-data/osc/margins={"t":0,"b":0,"l":0,"r":0} -> 1
[osd/libass] libass API version: 0x1701000
[osd/libass] libass source: tarball: 0.17.1
[osd/libass] Shaper: FriBidi 1.0.12 (SIMPLE) HarfBuzz-ng 8.2.1 (COMPLEX)
[osd/libass] Setting up fonts...
[osd/libass] Using font provider coretext
[osd/libass] Done.
[ffmpeg] Mime-type: 'video/x-matroska'
[demux] Trying demuxers for level=normal.
[lavf] Found 'matroska,webm' at score=75 size=2048.
[ffmpeg] stream level seek from 3395 to 542533
[ffmpeg/demuxer] matroska,webm: EBML header parsing failed
[lavf] avformat_open_input() failed
[ffmpeg] stream level seek from 545961 to 0
[demux] Trying demuxers for level=unsafe.
[lavf] Found 'matroska,webm' at score=75 size=2048.
[ffmpeg] stream level seek from 208195 to 542533
[ffmpeg/demuxer] matroska,webm: EBML header parsing failed
[lavf] avformat_open_input() failed
[ffmpeg] stream level seek from 544067 to 0
[cplayer] Opening failed or was aborted:
[cplayer] Running hook: ytdl_hook/on_load_fail
[ytdl_hook] full hook
[ytdl_hook] No youtube-dl found with path yt-dlp in config directories
[ytdl_hook] Found youtube-dl with path yt-dlp in PATH
[ytdl_hook] youtube-dl succeeded!
[ytdl_hook] Got direct URL
[cplayer] finished playback, unrecognized file format (reason 4)
[cplayer] Failed to recognize file format.
[cplayer]
[cplayer] Exiting... (Errors when loading file)
[cplayer] Set property: shared-script-properties -> 1

Sample files

Sample files needed to reproduce this issue can be uploaded to https://0x0.st/ or similar sites. (Only needed if the issue cannot be reproduced without it.) Do not use garbage like "cloud storage", especially not Google Drive.

This url is not a public url, I'm sorry that I can't provide it. The actual file size is also larger.

[FORMAT]
filename=/Users/chace/Downloads/00000.m2ts
nb_streams=6
nb_programs=1
format_name=mpegts
format_long_name=MPEG-TS (MPEG-2 Transport Stream)
start_time=4199.000000
duration=7285.280000
size=33567713280
bit_rate=36860862
probe_score=50
[/FORMAT]
Traneptora commented 9 months ago

This would be an issue with FFmpeg, because it is responsible for probing the input format. It appears it's only probing an mpegts file with a score of 50 and matroska with 75. Can you upload a sample? The first megabyte of the file should work fine for this purpose.

llyyr commented 9 months ago

can you try --demuxer-lavf-format=mpegts?

Kectai commented 9 months ago

can you try --demuxer-lavf-format=mpegts?

Adding this parameter is effective

Kectai commented 9 months ago

This would be an issue with FFmpeg, because it is responsible for probing the input format. It appears it's only probing an mpegts file with a score of 50 and matroska with 75. Can you upload a sample? The first megabyte of the file should work fine for this purpose.

I just checked the regulations. There may be some disputes about providing this source file on GitHub. I'm really sorry.

low-batt commented 9 months ago

This video is correctly detected as mpegts using mpv 0.35.1 / FFmpeg 5.1.2.

Commit 1237bf0d739a163c8308af97d7e482c64945dc65 adds the mime type to the AVProbeData input to av_probe_input_format2:

.mime_type = lavfdopts->allow_mimetype ? mime_type : NULL,

Would be interesting to know if disabling consideration of the mine type using the demuxer-lavf-allow-mimetype option allows the format to be correctly detected:

mpv --demuxer-lavf-allow-mimetype=no <URL>
Kectai commented 9 months ago

This video is correctly detected as mpegts using mpv 0.35.1 / FFmpeg 5.1.2.

Commit 1237bf0 adds the mime type to the AVProbeData input to av_probe_input_format2:

.mime_type = lavfdopts->allow_mimetype ? mime_type : NULL,

Would be interesting to know if disabling consideration of the mine type using the demuxer-lavf-allow-mimetype option allows the format to be correctly detected:

mpv --demuxer-lavf-allow-mimetype=no <URL>

Format can be detected correctly

mpv 'url' --demuxer-lavf-allow-mimetype=no  -v
[cplayer] Command line options: 'url' '--demuxer-lavf-allow-mimetype=no' '-v'
[cplayer] mpv 0.36.0 Copyright © 2000-2023 mpv/MPlayer/mplayer2 projects
[cplayer]  built on Sun Jul 23 05:10:36 2023
[cplayer] FFmpeg version: 6.0
[cplayer] FFmpeg library versions:
[cplayer]    libavutil       58.2.100
[cplayer]    libavcodec      60.3.100
[cplayer]    libavformat     60.3.100
[cplayer]    libswscale      7.1.100
[cplayer]    libavfilter     9.3.100
[cplayer]    libswresample   4.10.100
[cplayer]
[cplayer] Configuration: -Dhtml-build=enabled -Djavascript=enabled -Dlibmpv=true -Dlua=luajit -Dlibarchive=enabled -Duchardet=enabled -Dprefix=/opt/homebrew/Cellar/mpv/0.36.0 -Ddatadir=/opt/homebrew/Cellar/mpv/0.36.0/share/mpv -Dlibdir=/opt/homebrew/Cellar/mpv/0.36.0/lib -Dmandir=/opt/homebrew/Cellar/mpv/0.36.0/share/man -Dsysconfdir=/opt/homebrew/etc/mpv -Dbuildtype=release -Dwrap_mode=nofallback
[cplayer] List of enabled features: av-channel-layout avif_muxer bsd-fstatfs build-date cocoa coreaudio cplugins darwin ffmpeg gl gl-cocoa glob glob-posix gpl html-build iconv javascript jpeg jpegxl lcms2 libarchive libass libavdevice libbluray libdl libm luajit macos-cocoa-cb macos-media-player macos-touchbar manpage-build osx-thread-name posix posix_shm rubberband rubberband-3 stdatomic threads uchardet vapoursynth vector videotoolbox-gl zimg zimg-st428 zlib
[cplayer] Reading config file /opt/homebrew/etc/mpv/mpv/encoding-profiles.conf
[bdmv/bluray] Opening /opt/homebrew/etc/mpv/mpv/encoding-profiles.conf
[file] Opening /opt/homebrew/etc/mpv/mpv/encoding-profiles.conf
[cplayer] Applying profile 'default'...
[cplayer] Setting option 'demuxer-lavf-allow-mimetype' = 'no' (flags = 8)
[cplayer] Setting option 'v' = '' (flags = 8)
[osx/cocoacb] Created CGL pixel format with attributes: kCGLPFAOpenGLProfile, kCGLOGLPVersion_3_2_Core, kCGLPFAAccelerated, kCGLPFADoubleBuffer, kCGLPFAColorSize, 64, kCGLPFAColorFloat, kCGLPFABackingStore, kCGLPFAAllowOfflineRenderers, kCGLPFASupportsAutomaticGraphicsSwitching, 0
[libmpv_render] GL_VERSION='4.1 Metal - 86'
[libmpv_render] Detected desktop OpenGL 4.1.
[libmpv_render] GL_VENDOR='Apple'
[libmpv_render] GL_RENDERER='Apple M1 Pro'
[libmpv_render] GL_SHADING_LANGUAGE_VERSION='4.10'
[libmpv_render] Loaded extension GL_APPLE_rgb_422.
[libmpv_render] GL_*_swap_control extension missing.
[libmpv_render] Testing FBO format rgba16f
[libmpv_render] Using FBO format rgba16f.
[libmpv_render] Disabling HDR peak computation (one or more of the following is not supported: compute shaders=0, SSBO=0).
[libmpv_render] No advanced processing required. Enabling dumb mode.
[libmpv_render] Loading hwdec driver 'videotoolbox'
[cplayer] Waiting for scripts...
[osd/libass] libass API version: 0x1701000
[osd/libass] libass source: tarball: 0.17.1
[osd/libass] Shaper: FriBidi 1.0.12 (SIMPLE) HarfBuzz-ng 8.2.1 (COMPLEX)
[osd/libass] Setting up fonts...
[osd/libass] Using font provider coretext
[osd/libass] Done.
[cplayer] Set property: shared-script-properties -> 1
[cplayer] Set property: user-data/osc/visibility="auto" -> 1
[cplayer] Set property: shared-script-properties -> 1
[cplayer] Set property: user-data/osc/margins={"l":0,"b":0,"r":0,"t":0} -> 1
[cplayer] Done loading scripts.
[cplayer] Running hook: ytdl_hook/on_load
[ytdl_hook] ytdl:// hook
[ytdl_hook] not a ytdl:// url
[cplayer] Set property: shared-script-properties -> 1
[ffmpeg] Opening url
[cplayer] Set property: user-data/osc/margins={"l":0,"b":0,"r":0,"t":0} -> 1
[cplayer] Set property: shared-script-properties -> 1
[cplayer] Set property: user-data/osc/margins={"l":0,"b":0,"r":0,"t":0} -> 1
[osd/libass] libass API version: 0x1701000
[osd/libass] libass source: tarball: 0.17.1
[osd/libass] Shaper: FriBidi 1.0.12 (SIMPLE) HarfBuzz-ng 8.2.1 (COMPLEX)
[osd/libass] Setting up fonts...
[osd/libass] Using font provider coretext
[osd/libass] Done.
[ffmpeg] Mime-type: 'video/x-matroska'
[demux] Trying demuxers for level=normal.
[lavf] Found 'mpegts' at score=50 size=2048.
[ffmpeg/demuxer] mpegts: start time for stream 3 is not set in estimate_timings_from_pts
[ffmpeg/demuxer] mpegts: start time for stream 4 is not set in estimate_timings_from_pts
[ffmpeg/demuxer] mpegts: start time for stream 5 is not set in estimate_timings_from_pts
[ffmpeg] stream level seek from 5696835 to 33567463280
[ffmpeg] stream level seek from 33567466709 to 33567461566
[ffmpeg] stream level seek from 33567713280 to 33567213280
[ffmpeg] stream level seek from 33567216708 to 33567211566
[ffmpeg] stream level seek from 33567522195 to 0
[ffmpeg/demuxer] mpegts: Could not find codec parameters for stream 3 (Subtitle: hdmv_pgs_subtitle (pgssub) ([144][0][0][0] / 0x0090)): unspecified size
[ffmpeg/demuxer] Consider increasing the value for the 'analyzeduration' (0) and 'probesize' (5000000) options
[ffmpeg/demuxer] mpegts: Could not find codec parameters for stream 4 (Subtitle: hdmv_pgs_subtitle (pgssub) ([144][0][0][0] / 0x0090)): unspecified size
[ffmpeg/demuxer] Consider increasing the value for the 'analyzeduration' (0) and 'probesize' (5000000) options
[ffmpeg/demuxer] mpegts: Could not find codec parameters for stream 5 (Subtitle: hdmv_pgs_subtitle (pgssub) ([144][0][0][0] / 0x0090)): unspecified size
[ffmpeg/demuxer] Consider increasing the value for the 'analyzeduration' (0) and 'probesize' (5000000) options
[lavf] avformat_find_stream_info() finished after 0 bytes.
[demux] Detected file format: mpegts (libavformat)
[cplayer] Opening done: url
[cplayer] Running hook: ytdl_hook/on_preloaded
[lavf] select track 0
[lavf] select track 1
low-batt commented 9 months ago

I suspect the root cause of this failure is that the server providing the stream that fails to play is sending the wrong Media type:

[ffmpeg] Mime-type: 'video/x-matroska'

Previously this did not cause a failure because mpv was not passing the mime type to FFmpeg, so FFmpeg was probing the file and correctly determining the format to be mpegts. Now that mpv has been changed to provide the mime type to FFmpeg (when available), FFmpeg believes the mine type and returns matroska,webm as the format.

I am operating outside of my technical expertise, so we need to hear from the other developers here if the above analysis makes sense.

I ran some tests playing from various servers. Some did not specify a media type:

[   8.697][v][ffmpeg] Mime-type: ''
…
[   8.702][v][lavf] Found 'mpegts' at score=50 size=2048.

Some reported a generic byte stream:

[  92.921][v][ffmpeg] Mime-type: 'application/octet-stream'
…
[  93.386][v][lavf] Found 'mpegts' at score=50 size=2048.

The Wikipedia article MPEG transport stream lists video/MP2T as the media type for mpeg-ts streams.

Searching some more I found a server that serves video/x-matroska media: https://player.odycdn.com/api/v4/streams/free/sadomona/4123c18d892b0dd161e2922c5f5803fb248544bd/5a4b90

As can be seen here the mkv demuxer detects that stream:

[   7.122][v][ffmpeg] Mime-type: 'video/x-matroska'
[   7.122][d][ffmpeg] Stream opened successfully.
[   7.122][v][demux] Trying demuxers for level=normal.
[   7.122][d][demux] Trying demuxer: disc (force-level: normal)
[   7.122][d][demux] Trying demuxer: edl (force-level: normal)
[   7.122][d][demux] Trying demuxer: cue (force-level: normal)
[   7.122][d][demux] Trying demuxer: rawaudio (force-level: normal)
[   7.122][d][demux] Trying demuxer: rawvideo (force-level: normal)
[   7.122][d][demux] Trying demuxer: mkv (force-level: normal)
[   7.122][d][mkv] Found the head...
…
[   8.254][v][demux] Detected file format: Matroska

In the case at hand the mkv demuxer does not recognize the stream:

[  59.345][d][demux] Trying demuxer: rawvideo (force-level: normal)
[  59.345][d][demux] Trying demuxer: mkv (force-level: normal)
[  59.345][d][demux] Trying demuxer: libarchive (force-level: normal)
[  59.348][d][demux] Trying demuxer: lavf (force-level: normal)
[  59.352][v][lavf] Found 'matroska,webm' at score=75 size=2048.

See if others agree with this analysis.

Traneptora commented 9 months ago

The reason we provide the mimetype is FFmpeg will reject many streaming URLs (m3u8 URLs) with incorrect or missing mimetypes, since commit FFmpeg/FFmpeg@6b1f68ccb04d791f0250e05687c346a99ff47ea1. If the server provides an incorrect mimetype for mpegts, it's not clear what FFmpeg should do in that case, since probing by content is more expensive than probing by mimetype. I'll consult with upstream.

low-batt commented 9 months ago

Yes, this is one of those cases where the change that introduced a regression is valid and needed. It just had the unfortunate side effect of breaking a case where bad input data happened to be working.

Will be interesting to hear the thoughts of the FFmpeg project. I wonder if they have any insight as to how often servers are sending incorrect mime types.

I do not know mpv's philosophy on trying to compensate for bad input. In the case at hand, mpv could recognize the mime type video/x-matroska and try it's mkv demuxer. If that demuxer is unable to open the video then assume the mine type is invalid and proceed with the normal detection flow, but acting as if no mime type was supplied. Something like that. Assuming incorrect mime types are common enough to require a workaround.