Re: [MPlayer-users] [feature request] subtitles in separate window or console

Nicolas George <[email protected]> Mon, 28 Feb 2022 20:27:43 +0100
Newsgroups gmane.comp.video.mplayer.devel,gmane.comp.video.mplayer.user
Message-ID <[email protected]>
Nicolas George (12022-02-28):
> Now that I have updated my work tree, I will try to look at it soon.

Please see the attached patch.

This is far from perfect, but it works.

With OSD, the markup is lost.

With ASS, there is no way to get the text back from libass, I put the
number of images, at least it tells us if there are 0 some.

In both case, it prints the timestamp and the delay.

Ingo: since it is designed for -identify output, it makes sense to use
that level of logging.

It would be useful to have feedback from suprnerd, but they seems to
have lost interest in the discussion.

Regards,

-- 
  Nicolas George

_______________________________________________
MPlayer-dev-eng mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/mplayer-dev-eng
0001-Send-subtitles-information-to-identify.patch (text/x-diff, 5.9 KB)
From b3c80c98f266f3605c0c5f2779c00a9e593c9bd2 Mon Sep 17 00:00:00 2001
From: Nicolas George <[email protected]>
Date: Mon, 28 Feb 2022 20:20:19 +0100
Subject: [PATCH] Send subtitles information to identify

---
 mencoder.c      |  2 +-
 mpcommon.c      |  8 ++++----
 mpcommon.h      |  2 +-
 mplayer.c       | 10 +++++++++-
 sub/ass_mp.c    |  5 +++++
 sub/find_sub.c  |  4 ++--
 sub/subreader.h |  2 +-
 7 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/mencoder.c b/mencoder.c
index 9b7a880f7..af828723c 100644
--- a/mencoder.c
+++ b/mencoder.c
@@ -215,7 +215,7 @@ void mplayer_put_key(int code)
 char *current_module;
 
 // Needed by mpcommon.c
-void set_osd_subtitle(subtitle *subs) {
+void set_osd_subtitle(subtitle *subs, double ts) {
     vo_sub = subs;
     vo_osd_changed(OSDTYPE_SUBTITLE);
 }
diff --git a/mpcommon.c b/mpcommon.c
index 5866d1179..cf51e5238 100644
--- a/mpcommon.c
+++ b/mpcommon.c
@@ -183,7 +183,7 @@ void update_subtitles(sh_video_t *sh_video, double refpts, demux_stream_t *d_dvd
     if (reset) {
         sub_clear_text(&subs, MP_NOPTS_VALUE);
         if (vo_sub) {
-            set_osd_subtitle(NULL);
+            set_osd_subtitle(NULL, curpts);
         }
         if (vo_spudec) {
             spudec_reset(vo_spudec);
@@ -200,7 +200,7 @@ void update_subtitles(sh_video_t *sh_video, double refpts, demux_stream_t *d_dvd
         if (sub_fps==0) sub_fps = sh_video ? sh_video->fps : 25;
         current_module = "find_sub";
         if (refpts > sub_last_pts || refpts < sub_last_pts-1.0) {
-            find_sub(subdata, curpts *
+            find_sub(subdata, curpts, curpts *
                      (subdata->sub_uses_time ? 100. : sub_fps));
             if (vo_sub) vo_sub_last = vo_sub;
             // FIXME! frame counter...
@@ -358,13 +358,13 @@ void update_subtitles(sh_video_t *sh_video, double refpts, demux_stream_t *d_dvd
                 }
                 if (endpts == MP_NOPTS_VALUE) endpts = subpts + 4;
                 sub_add_text(&subs, packet, len, endpts, 1);
-                set_osd_subtitle(&subs);
+                set_osd_subtitle(&subs, curpts);
             }
             if (d_dvdsub->non_interleaved)
                 ds_get_next_pts(d_dvdsub);
         }
         if (sub_clear_text(&subs, curpts))
-            set_osd_subtitle(&subs);
+            set_osd_subtitle(&subs, curpts);
     }
     if (vo_spudec) {
         spudec_heartbeat(vo_spudec, 90000*curpts);
diff --git a/mpcommon.h b/mpcommon.h
index bf1739af0..8e3abcb83 100644
--- a/mpcommon.h
+++ b/mpcommon.h
@@ -76,7 +76,7 @@ void update_subtitles(struct sh_video *sh_video, double refpts, demux_stream_t *
 void update_teletext(struct sh_video *sh_video, demuxer_t *demuxer, int reset);
 int select_audio(demuxer_t* demuxer, int audio_id, char* audio_lang);
 int select_video(demuxer_t* demuxer, int video_id);
-void set_osd_subtitle(subtitle *subs);
+void set_osd_subtitle(subtitle *subs, double ts);
 
 int cfg_inc_verbose(m_option_t *conf);
 int cfg_include(m_option_t *conf, const char *filename);
diff --git a/mplayer.c b/mplayer.c
index ee0063e63..fa6460bfc 100644
--- a/mplayer.c
+++ b/mplayer.c
@@ -1521,7 +1521,7 @@ void set_osd_bar(int type, const char *name, double min, double max, double val)
 /**
  * @brief Display text subtitles on the OSD.
  */
-void set_osd_subtitle(subtitle *subs)
+void set_osd_subtitle(subtitle *subs, double ts)
 {
     int i;
     vo_sub = subs;
@@ -1538,6 +1538,14 @@ void set_osd_subtitle(subtitle *subs)
             }
         }
     }
+    if (mp_msg_test(MSGT_IDENTIFY, MSGL_V)) {
+        mp_msg(MSGT_IDENTIFY, MSGL_V, "ID_SUB_TS=%f\n", ts);
+        mp_msg(MSGT_IDENTIFY, MSGL_V, "ID_SUB_DELAY=%f\n", sub_delay);
+        for (i = 0; i < SUB_MAX_TEXT; i++) {
+            const char *txt = !subs || i >= subs->lines || !subs->text[i] ? "" : subs->text[i];
+            mp_msg(MSGT_IDENTIFY, MSGL_V, "ID_SUB_TEXT_%i=%s\n", i, txt);
+        }
+    }
 }
 
 /**
diff --git a/sub/ass_mp.c b/sub/ass_mp.c
index 61ceb3c00..c997d3f71 100644
--- a/sub/ass_mp.c
+++ b/sub/ass_mp.c
@@ -350,6 +350,7 @@ static void eosd_ass_update(struct mp_eosd_source *src, const struct mp_eosd_set
 	if (!aimg != !src->images)
 		src->changed = 2;
 	if (src->changed) {
+		unsigned n = 0;
 		eosd_image_remove_all(src);
 		while (aimg) {
 			img = eosd_image_alloc();
@@ -362,7 +363,11 @@ static void eosd_ass_update(struct mp_eosd_source *src, const struct mp_eosd_set
 			img->dst_y  = aimg->dst_y;
 			eosd_image_append(src, img);
 			aimg = aimg->next;
+			n++;
 		}
+		mp_msg(MSGT_IDENTIFY, MSGL_V, "ID_SUB_TS=%f\n", ts);
+		mp_msg(MSGT_IDENTIFY, MSGL_V, "ID_SUB_DELAY=%f\n", sub_delay);
+		mp_msg(MSGT_IDENTIFY, MSGL_V, "ID_SUB_TEXT_NB_IMAGES=%d\n", n);
 	}
 	prev_visibility = sub_visibility;
 }
diff --git a/sub/find_sub.c b/sub/find_sub.c
index 37b2f927b..c42f8ecf1 100644
--- a/sub/find_sub.c
+++ b/sub/find_sub.c
@@ -67,7 +67,7 @@ void step_sub(sub_data *subd, float pts, int movement) {
     sub_delay = pts - subs[current_sub].start / (subd->sub_uses_time ? 100 : sub_fps);
 }
 
-void find_sub(sub_data* subd,int key){
+void find_sub(sub_data* subd, float curpts, int key){
     subtitle *subs;
     subtitle *new_sub = NULL;
     int i,j;
@@ -172,5 +172,5 @@ void find_sub(sub_data* subd,int key){
 
     new_sub=NULL; // no sub here
 update:
-    set_osd_subtitle(new_sub);
+    set_osd_subtitle(new_sub, curpts);
 }
diff --git a/sub/subreader.h b/sub/subreader.h
index d499ad830..c492329b9 100644
--- a/sub/subreader.h
+++ b/sub/subreader.h
@@ -110,7 +110,7 @@ void dump_microdvd(sub_data* subd, float fps);
 void dump_jacosub(sub_data* subd, float fps);
 void dump_sami(sub_data* subd, float fps);
 void sub_free( sub_data * subd );
-void find_sub(sub_data* subd,int key);
+void find_sub(sub_data* subd, float pts, int key);
 void step_sub(sub_data *subd, float pts, int movement);
 void sub_add_text(subtitle *sub, const char *txt, int len, double endpts, int strip_markup);
 int sub_clear_text(subtitle *sub, double pts);
-- 
2.34.1
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEE6ooRQGBoNzw0KnwPcZVLI8pNxgwFAmIdIi0ACgkQcZVLI8pN
xgz1HQ/+PyHFCCyFIvJFCeTJxDDlUlhemgwA5p8rPKbWrISt8/J+ZdbgzfP8o3PQ
7tkS/3dblaroFoeghdxn2DjK5lwdyc2GHpXDrsCzwHPaZgI4ZDHQC4rQzC3WRGA+
gyidmcaZYcSRdlqAo1hmtgZxlSFEMiawAtPnqIfIHfTo9LoRWxHs+geWTbHfvmfV
W+xK9wDKGC85qQxm0a9u+U28FO0G+eaUabDRh+/oYclU33Zho5tf7sm1UgWCWp9R
qXbEkuo4UMDX23Tvd3lldOpmnsg0lalIYC2+TU+1jqO/PC0SkRnc780IL5B2/8/+
VyIn8+F/c4uoDM6F5HVqPH0rCo+yum6NbWy6kXymi4Rpsdomm0tZczUiJhMOHXmv
BBurPBzKUZmMSCb/Xsot8uGdPJzFzJUFJJkUWY7dAeJrpTYBnTlThYlhnT4Yl5fR
gxBOUhrV8sLtH5zt+ZNY2Xo1ETmbLoQxZNdrzFZVK6/gGOSpVowCXD1DgSmJ0j9N
nlPnZFxmbmAw/jn4CfBQUp3qrmaVVleeTzJLUV+PfYpfqor/Vn4BQ8OlFsmuTikU
ZSBWAAhHSpjhuKty5YIQad15pTXr4PFMl5hUST1BOg5M6FMdi/Gwp+/9z3x2gBx4
ezRjy0cuaMLbauTR7R2uIDLyUgvbXhE36u00wKfmtO5ohH7FVJE=
=IIGk
-----END PGP SIGNATURE-----