CRIWARE Unity Plugin Manual  Last Updated: 2024-07-12
Subtitled movie
Movies with subtitles can be used in Sofdec.
Subtitle data can be embedded into a movie file and read at runtime.

Creating subtitled movies

Movie data with subtitles can be created by specifying a subtitle file when encoding with the Sofdec2 Encoding Wizard.

  • On the "Specify Input Subtitle Material" page, specify the subtitle data file.
  • Subtitles can be registered to one of the subtitle channels (0 to 15), and up to 16 sets of subtitles can be embedded to the file.
  • The character code of the embedded subtitle follows that of the specified subtitle data file.
    For details, refer to the Sofdec Tool user's manual.

Acquisition of subtitle data

By acquiring subtitle data during playback, it is possible to display subtitles synchronized with the video.
The following processing is required to use subtitle data.

  • Specify the channel of subtitle data to be acquired
  • Get the character string from the pointer of the subtitle data
Specify the channel of subtitle data to be acquired
Use CriMana.Player.SetSubtitleChannel(int) to specify the subtitle channel.
Subtitles can not be acquired if the channel is not specified.
/* Get CriMana.Player at initialization and specify channel */
player = GetComponent<CriManaMovieMaterial>().player;
player.SetSubtitleChannel(0);
Get the character string from the pointer of the subtitle data
Get the string from CriMana.Player.subtitleBuffer.
When acquiring the subtitle data, it is necessary to convert it to a string using the character code of the subtitle file specified in the Sofdec tool.
Attention
The string that is pointed to may not end with a null terminator. Always use the APIs to specify the buffer sizes with pointers.
  • For UTF-8 or ASCII
The data can be converted to System.String using System.Runtime.InteropServices.Marshal.PtrToStringAnsi .
/* Get subtitles */
IntPtr buffer = player.subtitleBuffer;
string subtitle = Marshal.PtrToStringAnsi(buffer, player.subtitleSize);
  • For UTF-16
The data can be converted to System.String using System.Runtime.InteropServices.Marshal.PtrToStringUni .
/* Get subtitles */
IntPtr buffer = player.subtitleBuffer;
string subtitle = Marshal.PtrToStringUni(buffer, player.subtitleSize);
  • Other character codes
Subtitle data can be acquired as byte[] and converted to System.String by using the System.Text.Encoding class.
Please refer to the following URL for information about the System.Text.Encoding class.
https://docs.microsoft.com/en-us/dotnet/api/system.text.encoding
IntPtr buffer = player.subtitleBuffer;
/* Create a byte array and copy the contents of the subtitle buffer */
var array = new byte[player.subtitleSize];
Marshal.Copy(buffer, array, 0, player.subtitleSize);
/* Create Shift-JIS Encoding to convert the byte array to string */
var encoding = Encoding.GetEncoding("shift_jis");
string subtitle = encoding.GetString(array);