Search code examples
ffmpeghandbrakecli

Speed up hardcoding subs with ffmpeg vs handbrake


I have a video that i need to hardcode subtitles for legacy devices so I usually use ffmpeg for this and it works fine but its so slow.

This is the command i usually use.

ffmpeg -i test-cut.mp4 -vf "subtitles=test-cut.srt" -c:v libx264 -crf 24 -vsync passthrough -c:a copy test.ffmpeg.mp4

The other day i tried handbrakeCLI and it was a lot lot faster on the same file.

I used this HandbrakeCLI command to convert and hardcode, i know its not like for like but you would expect ffmpeg to be faster since its not converting the audio and really only has to convert the video at the frames that need subtitles.

HandBrakeCLI --preset "Very Fast 1080p30" --format av_mp4 -i test-cut.mp4 --srt-file test-cut.srt --srt-burn=1 -o test.handbrake.mp4

Is there a way that i can have ffmpeg just inprint the subs on the video that needs subs. instead of having to convert the whole video.

For example if i have a minute long video and there is 1 sentence that is said at 30 seconds in and that sentence/sub needs to be displayed for 5 seconds to have ffmpeg only convert that 5 seconds segment and just copy the rest of the video and audio to the new output?

The input video is 720p with 24 FPS and the speed difference is usually that handbrake is 2x and ffmpeg is about 0.7x of video duration. I know im using a 1080p profile for handbrake. Both were tested on the same machine and the same video.

Versions ffmpeg version 4.2.2 HandBrake 1.3.1

video info original video

CONTAINER......: MPEG-4
SIZE...........: 13.3 MiB
RUNTIME........: 45 s 94 ms
VIDEO CODEC....: avc1, [email protected], 8 bits
RESOLUTION.....: 1280x720
BITRATE........: 2 402 kb/s
FRAMERATE......: 24.000 FPS
AUDIO..........: AAC, 2 channels, 66.2 kb/s

handbrake output

CONTAINER......: MPEG-4
SIZE...........: 2.81 MiB
RUNTIME........: 45 s 51 ms
VIDEO CODEC....: x264, avc1, Main@L4, 8 bits
RESOLUTION.....: 1118x692
BITRATE........: 355 kb/s
FRAMERATE......: 24.000 FPS
AUDIO..........: AAC, 2 channels, 160 kb/s

ffmpeg output

CONTAINER......: MPEG-4
SIZE...........: 3.90 MiB
RUNTIME........: 45 s 94 ms
VIDEO CODEC....: x264, avc1, [email protected], 8 bits
RESOLUTION.....: 1280x720
BITRATE........: 651 kb/s
FRAMERATE......: 23.976 (23976/1000) FPS
AUDIO..........: AAC, 2 channels, 66.2 kb/s

Would be grateful if anyone could provide any suggestions to get ffmpeg faster at hardcoding subs.


Solution

  • For Handbrake, you use the veryfast preset.
    You can also specify a preset with ffmpeg, by default it is set to medium but you can change:
    -preset veryfast