Skip to content

Instantly share code, notes, and snippets.

@ShannonScott
Last active April 23, 2024 05:05
Show Gist options
  • Select an option

  • Save ShannonScott/59a7995777e496e7a933935bab8f1691 to your computer and use it in GitHub Desktop.

Select an option

Save ShannonScott/59a7995777e496e7a933935bab8f1691 to your computer and use it in GitHub Desktop.
[FFMPEG / FFPROBE Notes] Notes on using ffmpeg or ffprobe. #tags: ffmpeg, notes, video

Notes on using FFMPEG and FFPROBE

Count frames in a video

Get reported number of frames

Get the reported and actual number of frames in a video.

Note: I recently found a video that reported having 2985 frames, but actually only had 29 frames, which were all keyframes.

ffprobe -v error -select_streams v:0 -show_entries stream=nb_frames -of default=nokey=1:noprint_wrappers=1 <input-video>

Count actual frames

ffprobe -v error -count_frames -select_streams v:0 -show_entries stream=nb_read_frames -of default=nokey=1:noprint_wrappers=1 <input-video>

Count keyframes only

ffprobe -v error -skip_frame nokey -count_frames -select_streams v:0 -show_entries stream=nb_read_frames -of default=nokey=1:noprint_wrappers=1 <input-video>

Links

Transcode to h264 / MP4

ffmpeg -i <input-video> -c:v libx264 -preset slow -crf 23 -c:a copy <output-video>

Links

Trim video

Trim out two portions of the video. Keep 8s to 49s and 64s to end:

ffmpeg -i input.mp4 -filter_complex \
"[0:v]trim=start=8:end=49,setpts=PTS-STARTPTS[b]; \
 [0:v]trim=start=64,setpts=PTS-STARTPTS[d]; \
 [b][d]concat[out1]" -map '[out1]' output.mp4

Links

@xgorn

xgorn commented Jul 6, 2021

Copy link
Copy Markdown

where to install ffprobe?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment