computers:ffmpeg

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
computers:ffmpeg [2024/09/14 03:24] – [Joining video files together (Concatenate)] joncomputers:ffmpeg [2025/12/15 16:40] (current) jon
Line 98: Line 98:
 Example using Powershell: Example using Powershell:
 <code>ffmpeg -ss 00:53:00 -i 'input' -avoid_negative_ts 1 -to 07:19:17 -c copy 'output'</code> <code>ffmpeg -ss 00:53:00 -i 'input' -avoid_negative_ts 1 -to 07:19:17 -c copy 'output'</code>
 +
 +=== Caveats to cropping ===
 +
 +When you do cut with -c copy (no re-encode), and the cut point is not exactly on a keyframe, and/or the video uses B-frames (re-ordered frames), ffmpeg can’t rewrite frames to make a clean boundary. It copies packets but the decode/display timestamps (DTS/PTS) can become inconsistent around the cut boundary. Then when you concat, ffmpeg sees timestamps going “backwards” and prints: "Non-monotonic DTS... This may result in incorrect timestamps."
 +
 +Players often still play linearly, but seeking near the splice can fail hard (especially around the crop point). mp4 is particularly sensitive because it stores timing/indexing in a way that makes sloppy cuts more painful than in some other workflows.
 +
 +Workaround is to use a copy-cut and regenerate timestamps
 +
 +<code>ffmpeg -ss 0 -to 02:03:12 -i ogvideo.mp4 \
 +  -map 0 -c copy \
 +  -fflags +genpts -avoid_negative_ts make_zero \
 +  croppedvid.mp4</code>
 +
 +Then, "remux normalize" the video to give clean metadata. This is a nice to do on all the videos that you're working on if concat-ing them togther
 +
 +<code>
 +ffmpeg -i croppedvid.mp4 -map 0 -c copy -movflags +faststart fixed1.mp4
 +</code>
 +
 ==== Joining video files together (Concatenate) ==== ==== Joining video files together (Concatenate) ====
  
Line 110: Line 130:
 </code> </code>
  
-Here's how I've scripted this. Note, this pertains more to macOS with the sed statement since the '' is needed, but the tweak for linux is to just remove the '' -e+Here's how I've scripted this. Note, this pertains more to macOS with the sed statement since the single quotes are needed, but the tweak for linux is to just remove the single quotes and the -e
 <code> <code>
 find . -type f > concat.txt && sed -i '' -e '/^\.\/\.DS_Store$/d' -e '/^\.\/concat\.txt$/d' -e 's/^\.\///' -e 's/^/file /' concat.txt find . -type f > concat.txt && sed -i '' -e '/^\.\/\.DS_Store$/d' -e '/^\.\/concat\.txt$/d' -e 's/^\.\///' -e 's/^/file /' concat.txt
Line 117: Line 137:
 Then, reference the text file as your input. Then, reference the text file as your input.
 <code> <code>
-ffmpeg -f concat -i textfile.txt -c copy output.mp4+ffmpeg -f concat -safe 0 -i concat.txt -c copy output.mp4
 </code> </code>
 +
 ==== Splitting a large video into smaller clips ==== ==== Splitting a large video into smaller clips ====
 https://trac.ffmpeg.org/wiki/Seeking#Cuttingsmallsections https://trac.ffmpeg.org/wiki/Seeking#Cuttingsmallsections
  • computers/ffmpeg.1726284264.txt.gz
  • Last modified: 2024/09/14 03:24
  • by jon