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 [2021/01/15 19:52] – [Fading out audio in a specific spot] localadmincomputers:ffmpeg [2025/12/15 16:40] (current) jon
Line 12: Line 12:
  
 https://www.youtube.com/watch?v=sn_TDa9zY1c https://www.youtube.com/watch?v=sn_TDa9zY1c
 +
 +==== Mini DV Tapes ====
 +
 +  * Use WinDV for ingestion. It will break out each stop/start on the tape into new files.
 +  * Touch up for YT spec with all inclusive script, if audio is off, switch to mono.
  
 ==== DVDs ==== ==== DVDs ====
Line 27: Line 32:
 === Template for YouTube Specs === === Template for YouTube Specs ===
 https://support.google.com/youtube/answer/1722171 https://support.google.com/youtube/answer/1722171
 +https://support.google.com/youtube/answer/4603579?hl=en
 <code>ffmpeg -i input -c:v libx264 -preset slow -profile:v high -crf 18 -coder 1 -pix_fmt yuv420p -movflags +faststart -g 30 -bf 2 -c:a aac -b:a 384k -profile:a aac_low output</code> <code>ffmpeg -i input -c:v libx264 -preset slow -profile:v high -crf 18 -coder 1 -pix_fmt yuv420p -movflags +faststart -g 30 -bf 2 -c:a aac -b:a 384k -profile:a aac_low output</code>
  
 ==== Scripting ==== ==== Scripting ====
 +
 +=== Bash Scripting ===
 +When building out bash scripting, you will need to run your ffmpeg commands with -nostdin if you are piping in variables with paths((https://stackoverflow.com/questions/21634088/execute-ffmpeg-command-in-a-loop)). ffmpeg uses stdin for its commands, which will break your 'while read' commands.
 +
 +<note tip>
 +-stdin
 +
 +Enable interaction on standard input. On by default unless standard input is used as an input. To explicitly disable interaction you need to specify -nostdin.
 +Disabling interaction on standard input is useful, for example, if ffmpeg is in the background process group. Roughly the same result can be achieved with ffmpeg ... < /dev/null but it requires a shell.</note>
  
 === Batch Filing === === Batch Filing ===
Line 58: Line 73:
  
 === Powershell Coding === === Powershell Coding ===
 +
 +==== Frequent Commands ====
 +
 +https://www.videoproc.com/resource/ffmpeg-commands.htm
 +
 +==== Listing out features ====
 +
 +https://dev.to/drsensor/list-of-helpful-ffmpeg-command-for-checking-capabilities-1110
  
 ==== Watermarking ==== ==== Watermarking ====
Line 75: 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 80: Line 123:
 https://stackoverflow.com/questions/7333232/how-to-concatenate-two-mp4-files-using-ffmpeg https://stackoverflow.com/questions/7333232/how-to-concatenate-two-mp4-files-using-ffmpeg
 https://stackoverflow.com/questions/18474312/concatenate-join-mp4-files-using-ffmpeg-and-windows-command-line-batch-not-lin https://stackoverflow.com/questions/18474312/concatenate-join-mp4-files-using-ffmpeg-and-windows-command-line-batch-not-lin
 +
 +Make a text file in the same directory. Each video needs the word 'file' at the beginning of the line to delineate.
 +<code>
 +file videofile.mp4
 +file videfile2.mp4
 +</code>
 +
 +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>
 +find . -type f > concat.txt && sed -i '' -e '/^\.\/\.DS_Store$/d' -e '/^\.\/concat\.txt$/d' -e 's/^\.\///' -e 's/^/file /' concat.txt
 +</code>
 +
 +Then, reference the text file as your input.
 +<code>
 +ffmpeg -f concat -safe 0 -i concat.txt -c copy output.mp4
 +</code>
  
 ==== Splitting a large video into smaller clips ==== ==== Splitting a large video into smaller clips ====
 +https://trac.ffmpeg.org/wiki/Seeking#Cuttingsmallsections
  
 Example in Batch: Example in Batch:
Line 105: Line 165:
 ==== Muting specific spots in your video ==== ==== Muting specific spots in your video ====
  
-Example from the link: +Example from the link. This mutes audio at the 59 second mark down to 0 and then back up at 1:01 
-<code>ffmpeg -i video.mp4 -af "volume=enable='between(t,5,10)':volume=0, volume=enable='between(t,15,20)':volume=0" ..</code>+<code>ffmpeg -i input -vcodec copy -af "volume=enable='between(t,59,61)':volume=0" output</code>
  
 https://stackoverflow.com/questions/29215197/mute-specified-sections-of-an-audio-file-using-ffmpeg https://stackoverflow.com/questions/29215197/mute-specified-sections-of-an-audio-file-using-ffmpeg
Line 125: Line 185:
 ffmpeg -i video.mp4 -vcodec copy -af "afade=t=out:st=59:d=1,afade=t=in:st=61:d=1" out.mp4 ffmpeg -i video.mp4 -vcodec copy -af "afade=t=out:st=59:d=1,afade=t=in:st=61:d=1" out.mp4
 </code> </code>
 +==== Adjusting audio to broadcast spec ====
 +
 +https://www.reddit.com/r/ffmpeg/comments/b2ygzt/increase_volume_on_multiple_files/
 +
 ==== Converting from one file type to another ==== ==== Converting from one file type to another ====
  
Line 130: Line 194:
  
 Trying to adjust MKV files. Safe bet, do all adjustments to MP4 file first, then MKV when permanent. - https://superuser.com/questions/1411133/ffmpeg-invalid-length-0x59f0-0x8bd7fe90-in-parent-when-trying-to-do-anything Trying to adjust MKV files. Safe bet, do all adjustments to MP4 file first, then MKV when permanent. - https://superuser.com/questions/1411133/ffmpeg-invalid-length-0x59f0-0x8bd7fe90-in-parent-when-trying-to-do-anything
 +
 +==== Limiting Cores/Threads ====
 +
 +https://superuser.com/questions/155305/how-many-threads-does-ffmpeg-use-by-default
 +
 +
 +==== Hardware Acceleration ====
 +
 +https://trac.ffmpeg.org/wiki/HWAccelIntro
 +https://www.rickmakes.com/ffmpeg-notes/
 +
 +Each OS has its own Platform APIs of hardware acceleration and additionally, Intel, AMD, and Nvidia GPUs have their own hardware acceleration protocols.
 +
 +Nvidia on Windows/Linux has h264_nvenc, hevc_nvenc(h265), and av1_nvenc
 +Intel on Windows/Linux has h264_qsv, hevc_qsv, etc...
 +
 +macOS supports VideoToolBox for Intel QuickSync, such as h264_videotoolbox, hevc_videotoolbox, and prores_videotoolbox 
 +
 +==== Unorganized Links ====
 +
 +https://dev.to/drsensor/list-of-helpful-ffmpeg-command-for-checking-capabilities-1110
 +https://stackoverflow.com/questions/68977300/ffmpeg-more-than-1000-frames-duplicated-and-input-height-doesnt-match
  • computers/ffmpeg.1610740333.txt.gz
  • Last modified: 2021/01/15 19:52
  • by localadmin