web-dev-qa-db-ja.com

ffmpegを使用してビデオをトリミングし、連結する-「出力ストリームに非単調なDTSで)」エラーが発生する

私は2本のビデオを持っていて、両方のビデオの両端をドロップし、中央部分のみを残してから、中央部分を連結する必要があります。どちらのビデオもまったく同じオリジンです-同じFPSと同じコーデック。

私がやろうとしていること:

ffmpeg -i 0.mp4 -c:v h264_nvenc -preset fast -rc vbr -qmin 1 -qmax 1 -filter_complex "[0:v]trim=start=01.00:duration=03.00,setpts=PTS-STARTPTS[vmiddle]" -map [vmiddle] middle_0.mp4
ffmpeg -i 1.mp4 -c:v h264_nvenc -preset fast -rc vbr -qmin 1 -qmax 1 -filter_complex "[0:v]trim=start=01.00:duration=03.00,setpts=PTS-STARTPTS[vmiddle]" -map [vmiddle] middle_1.mp4

これらの2つのコマンドは、01.00で始まり、04.00で終わる各ビデオの中央部分のみを切り取ります。

次に、ビデオを連結します。

ffmpeg -y -f concat -i concat.txt -c copy concat.mp4

Concat.txtファイルには明らかに以下が含まれます:

file 'middle0.mp4'
file 'middle1.mp4'

しかし、これは機能しません。出力ビデオconcat.mp4には奇妙な不具合が含まれており、コンソールで多くのエラーが発生します。

[mov,mp4,m4a,3gp,3g2,mj2 @ 00000000025ead60] Auto-inserting h264_mp4toannexb bitstream filter
[concat @ 0000000000dd6bc0] DTS 34666 < 45568 out of order
[mp4 @ 0000000000ddbfe0] Non-monotonous DTS in output stream 0:0; previous: 45568, current: 34666; changing to 45569. This may result in incorrect timestamps in the output file.
[mp4 @ 0000000000ddbfe0] Non-monotonous DTS in output stream 0:0; previous: 45569, current: 35050; changing to 45570. This may result in incorrect timestamps in the output file.
[mp4 @ 0000000000ddbfe0] Non-monotonous DTS in output stream 0:0; previous: 45570, current: 35434; changing to 45571. This may result in incorrect timestamps in the output file.
[mp4 @ 0000000000ddbfe0] Non-monotonous DTS in output stream 0:0; previous: 45571, current: 35818; changing to 45572. This may result in incorrect timestamps in the output file.
[mp4 @ 0000000000ddbfe0] Non-monotonous DTS in output stream 0:0; previous: 45572, current: 36202; changing to 45573. This may result in incorrect timestamps in the output file.
[mp4 @ 0000000000ddbfe0] Non-monotonous DTS in output stream 0:0; previous: 45573, current: 36586; changing to 45574. This may result in incorrect timestamps in the output file.
[mp4 @ 0000000000ddbfe0] Non-monotonous DTS in output stream 0:0; previous: 45574, current: 36970; changing to 45575. This may result in incorrect timestamps in the output file.
[mp4 @ 0000000000ddbfe0] Non-monotonous DTS in output stream 0:0; previous: 45575, current: 37354; changing to 45576. This may result in incorrect timestamps in the output file.
[mp4 @ 0000000000ddbfe0] Non-monotonous DTS in output stream 0:0; previous: 45576, current: 37738; changing to 45577. This may result in incorrect timestamps in the output file.
[mp4 @ 0000000000ddbfe0] Non-monotonous DTS in output stream 0:0; previous: 45577, current: 38122; changing to 45578. This may result in incorrect timestamps in the output file.
[mp4 @ 0000000000ddbfe0] Non-monotonous DTS in output stream 0:0; previous: 45578, current: 38506; changing to 45579. This may result in incorrect timestamps in the output file.
[mp4 @ 0000000000ddbfe0] Non-monotonous DTS in output stream 0:0; previous: 45579, current: 38890; changing to 45580. This may result in incorrect timestamps in the output file.
[mp4 @ 0000000000ddbfe0] Non-monotonous DTS in output stream 0:0; previous: 45580, current: 39274; changing to 45581. This may result in incorrect timestamps in the output file.
[mp4 @ 0000000000ddbfe0] Non-monotonous DTS in output stream 0:0; previous: 45581, current: 39658; changing to 45582. This may result in incorrect timestamps in the output file.
[mp4 @ 0000000000ddbfe0] Non-monotonous DTS in output stream 0:0; previous: 45582, current: 40042; changing to 45583. This may result in incorrect timestamps in the output file.
[mp4 @ 0000000000ddbfe0] Non-monotonous DTS in output stream 0:0; previous: 45583, current: 40426; changing to 45584. This may result in incorrect timestamps in the output file.
[mp4 @ 0000000000ddbfe0] Non-monotonous DTS in output stream 0:0; previous: 45584, current: 40810; changing to 45585. This may result in incorrect timestamps in the output file.
[mp4 @ 0000000000ddbfe0] Non-monotonous DTS in output stream 0:0; previous: 45585, current: 41194; changing to 45586. This may result in incorrect timestamps in the output file.
[mp4 @ 0000000000ddbfe0] Non-monotonous DTS in output stream 0:0; previous: 45586, current: 41578; changing to 45587. This may result in incorrect timestamps in the output file.
[mp4 @ 0000000000ddbfe0] Non-monotonous DTS in output stream 0:0; previous: 45587, current: 41962; changing to 45588. This may result in incorrect timestamps in the output file.
[mp4 @ 0000000000ddbfe0] Non-monotonous DTS in output stream 0:0; previous: 45588, current: 42346; changing to 45589. This may result in incorrect timestamps in the output file.
[mp4 @ 0000000000ddbfe0] Non-monotonous DTS in output stream 0:0; previous: 45589, current: 42730; changing to 45590. This may result in incorrect timestamps in the output file.
[mp4 @ 0000000000ddbfe0] Non-monotonous DTS in output stream 0:0; previous: 45590, current: 43114; changing to 45591. This may result in incorrect timestamps in the output file.
[mp4 @ 0000000000ddbfe0] Non-monotonous DTS in output stream 0:0; previous: 45591, current: 43498; changing to 45592. This may result in incorrect timestamps in the output file.
[mp4 @ 0000000000ddbfe0] Non-monotonous DTS in output stream 0:0; previous: 45592, current: 43882; changing to 45593. This may result in incorrect timestamps in the output file.
[mp4 @ 0000000000ddbfe0] Non-monotonous DTS in output stream 0:0; previous: 45593, current: 44266; changing to 45594. This may result in incorrect timestamps in the output file.
[mp4 @ 0000000000ddbfe0] Non-monotonous DTS in output stream 0:0; previous: 45594, current: 44650; changing to 45595. This may result in incorrect timestamps in the output file.
[mp4 @ 0000000000ddbfe0] Non-monotonous DTS in output stream 0:0; previous: 45595, current: 45034; changing to 45596. This may result in incorrect timestamps in the output file.
[mp4 @ 0000000000ddbfe0] Non-monotonous DTS in output stream 0:0; previous: 45596, current: 45418; changing to 45597. This may result in incorrect timestamps in the output file.

注:setpts=PTS-STARTPTSを使用してプレゼンテーションのタイムスタンプを既に設定しているため、各ビデオは00.00から始まります。しかし、この単調でないDTSを修正する方法は?私は本当に行き詰まっています、助けてください。

連結中にビデオを再エンコードすることでこれを修正できることは知っていますが、これを買う余裕はありません。この手順は長いパイプラインの一部であり、時間は非常に重要です。コピーコーデックを使用する必要があります。

追加:

両方のビデオに対してffprobe出力を要求しました。 ffprobeの出力についてはほとんど知りません。何が起こっているのか、なぜ矛盾があるのか​​、そしてそれが何を意味するのか説明していただけませんか。 (第1ビデオで512ステップ、第2ビデオで384ステップ)

Middle0(最初のビデオ)

ミドル1(2番目のビデオ)

5

使用する

ffmpeg -i 0.mp4 -c:v h264_nvenc -preset fast -rc vbr -qmin 1 -qmax 1 -filter_complex "[0:v]trim=start=01.00:duration=03.00,setpts=PTS-STARTPTS[vmiddle]" -video_track_timescale 18000 -map [vmiddle] middle_0.mp4

Ffprobe読み出しのこれらの数値はプレゼンテーションのタイムスタンプであり、各フレームを表示するタイミングをプレーヤーに通知します。これらは、タイムベースで表されます。したがって、タイムベースが1/1200(またはタイムスケールが1200)の600のPTSは、600 * 1/1200 = 0.5秒の表示時間を意味し、タイムスケールが1400のPTSが700であることを意味します。異なるタイムベースのビデオが結合されると、ffmpegが最初のビデオのタイムベースを最終的な値として採用するため、結果は正しくありません。それらを均一にするためにパラメーターを追加しました。

2
Gyan

https://trac.ffmpeg.org/wiki/Concatenate のとおり

私も同じ問題を抱えていました。 Macでffmpegバージョン2.6.3を実行しています。 -q 0のタグを追加してソースクリップを.MTS形式に変換し、テキストファイルの拡張子を更新して、ffmpegでconcatコマンドを実行したときに出力ファイルを.MTSに設定しました。それは魅力のように働きました。これが私のワークフローです。

ffmpeg -i clip-1.MOV -q 0 clip-1.MTS

ffmpeg -i clip-2.MOV -q 0 clip-2.MTS

テキストファイル(mylist.txt)を次のように更新しました。

file clip-1.MTS
file clip-2.MTS

次に、次のようにconcatコマンドを実行しました。

ffmpeg -f concat -i mylist.txt -c copy output.MTS

私のために働いた!最終的なoutput.MTSを必要な形式に変換できます。

0
Duncan Lindsey