ffmpeg.md 2.0 KB


title: FFmpeg breadcrumbs:

  • title: Media --- {% include header.md %}

Resources

General

  • TODO Find my other FFmpeg notes.
  • Install:
    • Linux (Ubuntu): apt install ffmpeg
    • Windows: Download the binary.
  • View video feed: ffplay <dev>
    • For some reason this typically uses a limited framerate and resolution.
  • Options (TODO move this):
    • -crf 23: Constant rate factor. Defaults to 23. Set to 0 for lossless video.

Examples

Recording

  • Record stream to file, automatically split every X seconds, restart if the stream is unavailable:
    • Script: while true; do ffmpeg -hide_banner -loglevel error -i http://localhost:5555/ -c copy -map 0 -f segment -segment_time $((5*60)) -segment_format mp4 -strftime 1 "%Y-%m-%d_%H-%M-%S.mp4"; sleep 1; done
  • Record time lapse at 10x speed without audio:
    • Command: ffmpeg -i http://localhost:5555/ -filter:v "setpts=0.1*PTS" -an out.mkv

Tasks

Concatenate Video Files

Useful e.g. to recombine video files for recorders which automatically splits the recording.

  1. ffmpeg -f concat -safe 0 -i <(for f in ./*.MP4; do echo "file '$PWD/$f'"; done) -c copy output.MP4
    • For lexicographically sorted files ending in .MP4.

Speed Up/Slow Down Video, but Keep All Frames

Useful e.g. to change the framerate of a video-only timelapse video.

See: Speeding up/slowing down video (FFmpeg)

  1. Convert to raw bitstream:
    • H.264: ffmpeg -i input.mp4 -map 0:v -c:v copy -bsf:v h264_mp4toannexb raw.h264
    • H.265: ffmpeg -i input.mp4 -map 0:v -c:v copy -bsf:v hevc_mp4toannexb raw.h265
  2. Generate new video: ffmpeg -fflags +genpts -r <fps> -i raw.h264 -c:v copy output.mp4 (for desired frame rate fps)

{% include footer.md %}