sufehmi icon

ffmpeg CHEAT SHEET

sufehmi | PRO | 05/16/26 11:02:53 AM UTC (Edited) | 3 ⭐ | 12345 👁️ | Never ⏰ | []
Bash |

3.35 KB

|

None

|

3 👍

/

0 👎

### FASTEST CROP WITH MINIMAL QUALITY LOSS #####################################################
#
# out_w:out_h: Width and height of the cropped area.
# x:y: Top-left corner coordinates.
# -crf 18: Visually lossless quality (lower numbers = higher quality; 17–18 is standard for high fidelity).
# -c:a copy: Copies the audio without re-encoding it to save time
 
ffmpeg -i input.mp4 -vf "crop=out_w:out_h:x:y" -c:v libx264 -crf 18 -c:a copy output.mp4
 
### CONCATENATE 360 VIDEO FILES WITH 360 METADATA INTACT #######################################
# 
# even Google's AI got this wrong, sigh
# 
# first, create list of files to be concatenated, let's call it filelist.txt
# then type the filenames in it, like this:
# 
# file '/path/to/file1.mp4'
# file '/path/to/file2.mp4'
# file '/path/to/file3.mp4'
#
# then type the following command:
# the "-strict unofficial" will ensure that the 360 metadata will stay intact
 
ffmpeg -f concat -safe 0 -i filelist.txt -c copy  -strict unofficial  output.mp4
 
### CHANGE AUDIO VOLUME LEVEL BY MULTIPLIER OR DECIBEL & PRESERVE 360 VIDEO #####################
 
# change audio volume by 2x
ffmpeg -i input.mp4  -af "volume=2" -c:v copy output.mp4
 
# change audio volume into 5 dB
ffmpeg -i input.mp4  -af "volume=5db" -c:v copy output.mp4
 
# change audio volume by 2x AND preserve 360 video metadata
# otherwise the metadata will be stripped & video players will play it as 2D video
ffmpeg -i input.mp4  -af "volume=2" -c:v copy -strict unofficial output.mp4
 
### CONVERT TO WHATSAPP VIDEO FORMAT + CUT TO CERTAIN TIME #####################################
# this will result in whatsapp.mp4 which contains the contents of input.mp4 
# starting from minute 36 seconds 21 , with length of 10 seconds
# and it's compatible with WhatsApp
 
ffmpeg -i input.mp4 -ss 00:36:21 -t 00:00:10 -vcodec libx264 -acodec aac whatsapp.mp4
 
# My helmet cam produces videos in a strange format, which is rejected by WhatsApp everytime
# This one-liner produces a video that will be able to be uploaded to WhatsApp
 
### RESIZE / SCALE  ffmpeg encoding with VAAPI / hardware acceleration #########################
# I got about 7x speed up + very low CPU usage 
# (so I'm able do other stuff while ffmpeg is busy doing the decoding/encoding)
 
# need this installed first 
apt-get install intel-media-va-driver-non-free
# if you keep getting the following error - that means you need to execute that command above:
#         Failed to create processing pipeline config: 12 (the requested VAProfile is not supported)
 
# let's go 
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
 
# to find your vaapi device, type : ls  /dev/dri/* 
# see list of standard resolutions here : https://levvvel.com/169-resolutions/
# remove ",fps=fps=25" bit if you're not changing the fps rate
 
### FASTEST WAY TO CUT A VIDEO #############################################################
# this will result in output.mp4 which contains the contents of input.mp4 
# from minute 36 seconds 21 , with length of 10 seconds
 
ffmpeg -i input.mp4 -ss 00:36:21 -t 00:00:10 -acodec copy -vcodec copy output.mp4
 
 

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎