mpv --ytdl で再生中のビデオを再生中にファイルに保存する

mpv --ytdl で再生中のビデオを再生中にファイルに保存する

プレイできるようになりたいそしてmpv --ytdl でビデオを保存します。どうすればいいでしょうか? 特に重要なのは、バッファも保存されることです。

基本的に、YouTube からビデオを再生し、mpv を終了しても、ビデオがロードされた時点までビデオを視聴し続けられるようにしたいので、バッファをファイルに保存する必要もあります。

私はすでにyoutube-dl -o -を使用してビデオをstdoutにストリーミングし、それを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

これはストリーミングではなくダウンロード後に再生されますが、ダイヤルアップ アカウントなどを持っていない限り、違いはわかりません。

関連情報