2024-12-25

ffmpeg

Table of Contents

Flags:

1. Convert all audio to mp3

for i in *.webm; do ffmpeg -i "$i" "${i%.*}.mp3"; done

2. Extract clip from audio/video file

ffmpeg -i input-file.webm -ss 00:31:04 -to 00:31:45 -c copy -map_metadata 0 clip-output.webm
ffmpeg -i [input_file] -ss [start_time] -t [duration] -c copy -map_metadata 0 [output_file]

3. Remove audio from video

ffmpeg -i $input_file -c copy -an $output_file

4. Add audio to image

image.jpg + music.mp3 = video.mp4

ffmpeg -loop 1 -i image.jpg -i music.mp3  -c:v libx264 -tune stillimage -c:a aac -b:a 192k -shortest -pix_fmt yuv420p video.mp4

5. Get media details

ffprobe  -print_format json -show_format -show_streams [input_file] | less

6. Compress video

Just Re-encode with default CRF (23) and default codec (H264):

ffmpeg -i input.mp4 -map_metadata 0 -movflags use_metadata_tags output.mp4

Re-encode with codec H265 with default CRF (28) [But this sometimes gives problem with QuickTimePlayer in Mac]

ffmpeg -i input.mp4 -c:v libx265 -crf 28 -map_metadata 0 -movflags use_metadata_tags output.mp4

Uses

  • H.265 format
  • CRF (Constant Rate Factor) of 28 (Default for H.265)

Increasing CRF by 6 results to half of file size


Backlinks


You can send your feedback, queries here