How to hardcode subtitles into an AVI without loss of quality

I am using a program to hardcode subs into an AVI file. The problem is that is recompresses the video using a codec. I don't see why this is necessary and causes a noticeable loss of quality. Is there a program that will put the subs in without having to recompress the video so that there is no loss in video quality?

4 Answers

No. The hardsubs modify the video content and so recompressing it is necessary.

3

I think as it is typically used, hard subtitles mean they are embedded into the image data, which by definition requires re-compression. Soft subtitles are added as separate files, e.g. .srt. However, there is a middle way in embedded subtitles. Embedded subtitles are added into the video container as a separate track, which means they will be included in the file but not require re-compression.

For Divx-format the best tool is Windows based application AVIAddXSubs. It can embed Idx/Sub/Srt subtitles.

For MP4 and some other alternatives, Handbrake can embed soft subtitles. Read more at their wiki

3

You can use mplayer to play the video with subtitles, and then output everything to a raw yuv file (-vo yuv4mpeg). If you play a movie, this outputted file will be really huge, hundreds of gigabytes, so make sure that it will not cause issues.

After the file has been outputted, it can be compressed by using ffmpeg and then H264 codec.

1

The recompression is necessary because you alter the frame data if you overlay text on the frame itself. So the workflow goes Decompress frame > Modify it to add text > recompress frame.

You can use a lossless codec for the file with the subtitles added. One would be huffyuv, h.264 and Dirac also seem to have lossless profiles. (This will result in identical quality to the original file, with a much larger filesize)

Theoretically, it might be possible to write an application that only re-encode the blocks that are changed by the subtitles, but this likely needs to embedded deep into codec code... That should allow limiting the areas of which quality is affected... I'm not aware of anything like that that exists though... (It would also need to be written specifically for each codec, while altering a decompressed frame allows existing encoder and decoder libraries to be used, as well as recompressing in a different format)

Ideally, you should use lossless compressed files until editing is finished and the export the final file with the preferred compression. This only works for videos that you produce however.

Another option, that might be acceptable, is to add the subtitles as an additional data stream (this will allow them to be turned off though). MPEG-4 Timed text is one such subtitle format, Ogg Writ is another. (But neither of them seem to support an AVI container) (With these, the subtitles is just another track, like the audio and video that is rendered when the file is played)

It might also work tto recompress using a better codec (likely Dirac, H.264 or H.265, depending on input format) to attempt to limit the loss of quality without a huge increase in file size.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like