@@ -67,9 +67,13 @@ void buffer_free(buffer_t *buf) {
6767void msg_callback (int level, const char *fmt, va_list va, void *data) {
6868 if (level > log_level) // 6 for verbose
6969 return ;
70- printf (" libass: " );
71- vprintf (fmt, va);
72- printf (" \n " );
70+
71+ const int ERR_LEVEL = 1 ;
72+ FILE* stream = level <= ERR_LEVEL ? stderr : stdout;
73+
74+ fprintf (stream, " libass: " );
75+ vfprintf (stream, fmt, va);
76+ fprintf (stream, " \n " );
7377}
7478
7579const float MIN_UINT8_CAST = 0.9 / 255 ;
@@ -112,15 +116,15 @@ class SubtitleOctopus {
112116 void initLibrary (int frame_w, int frame_h) {
113117 ass_library = ass_library_init ();
114118 if (!ass_library) {
115- printf ( " ass_library_init failed!\n " );
119+ fprintf (stderr, " ass_library_init failed!\n " );
116120 exit (2 );
117121 }
118122
119123 ass_set_message_cb (ass_library, msg_callback, NULL );
120124
121125 ass_renderer = ass_renderer_init (ass_library);
122126 if (!ass_renderer) {
123- printf ( " ass_renderer_init failed!\n " );
127+ fprintf (stderr, " ass_renderer_init failed!\n " );
124128 exit (3 );
125129 }
126130
@@ -135,7 +139,7 @@ class SubtitleOctopus {
135139 removeTrack ();
136140 track = ass_read_file (ass_library, subfile, NULL );
137141 if (!track) {
138- printf ( " Failed to start a track\n " );
142+ fprintf (stderr, " Failed to start a track\n " );
139143 exit (4 );
140144 }
141145 }
@@ -144,7 +148,7 @@ class SubtitleOctopus {
144148 removeTrack ();
145149 track = ass_read_memory (ass_library, buf, (size_t )bufsize, NULL );
146150 if (!track) {
147- printf ( " Failed to start a track\n " );
151+ fprintf (stderr, " Failed to start a track\n " );
148152 exit (4 );
149153 }
150154 }
@@ -266,7 +270,7 @@ class SubtitleOctopus {
266270 // make float buffer for blending
267271 float * buf = (float *)buffer_resize (&m_blend, sizeof (float ) * width * height * 4 , 0 );
268272 if (buf == NULL ) {
269- printf ( " libass: error : cannot allocate buffer for blending\n " );
273+ fprintf (stderr, " libass: cannot allocate buffer for blending\n " );
270274 return &m_blendResult;
271275 }
272276 memset (buf, 0 , sizeof (float ) * width * height * 4 );
0 commit comments