sufehmi

ffmpeg CHEAT SHEET

May 16th, 2026 (edited)
6,261
3
Never
4
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.35 KB | None | 3 0
  1. ### FASTEST CROP WITH MINIMAL QUALITY LOSS #####################################################
  2. #
  3. # out_w:out_h: Width and height of the cropped area.
  4. # x:y: Top-left corner coordinates.
  5. # -crf 18: Visually lossless quality (lower numbers = higher quality; 17–18 is standard for high fidelity).
  6. # -c:a copy: Copies the audio without re-encoding it to save time
  7.  
  8. ffmpeg -i input.mp4 -vf "crop=out_w:out_h:x:y" -c:v libx264 -crf 18 -c:a copy output.mp4
  9.  
  10. ### CONCATENATE 360 VIDEO FILES WITH 360 METADATA INTACT #######################################
  11. #
  12. # even Google's AI got this wrong, sigh
  13. #
  14. # first, create list of files to be concatenated, let's call it filelist.txt
  15. # then type the filenames in it, like this:
  16. #
  17. # file '/path/to/file1.mp4'
  18. # file '/path/to/file2.mp4'
  19. # file '/path/to/file3.mp4'
  20. #
  21. # then type the following command:
  22. # the "-strict unofficial" will ensure that the 360 metadata will stay intact
  23.  
  24. ffmpeg -f concat -safe 0 -i filelist.txt -c copy  -strict unofficial  output.mp4
  25.  
  26. ### CHANGE AUDIO VOLUME LEVEL BY MULTIPLIER OR DECIBEL & PRESERVE 360 VIDEO #####################
  27.  
  28. # change audio volume by 2x
  29. ffmpeg -i input.mp4  -af "volume=2" -c:v copy output.mp4
  30.  
  31. # change audio volume into 5 dB
  32. ffmpeg -i input.mp4  -af "volume=5db" -c:v copy output.mp4
  33.  
  34. # change audio volume by 2x AND preserve 360 video metadata
  35. # otherwise the metadata will be stripped & video players will play it as 2D video
  36. ffmpeg -i input.mp4  -af "volume=2" -c:v copy -strict unofficial output.mp4
  37.  
  38. ### CONVERT TO WHATSAPP VIDEO FORMAT + CUT TO CERTAIN TIME #####################################
  39. # this will result in whatsapp.mp4 which contains the contents of input.mp4
  40. # starting from minute 36 seconds 21 , with length of 10 seconds
  41. # and it's compatible with WhatsApp
  42.  
  43. ffmpeg -i input.mp4 -ss 00:36:21 -t 00:00:10 -vcodec libx264 -acodec aac whatsapp.mp4
  44.  
  45. # My helmet cam produces videos in a strange format, which is rejected by WhatsApp everytime
  46. # This one-liner produces a video that will be able to be uploaded to WhatsApp
  47.  
  48. ### RESIZE / SCALE  ffmpeg encoding with VAAPI / hardware acceleration #########################
  49. # I got about 7x speed up + very low CPU usage
  50. # (so I'm able do other stuff while ffmpeg is busy doing the decoding/encoding)
  51.  
  52. # need this installed first
  53. apt-get install intel-media-va-driver-non-free
  54. # if you keep getting the following error - that means you need to execute that command above:
  55. #         Failed to create processing pipeline config: 12 (the requested VAProfile is not supported)
  56.  
  57. # let's go
  58. time ffmpeg -init_hw_device vaapi=foo:/dev/dri/renderD128 -hwaccel vaapi -hwaccel_output_format vaapi -hwaccel_device foo -i INPUT-720p.mp4 -filter_hw_device foo -vf 'format=nv12|vaapi,hwupload,scale_vaapi=iw/2:ih/2:mode=hq,fps=fps=25' -c:v h264_vaapi  -compression_level 1 -y -c:a copy OUTPUT-360p.mp4
  59.  
  60. # to find your vaapi device, type : ls  /dev/dri/*
  61. # see list of standard resolutions here : https://levvvel.com/169-resolutions/
  62. # remove ",fps=fps=25" bit if you're not changing the fps rate
  63.  
  64. ### FASTEST WAY TO CUT A VIDEO #############################################################
  65. # this will result in output.mp4 which contains the contents of input.mp4
  66. # from minute 36 seconds 21 , with length of 10 seconds
  67.  
  68. ffmpeg -i input.mp4 -ss 00:36:21 -t 00:00:10 -acodec copy -vcodec copy output.mp4
  69.  
  70.  
Advertisement