播放時將 mpv --ytdl 中播放的影片儲存到檔案中

播放時將 mpv --ytdl 中播放的影片儲存到檔案中

我希望能夠玩使用 mpv --ytdl 儲存影片。我怎樣才能做到這一點?特別重要的是緩衝區也被保存了。

基本上,我想播放來自 youtube 的視頻,然後退出 mpv 並且仍然能夠繼續觀看視頻直到加載它 - 這就是為什麼我還需要將緩衝區保存到文件中。

我已經嘗試過使用 youtube-dl -o - 將視訊串流傳輸到標準輸出,然後使用 mpv 進行管道傳輸,即

youtube-dl -o - | mpv -

(我的想法是,我可以使用 tee 來分割流並簡單地將其寫入文件) - 但是,這有一個問題,我無法使用 mpv 來瀏覽視頻 - 它只是一個來自 stdin 之後的固定流全部。我的另一個想法是使用 mpv 的 -o 選項來指定輸出檔。然而,這並沒有節省內部緩衝區。

答案1

另一個選項,仍然是高度實驗性的,是使用 mpv 自己的--record-file

mpv --record-file=video.mkv https://www.youtube.com/watch?v=…

我在這方面取得的成功有限。由於 youtube-dl 抓取的來源檔案需要與您為錄製檔案指定的檔案副檔名相符。然而,這似乎最接近問題中所描述的內容。

(當前穩定的)手冊:

--record-file=<file>

將目前流記錄到給定的目標檔案。目標檔案總是會被覆蓋而無需詢問。

這會在不重新編碼的情況下重新復用源流,這使得這是一個非常脆弱和實驗性的功能。這完全有可能寫入已損壞、不符合標準、無法與所有播放器(包括 mpv)播放或不完整的檔案。

目標檔案格式由目標檔案名稱的檔案副檔名決定。如果可能,建議使用與來源容器相同的目標容器,並首選 Matroska 作為後備。

在串流記錄期間查找,或在播放期間啟用/停用串流記錄,可能會切斷數據,或在輸出檔案中產生「漏洞」。這些都是技術限制。特別是,提前讀取的視訊資料或字幕可能會產生此類漏洞,這可能會導致各種播放器(包括 mpv)的播放問題。

此選項的行為將來可能會發生變化,例如將其更改為模板(類似於--screenshot-template)、重新命名、刪除或其他任何操作,直到它被聲明為半穩定。

答案2

--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.
 --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).

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

答案3

youtube-dl -o - | tee video.mp4 | mpv -

答案4

youtube-dl url --exec mpv

這不會串流傳輸,但會在下載後播放,但除非您有撥號帳戶或其他帳戶,否則您不會知道其中的區別。

相關內容