mpv icon indicating copy to clipboard operation
mpv copied to clipboard

Terminal subtitles move upwards when jumping in audio-only media

Open forthrin opened this issue 1 year ago • 10 comments

Important Information

System Version: macOS 14.3 (23D56) Model Identifier: MacBookAir10,1 mpv version: git-2024-02-11-71598ca FFmpeg version: git-2024-02-11-66231e5

Reproduction steps

  1. $ mpv --no-config foo.m4a --sub-file=foo.srt
  2. Press or (repeatedly)

Expected behavior

Subtitles should stay put.

Actual behavior

Subtitles are erroneously moved one line up in the terminal (mpv must be printing a superfluous \033[A)

Log file

N/A (Will supply if not reproducible)

Sample files

N/A (Any audio file and subtitle file should work)

forthrin avatar Feb 14 '24 18:02 forthrin

I'm unable to reproduce (linux if it matters).

Dudemanguy avatar Feb 15 '24 18:02 Dudemanguy

Actually, it climbs regardless of seeking. Using plain "Terminal". Try this. ddd will be displayed one line too far up.

1
00:00:00,000 --> 00:00:01,000
aaa
bbb

2
00:00:01,000 --> 00:00:02,000
ccc

3
00:00:02,000 --> 00:00:03,000
ddd
eee

forthrin avatar Feb 15 '24 19:02 forthrin

Not sure what you mean honestly but I get this which is what I'd expect.

2024-02-15-135239_668x136_scrot

Dudemanguy avatar Feb 15 '24 19:02 Dudemanguy

In step three, notice how ddd overlaps the "Audio" line. This will continue to climb for all similar combinations of lines.

$ mpv a.wav 
 (+) Audio --aid=1 (pcm_s16le 2ch 48000Hz)
aaa
bbb
(Paused)

$ mpv a.wav 
 (+) Audio --aid=1 (pcm_s16le 2ch 48000Hz)
ccc
(Paused)

$ mpv a.wav 
ddd
eee
(Paused)

forthrin avatar Feb 15 '24 20:02 forthrin

In step three, notice how ddd overlaps the "Audio" line.

It doesn't for me. The file I was playing has file tags printed to the terminal so the audio line was not shown in the picture. Here's another screenshot with a different file with no metadata. Also shouldn't the AO line be right above the subs in your terminal output?

2024-02-15-142820_893x213_scrot

Dudemanguy avatar Feb 15 '24 20:02 Dudemanguy

Must mean the position has already been displaced from the start. Let's see if someone else with macOS can reproduce.

forthrin avatar Feb 15 '24 20:02 forthrin

i can reproduce this. also seeking backwards a few times.

Akemi avatar Feb 15 '24 22:02 Akemi

@kasper93: Maybe this refactoring needs a re-refactoring. Some observations when the problem occurs:

  1. ANSI codes first go up, then down ("two steps forward, one step back"). Seems unnecessary (unless for clearing lines).
  2. ANSI codes get negative arguments from the prevailing arithmetic. I find no mention of this in any documentation.
  • https://bjh21.me.uk/all-escapes/all-escapes.txt
  • https://en.wikipedia.org/wiki/ANSI_escape_code
  • https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797
  • https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
  • https://real-world-systems.com/docs/ANSIcode.html
  • https://ttssh2.osdn.jp/manual/en/about/ctrlseq.html
  • https://web.mit.edu/gnu/doc/html/screen_10.html
  • https://www.xfree86.org/current/ctlseqs.html#VT100%20Mode

forthrin avatar Feb 16 '24 05:02 forthrin

ANSI codes first go up, then down ("two steps forward, one step back"). Seems unnecessary (unless for clearing lines).

Repositioning cursor is free, but also it never jump back and forth. Read again.

ANSI codes get negative arguments from the prevailing arithmetic. I find no mention of this in any documentation.

line_skip, shouldn't be negative there.

Quickly looking, just a check is missing. Not tested.

diff --git a/common/msg.c b/common/msg.c
index 729fafa572..f675f6377d 100644
--- a/common/msg.c
+++ b/common/msg.c
@@ -224,7 +224,7 @@ static void prepare_prefix(struct mp_log_root *root, bstr *out, int lev, int ter
         // Reposition cursor after last message
         line_skip = (new_lines ? new_lines : root->blank_lines) - root->status_lines;
         line_skip = MPMIN(root->blank_lines - root->status_lines, line_skip);
-        if (line_skip)
+        if (line_skip > 0)
             bstr_xappend_asprintf(root, out, "\033[%dA", line_skip);
     } else if (new_lines) {
         line_skip = new_lines - root->blank_lines;

kasper93 avatar Feb 16 '24 13:02 kasper93

Seems to work just great. I added some plain text to the print statements, and they showed both [A and [B being printed after each other in the same go. But this doesn't seem to happen with the patch, so probably just a side effect.

I did notice though that A: -00:00:00.000 is printed for one frame. But that's another bug report, I guess.

forthrin avatar Feb 16 '24 14:02 forthrin