Search code examples
ffmpeg

fastest way to re-encode x264 videos using ffmpeg


Hello I am looking for the fastest way to fastest way to re-encode x264 mp4 and insert keyframes while using minimal resource as possible.

Thank you.


Solution

  • Add -preset ultrafast:

    ffmpeg -i input.mp4 -codec:v libx264 -preset ultrafast -force_key_frames "expr:gte(t,n_forced*4)" -hls_time 4 -hls_playlist_type vod -hls_segment_type mpegts vid.m3u8
    
    • It is recommended to use the slowest -preset you can. See FFmpeg Wiki: H.264 for more info.

    • You can also add -codec:a copy to stream copy the audio to avoid re-encoding it.

    • If you have access to a hardware accelerated H.264 encoder then you can look into using that instead, but none are as efficient as x264 (quality per bit).

    fastest way to re-encode [...] while using minimal resource as possible

    This is mutually exclusive. Video encoding is resource intensive you have to make a compromise between encoding speed, efficiency, and less resource use. If you want to use fewer resources the result is slower encoding and/or lower quality per bit.