播放时将 mpv --ytdl 中播放的视频保存到文件中

Paw*_*uin 6 video streaming youtube-dl mpv

我希望能够使用 mpv --ytdl播放保存视频。我怎么会那样做?特别重要的是缓冲区也得到了保存。

基本上,我想从 youtube 播放视频,然后退出 mpv 并且仍然能够继续观看视频直到它被加载 - 这就是为什么我还需要将缓冲区保存到文件中。

我已经尝试使用 youtube-dl -o - 将视频流式传输到标准输出,然后使用 mpv 进行管道传输,即

youtube-dl -o - | mpv -
Run Code Online (Sandbox Code Playgroud)

(我的想法是我可以使用 tee 来拆分流并将其简单地写入文件)-但是,这有一个问题,即我无法使用 mpv 来浏览视频-它只是一个来自 stdin 之后的固定流全部。我的另一个想法是使用 mpv 的 -o 选项来指定输出文件。但是,这不会保存内部缓冲区。

小智 11

另一个仍然处于高度实验阶段的选择是使用 mpv 自己的--record-file

mpv --record-file=video.mkv https://www.youtube.com/watch?v=…
Run Code Online (Sandbox Code Playgroud)

我的成功有限。由于 youtube-dl 获取的源文件需要与您为录制文件指定的文件扩展名相匹配。然而,这似乎与问题中描述的最接近。

(当前稳定的)手册

--record-file=<file>

将当前流记录到给定的目标文件。目标文件将始终被覆盖而不询问。

这会在不重新编码的情况下重新混合源流,这使其成为非常脆弱和实验性的功能。这完全有可能写入已损坏、不符合标准、无法与所有播放器(包括 mpv)播放或不完整的文件。

目标文件格式由目标文件名的文件扩展名决定。如果可能,建议使用与源容器相同的目标容器,并首选 Matroska 作为后备。

在流记录过程中寻找,或在播放过程中启用/禁用流记录,可能会切断数据,或在输出文件中产生“漏洞”。这些是技术限制。特别是,提前读取的视频数据或字幕可能会产生此类漏洞,这可能会导致各种播放器(包括 mpv)出现播放问题。

此选项的行为将来可能会更改,例如将其更改为模板(类似于--screenshot-template)、重命名、删除或其他任何内容,直到它被声明为半稳定。


Wis*_*Wis 7

--record-file已弃用,支持--stream-record. 两者都不是完美的解决方案,因为超出缓存的快进将导致输出文件中的跳过。

从 mpv 手册页:

--record-file=<file>
       Deprecated, use --stream-record, or the dump-cache command.

       Record the current stream to the given target file. The target file will always be overwritten without asking.

       This was deprecated because it isn't very nice to use. For one, seeking while this is enabled will be directly reflected in  the
       output, which was not useful and annoying.
Run Code Online (Sandbox Code Playgroud)
 --stream-record=<file>
        Write  received/read  data from the demuxer to the given output file.
        The output file will always be overwritten without asking.
        The output format is determined by the extension of the output file.

        Switching streams or seeking during recording might result in recording
        being stopped and/or broken files. Use with care.

        Seeking outside of the demuxer cache will result in "skips" in the output file,
        but seeking within  the demuxer cache should not affect  recording. 
        One exception is when you seek back far enough to exceed the forward buffering size,
        in which case the cache stops actively reading.
        This will return in dropped data if it's a live stream.

        If this is set at runtime, the old file is closed, and the new file is opened.
        Note that this will write only data that  is  appended at the end of the cache,
        and the already cached data cannot be written.
        You can try the dump-cache command as an alternative.

        External files (--audio-file etc.) are ignored by this,
        it works on the "main" file only. Using this with  files  using  ordered
        chapters or EDL files will also not work correctly in general.

        There  are  some  glitches with this because it uses FFmpeg's libavformat for writing the output file.
        For example, it's typical that it will only work if the output format is the same as the input format.
        This is the case even if it works with  the  ffmpeg tool.
        One reason for this is that ffmpeg and its libraries contain certain hacks and workarounds for these issues,
        that are unavailable to outside users.

        This replaces --record-file.
        It is similar to the ancient/removed --stream-capture/-capture options,
        and provides better  behavior in most cases (i.e. actually works).
Run Code Online (Sandbox Code Playgroud)

用法: mpv --stream-record=$HOME/Downloads/path/name.mp4 <URL>


Ipo*_*cer 6

youtube-dl -o - | tee video.mp4 | mpv -
Run Code Online (Sandbox Code Playgroud)