mirror of
https://github.com/mpv-player/mpv
synced 2025-03-21 10:51:51 +00:00
Add support for loading ASS subtitles through the stream layer and thus e.g.
from some network location. Patch by Yuriy Kaminskiy [yumkam mail ru] git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@30515 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
c5b0ff1cfa
commit
fc50523f80
@ -1713,7 +1713,7 @@ static const char help_text[]=
|
||||
#define MSGTR_LIBASS_ErrorRecodingFile "[ass] chyba překódování souboru.\n"
|
||||
#define MSGTR_LIBASS_FopenFailed "[ass] ass_read_file(%s): fopen selhalo\n"
|
||||
#define MSGTR_LIBASS_FseekFailed "[ass] ass_read_file(%s): fseek selhalo\n"
|
||||
#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan10M "[ass] ass_read_file(%s): Odmítám nahrát titulky delší než 10M\n"
|
||||
#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan100M "[ass] ass_read_file(%s): Odmítám nahrát titulky delší než 100M\n"
|
||||
#define MSGTR_LIBASS_ReadFailed "Čtení selhalo, %d: %s\n"
|
||||
#define MSGTR_LIBASS_AddedSubtitleFileMemory "[ass] Přidán soubos s titulky: <memory> (%d stylů, %d událostí)\n"
|
||||
#define MSGTR_LIBASS_AddedSubtitleFileFname "[ass] Přidán soubos s titulky: %s (%d stylů, %d událostí)\n"
|
||||
|
@ -2042,7 +2042,7 @@ static const char help_text[]=
|
||||
#define MSGTR_LIBASS_ErrorRecodingFile "[ass] Fehler bei Recodierung der Datei.\n"
|
||||
#define MSGTR_LIBASS_FopenFailed "[ass] ass_read_file(%s): fopen fehlgeschlagen\n"
|
||||
#define MSGTR_LIBASS_FseekFailed "[ass] ass_read_file(%s): fseek fehlgeschlagen\n"
|
||||
#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan10M "[ass] ass_read_file(%s): Laden von Untertiteln größer als 10M verweigert.\n"
|
||||
#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan100M "[ass] ass_read_file(%s): Laden von Untertiteln größer als 100M verweigert.\n"
|
||||
#define MSGTR_LIBASS_ReadFailed "Lesen fehlgeschlagen, %d: %s\n"
|
||||
#define MSGTR_LIBASS_AddedSubtitleFileMemory "[ass] Hinzugefügte Untertiteldatei: <Speicher> (%d Styles, %d Ereignisse)\n"
|
||||
#define MSGTR_LIBASS_AddedSubtitleFileFname "[ass] Hinzugefügte Untertiteldatei: %s (%d Styles, %d Ereignisse)\n"
|
||||
|
@ -1719,7 +1719,7 @@ static const char help_text[]=
|
||||
#define MSGTR_LIBASS_ErrorRecodingFile "[ass] error recoding file.\n"
|
||||
#define MSGTR_LIBASS_FopenFailed "[ass] ass_read_file(%s): fopen failed\n"
|
||||
#define MSGTR_LIBASS_FseekFailed "[ass] ass_read_file(%s): fseek failed\n"
|
||||
#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan10M "[ass] ass_read_file(%s): Refusing to load subtitles larger than 10M\n"
|
||||
#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan100M "[ass] ass_read_file(%s): Refusing to load subtitles larger than 100M\n"
|
||||
#define MSGTR_LIBASS_ReadFailed "Read failed, %d: %s\n"
|
||||
#define MSGTR_LIBASS_AddedSubtitleFileMemory "[ass] Added subtitle file: <memory> (%d styles, %d events)\n"
|
||||
#define MSGTR_LIBASS_AddedSubtitleFileFname "[ass] Added subtitle file: %s (%d styles, %d events)\n"
|
||||
|
@ -2080,7 +2080,7 @@ static const char help_text[]=
|
||||
#define MSGTR_LIBASS_ErrorRecodingFile "[ass] error recodificando el fichero.\n"
|
||||
#define MSGTR_LIBASS_FopenFailed "[ass] ass_read_file(%s): fopen ha fallado\n"
|
||||
#define MSGTR_LIBASS_FseekFailed "[ass] ass_read_file(%s): fseek ha fallado\n"
|
||||
#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan10M "[ass] ass_read_file(%s): No se pueden cargar ficheros de subtítulos mayores de 10M\n"
|
||||
#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan100M "[ass] ass_read_file(%s): No se pueden cargar ficheros de subtítulos mayores de 100M\n"
|
||||
#define MSGTR_LIBASS_ReadFailed "La lectura ha fallado, %d: %s\n"
|
||||
#define MSGTR_LIBASS_AddedSubtitleFileMemory "[ass] Añadido fichero de subtítulos: <memoria> (%d estilos, %d eventos)\n"
|
||||
#define MSGTR_LIBASS_AddedSubtitleFileFname "[ass] Añadido fichero de subtítulos: %s (%d estilos, %d eventos)\n"
|
||||
|
@ -2008,7 +2008,7 @@ static const char help_text[]=
|
||||
#define MSGTR_LIBASS_ErrorRecodingFile "[ass] erreur lors de l'enregistrement du fichier.\n"
|
||||
#define MSGTR_LIBASS_FopenFailed "[ass] ass_read_file(%s) : fopen a échoué\n"
|
||||
#define MSGTR_LIBASS_FseekFailed "[ass] ass_read_file(%s) : fseek à échoué\n"
|
||||
#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan10M "[ass] ass_read_file(%s) : Chargement des fichiers plus grands que 10Mo refusé\n"
|
||||
#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan100M "[ass] ass_read_file(%s) : Chargement des fichiers plus grands que 100Mo refusé\n"
|
||||
#define MSGTR_LIBASS_ReadFailed "Lecture impossible, %d: %s\n"
|
||||
#define MSGTR_LIBASS_AddedSubtitleFileMemory "[ass] Ajout d'un fichier de sous-titres : <memory> (%d styles, %d évènements)\n"
|
||||
#define MSGTR_LIBASS_AddedSubtitleFileFname "[ass] Ajout d'un fichier de sous-titres : %s (%d styles, %d events)\n"
|
||||
|
@ -1718,7 +1718,7 @@ static const char help_text[]=
|
||||
#define MSGTR_LIBASS_ErrorRecodingFile "[ass] hiba a fájl rögzítésekor.\n"
|
||||
#define MSGTR_LIBASS_FopenFailed "[ass] ass_read_file(%s): fopen sikertelen\n"
|
||||
#define MSGTR_LIBASS_FseekFailed "[ass] ass_read_file(%s): fseek sikertelen\n"
|
||||
#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan10M "[ass] ass_read_file(%s): 10M-nél nagyobb felirat fájl betöltése visszautasítva\n"
|
||||
#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan100M "[ass] ass_read_file(%s): 100M-nél nagyobb felirat fájl betöltése visszautasítva\n"
|
||||
#define MSGTR_LIBASS_ReadFailed "Olvasás sikertelen, %d: %s\n"
|
||||
#define MSGTR_LIBASS_AddedSubtitleFileMemory "[ass] Felirat fájl hozzáadása: <memória> (%d stílus, %d esemény)\n"
|
||||
#define MSGTR_LIBASS_AddedSubtitleFileFname "[ass] Felirat fájl hozzáadása: %s (%d stílus, %d esemény)\n"
|
||||
|
@ -1713,7 +1713,7 @@ static const char help_text[]=
|
||||
#define MSGTR_LIBASS_ErrorRecodingFile "[ass] errore ricodificando il file.\n"
|
||||
#define MSGTR_LIBASS_FopenFailed "[ass] ass_read_file(%s): fopen fallita\n"
|
||||
#define MSGTR_LIBASS_FseekFailed "[ass] ass_read_file(%s): fseek fallita\n"
|
||||
#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan10M "[ass] ass_read_file(%s): Mi rifiuto di caricare sottotitoli più grandi di 10M\n"
|
||||
#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan100M "[ass] ass_read_file(%s): Mi rifiuto di caricare sottotitoli più grandi di 100M\n"
|
||||
#define MSGTR_LIBASS_ReadFailed "Lettura fallita, %d: %s\n"
|
||||
#define MSGTR_LIBASS_AddedSubtitleFileMemory "[ass] Aggiunto file sottotitoli: <memoria> (%d stili, %d eventi)\n"
|
||||
#define MSGTR_LIBASS_AddedSubtitleFileFname "[ass] Added subtitle file: %s (%d stili, %d eventi)\n"
|
||||
|
@ -1753,7 +1753,7 @@ static const char help_text[]=
|
||||
#define MSGTR_LIBASS_ErrorRecodingFile "[ass] ошибка записи файла.\n"
|
||||
#define MSGTR_LIBASS_FopenFailed "[ass] ass_read_file(%s): сбой fopen\n"
|
||||
#define MSGTR_LIBASS_FseekFailed "[ass] ass_read_file(%s): сбой fseek\n"
|
||||
#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan10M "[ass] ass_read_file(%s): Отклонение загрузки субтитров больше 10M\n"
|
||||
#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan100M "[ass] ass_read_file(%s): Отклонение загрузки субтитров больше 100M\n"
|
||||
#define MSGTR_LIBASS_ReadFailed "Ошибка чтения, %d: %s\n"
|
||||
#define MSGTR_LIBASS_AddedSubtitleFileMemory "[ass] Добавлен файл субтитров: <память> (стилей: %d, событий: %d)\n"
|
||||
#define MSGTR_LIBASS_AddedSubtitleFileFname "[ass] Добавлен файл субтитров: %s (стилей: %d, событий: %d)\n"
|
||||
|
@ -2017,7 +2017,7 @@ static const char help_text[]=
|
||||
#define MSGTR_LIBASS_ErrorRecodingFile "[ass] Dosyayı tekrar kodlamada hata.\n"
|
||||
#define MSGTR_LIBASS_FopenFailed "[ass] ass_read_file(%s): fopen başarısız\n"
|
||||
#define MSGTR_LIBASS_FseekFailed "[ass] ass_read_file(%s): fseek başarısız\n"
|
||||
#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan10M "[ass] ass_read_file(%s): 10 megabayttan büyük altyazıları yüklemeyi reddediyor\n"
|
||||
#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan100M "[ass] ass_read_file(%s): 100 megabayttan büyük altyazıları yüklemeyi reddediyor\n"
|
||||
#define MSGTR_LIBASS_ReadFailed "Okuma başarısız, %d: %s\n"
|
||||
#define MSGTR_LIBASS_AddedSubtitleFileMemory "[ass] Altyazı dosyasını ekledi: <bellek> (%d tarz, %d olay)\n"
|
||||
#define MSGTR_LIBASS_AddedSubtitleFileFname "[ass] Altyazı dosyasını ekledi: %s (%d tarz, %d olay)\n"
|
||||
|
@ -1701,7 +1701,7 @@ static const char help_text[]=
|
||||
#define MSGTR_LIBASS_ErrorRecodingFile "[ass] 记录到文件出错。\n"
|
||||
#define MSGTR_LIBASS_FopenFailed "[ass] ass_read_file(%s): 文件打开(fopen)失败\n"
|
||||
#define MSGTR_LIBASS_FseekFailed "[ass] ass_read_file(%s): 文件定位(fseek)失败\n"
|
||||
#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan10M "[ass] ass_read_file(%s): 拒绝装入大于10M的字幕\n"
|
||||
#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan100M "[ass] ass_read_file(%s): 拒绝装入大于100M的字幕\n"
|
||||
#define MSGTR_LIBASS_ReadFailed "读失败, %d: %s\n"
|
||||
#define MSGTR_LIBASS_AddedSubtitleFileMemory "[ass] 已加入字幕文件: <内存> (%d styles, %d events)\n"
|
||||
#define MSGTR_LIBASS_AddedSubtitleFileFname "[ass] 已加入字幕文件: %s (%d styles, %d events)\n"
|
||||
|
@ -1968,7 +1968,7 @@ static const char help_text[]=
|
||||
#define MSGTR_LIBASS_ErrorRecodingFile "[ass] 記録到文件出錯。\n"
|
||||
#define MSGTR_LIBASS_FopenFailed "[ass] ass_read_file(%s): 文件打開(fopen)失敗\n"
|
||||
#define MSGTR_LIBASS_FseekFailed "[ass] ass_read_file(%s): 文件定位(fseek)失敗\n"
|
||||
#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan10M "[ass] ass_read_file(%s): 拒絶裝入大于10M的字幕\n"
|
||||
#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan100M "[ass] ass_read_file(%s): 拒絶裝入大于100M的字幕\n"
|
||||
#define MSGTR_LIBASS_ReadFailed "讀失敗, %d: %s\n"
|
||||
#define MSGTR_LIBASS_AddedSubtitleFileMemory "[ass] 已加入字幕文件: <内存> (%d styles, %d events)\n"
|
||||
#define MSGTR_LIBASS_AddedSubtitleFileFname "[ass] 已加入字幕文件: %s (%d styles, %d events)\n"
|
||||
|
@ -28,6 +28,8 @@
|
||||
#include "get_path.h"
|
||||
|
||||
#include "ass_mp.h"
|
||||
#include "help_mp.h"
|
||||
#include "stream/stream.h"
|
||||
|
||||
#ifdef CONFIG_FONTCONFIG
|
||||
#include <fontconfig/fontconfig.h>
|
||||
@ -216,6 +218,51 @@ ass_track_t* ass_read_subdata(ass_library_t* library, sub_data* subdata, double
|
||||
return track;
|
||||
}
|
||||
|
||||
ass_track_t* ass_read_stream(ass_library_t* library, char *fname, char *charset) {
|
||||
int i;
|
||||
char *buf = NULL;
|
||||
ass_track_t *track;
|
||||
size_t sz = 0;
|
||||
size_t buf_alloc = 0;
|
||||
stream_t *fd;
|
||||
|
||||
fd = open_stream(fname, NULL, &i);
|
||||
if (!fd) {
|
||||
mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_FopenFailed, fname);
|
||||
return NULL;
|
||||
}
|
||||
if (fd->end_pos > STREAM_BUFFER_SIZE)
|
||||
/* read entire file if size is known */
|
||||
buf_alloc = fd->end_pos;
|
||||
for (;;) {
|
||||
if (buf_alloc >= 100*1024*1024) {
|
||||
mp_msg(MSGT_ASS, MSGL_INFO, MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan100M, fname);
|
||||
sz = 0;
|
||||
break;
|
||||
}
|
||||
if (buf_alloc < sz + STREAM_BUFFER_SIZE)
|
||||
buf_alloc += STREAM_BUFFER_SIZE;
|
||||
buf = realloc(buf, buf_alloc + 1);
|
||||
i = stream_read(fd, buf + sz, buf_alloc - sz);
|
||||
if (i <= 0) break;
|
||||
sz += i;
|
||||
}
|
||||
free_stream(fd);
|
||||
if (!sz) {
|
||||
free(buf);
|
||||
return NULL;
|
||||
}
|
||||
buf[sz] = 0;
|
||||
buf = realloc(buf, sz + 1);
|
||||
track = ass_read_memory(library, buf, sz, charset);
|
||||
if (track) {
|
||||
free(track->name);
|
||||
track->name = strdup(fname);
|
||||
}
|
||||
free(buf);
|
||||
return track;
|
||||
}
|
||||
|
||||
void ass_configure(ass_renderer_t* priv, int w, int h, int unscaled) {
|
||||
int hinting;
|
||||
ass_set_frame_size(priv, w, h);
|
||||
|
@ -59,6 +59,7 @@ extern int ass_hinting;
|
||||
ass_track_t* ass_default_track(ass_library_t* library);
|
||||
int ass_process_subtitle(ass_track_t* track, subtitle* sub);
|
||||
ass_track_t* ass_read_subdata(ass_library_t* library, sub_data* subdata, double fps);
|
||||
ass_track_t* ass_read_stream(ass_library_t* library, char *fname, char *charset);
|
||||
|
||||
void ass_configure(ass_renderer_t* priv, int w, int h, int hinting);
|
||||
void ass_configure_fonts(ass_renderer_t* priv);
|
||||
|
@ -1082,9 +1082,9 @@ void add_subtitles(char *filename, float fps, int noerr)
|
||||
#ifdef CONFIG_ASS
|
||||
if (ass_enabled)
|
||||
#ifdef CONFIG_ICONV
|
||||
asst = ass_read_file(ass_library, filename, sub_cp);
|
||||
asst = ass_read_stream(ass_library, filename, sub_cp);
|
||||
#else
|
||||
asst = ass_read_file(ass_library, filename, 0);
|
||||
asst = ass_read_stream(ass_library, filename, 0);
|
||||
#endif
|
||||
if (ass_enabled && subd && !asst)
|
||||
asst = ass_read_subdata(ass_library, subd, fps);
|
||||
|
Loading…
Reference in New Issue
Block a user