How can I change the encoding of a subtitle file?
I downloaded a Greek subtitle for a movie, and this is what I see when I open it with Gedit.
Subtitle works great on VLC, all perfect. But what if I want to edit this subtitle with some Greek words? I instantly get an error about character encoding.
I hit retry and then VLC doesn't recognize the subtitles...
For subtitle edition/translation (text-based subtitles, that is), I strongly suggest Gaupol.
sudo apt-get install gaupol
Besides of gaupol
, you can also try Subtitle Editor and Gnome Subtitles.
However, from the screenshots, it is clear that your .srt
file is not encoded in Unicode.
As it turns out, iconv
does change the encoding of the file to UTF-8, but the converted file will still have the same characters you see when opening in Gedit.
The solution I found is this:
- Open Gaupol and go to menu File → Open or click on the button Open.
-
There is a selection menu in the lower part of the open window, titled Character encoding. Click on Other... (last option).
-
Select an appropriate encoding for your file, e.g. Greek ISO-8859-7, and click on the button Accept.
Now open your
.srt
file and make sure all characters are correctly rendered. Otherwise, repeat the above procedure with another encoding. You can run the commandfile -bi yourfile.srt
to determine the correct encoding of your file (although I've read the results are not necessarily exact).- With your subtitle file open in the correct character encoding, now go to the menu File → Save as... and change the character encoding option (again, at the bottom of the window) to UTF-8 and save the file (possibly with a new name, for safety).
This same procedure of adding the codepage will work for Gedit. Yet I leave the instructions for Gaupol since this question is about subtitle files.
Good luck.
iconv -f ISO-8859-7 -t UTF-8 Input_file.srt > Output_file.srt
Open them from Kate editor you can see the proper text, if you still need to open them from Gedit, in other words, permanently change the codification run the above terminal command.
I'd recommend enca
. Unlike gaupol, you can handle not only subtitle-files, but any text file.
-
Install enca:
sudo apt-get install enca
-
To figure out the encoding of the file, see if enca can guess it:
enca <file>
or, if it fails and you know the language of the text file, than run for example
enca -L ru <file>
and see what it gives you. Get the list of supported languages from
man enca
. -
I'd recommend to convert to UTF-8, you can do it by running
enconv -x utf8 <file>
or, again, if
enca
cannot guess the language byenconv -L ru -x utf8 <file>
that should do the trick.