Opened 7 years ago

Last modified 6 years ago

#6947 new defect

Unwanted visual formatting added when embedding subtitles

Reported by: forthrin Owned by:
Priority: normal Component: undetermined
Version: unspecified Keywords: mov_text
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

When playing an MP4 file with embedded subtitles in VLC, the subtitles are shown as specified by the user in VLC's subtitle preferences, but *not* "Font colour" and "Opacity".

After discussing this with the VLC team, it may seem like FFmpeg secretly applies font colour and opacity when embedding the subtitles.

$ cat a.srt
1
00:00:00,000 --> 00:10:00,000
The quick brown fox jumps
over the lazy dog.

$ ffmpeg -i a.mp4 -i a.srt -vcodec copy -scodec mov_text b.mp4
$ ffmpeg -i b.mp4 b.srt

$ cat b.srt
1
00:00:00,000 --> 00:09:56,459
<font face="Serif" size="18">The quick brown fox jumps
over the lazy dog.</font>

According to this, FFmpeg applies "Font face" and "Font size", but not "Font colour" and "Opacity". Strange...

Anyway, unless the tx3g/mov_text format *requires* visual formatting, it seems most correct that a plain text subtitle is embedded *as-is*, eg. without any applied formatting, leaving all formatting to the video player.

Please give insight how the subtitle embedding works, and how to embed subtitles without visual formatting.

ffmpeg 3.4.1 (macOS/Homebrew)

Change History (9)

comment:1 by Carl Eugen Hoyos, 7 years ago

Is the issue not reproducible with current FFmpeg git head?

comment:2 by forthrin, 7 years ago

The exact same thing happens with this version.

git clone git://source.ffmpeg.org/ffmpeg
./configure
make
./ffmpeg
ffmpeg version N-89763-gd38a223943 Copyright (c) 2000-2018 the FFmpeg developers
  built with Apple LLVM version 9.0.0 (clang-900.0.39.2)
./ffmpeg -i a.mp4 -i a.srt -vcodec copy -scodec mov_text b.mp4
./ffmpeg -i b.mp4 b.srt
cat b.srt
1
00:00:00,000 --> 00:09:56,459
<font face="Serif" size="18">The quick brown fox jumps
over the lazy dog.</font>

comment:3 by Carl Eugen Hoyos, 6 years ago

Keywords: mov_text added

Instead of providing information how to download FFmpeg (yes, most developers know how to do it), please test current FFmpeg git head and provide the command line you tested including the complete, uncut console output.

comment:4 by forthrin, 6 years ago

The exact same problem persists with Git head:

~$ cat a.srt
1
00:00:00,000 --> 00:10:00,000
The quick brown fox jumps
over the lazy dog.

~$ ffmpeg -i a.mp4 -i a.srt -vcodec copy -scodec mov_text b.mp4
ffmpeg version git-2019-01-12-1ea5529 Copyright (c) 2000-2019 the FFmpeg developers
  built with Apple LLVM version 9.0.0 (clang-900.0.39.2)
  configuration: --enable-libx264 --enable-gpl
  libavutil      56. 25.100 / 56. 25.100
  libavcodec     58. 43.101 / 58. 43.101
  libavformat    58. 25.100 / 58. 25.100
  libavdevice    58.  6.101 / 58.  6.101
  libavfilter     7. 48.100 /  7. 48.100
  libswscale      5.  4.100 /  5.  4.100
  libswresample   3.  4.100 /  3.  4.100
  libpostproc    55.  4.100 / 55.  4.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'a.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.12.100
  Duration: 00:00:10.09, start: 0.000000, bitrate: 2549 kb/s
    Chapter #0:0: start 0.000000, end 10.000000
    Metadata:
      title           : 
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 906 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 47.95 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: dts (DTS-HD MA) (mp4a / 0x6134706D), 48000 Hz, stereo, s16p (default)
    Metadata:
      handler_name    : SoundHandler
    Stream #0:2(eng): Data: bin_data (text / 0x74786574), 0 kb/s
    Metadata:
      handler_name    : SubtitleHandler
Input #1, srt, from 'a.srt':
  Duration: N/A, bitrate: N/A
    Stream #1:0: Subtitle: subrip
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (dts (dca) -> aac (native))
  Stream #1:0 -> #0:2 (subrip (srt) -> mov_text (native))
Press [q] to stop, [?] for help
Output #0, mp4, to 'b.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.25.100
    Chapter #0:0: start 0.000000, end 10.000000
    Metadata:
      title           : 
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 906 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 24k tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp (16 bit), 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      encoder         : Lavc58.43.101 aac
    Stream #0:2: Subtitle: mov_text (tx3g / 0x67337874)
    Metadata:
      encoder         : Lavc58.43.101 mov_text
frame=  242 fps=0.0 q=-1.0 Lsize=    1278kB time=00:00:10.00 bitrate=1046.7kbits/s speed=46.5x    
video:1117kB audio:150kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.897478%
[aac @ 0x7ff8d2006400] Qavg: 4652.685

~$ ffmpeg -i b.mp4 b.srt
ffmpeg version git-2019-01-12-1ea5529 Copyright (c) 2000-2019 the FFmpeg developers
  built with Apple LLVM version 9.0.0 (clang-900.0.39.2)
  configuration: --enable-libx264 --enable-gpl
  libavutil      56. 25.100 / 56. 25.100
  libavcodec     58. 43.101 / 58. 43.101
  libavformat    58. 25.100 / 58. 25.100
  libavdevice    58.  6.101 / 58.  6.101
  libavfilter     7. 48.100 /  7. 48.100
  libswscale      5.  4.100 /  5.  4.100
  libswresample   3.  4.100 /  3.  4.100
  libpostproc    55.  4.100 / 55.  4.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'b.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.25.100
  Duration: 00:10:00.00, start: 0.000000, bitrate: 17 kb/s
    Chapter #0:0: start 0.000000, end 10.000000
    Metadata:
      title           : 
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 906 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 47.95 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 122 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
    Stream #0:2(und): Subtitle: mov_text (tx3g / 0x67337874) (default)
    Metadata:
      handler_name    : SubtitleHandler
    Stream #0:3(eng): Data: bin_data (text / 0x74786574), 0 kb/s
    Metadata:
      handler_name    : SubtitleHandler
Output #0, srt, to 'b.srt':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.25.100
    Chapter #0:0: start 0.000000, end 10.000000
    Metadata:
      title           : 
    Stream #0:0(und): Subtitle: subrip (srt) (default)
    Metadata:
      handler_name    : SubtitleHandler
      encoder         : Lavc58.43.101 srt
Stream mapping:
  Stream #0:2 -> #0:0 (mov_text (native) -> subrip (srt))
Press [q] to stop, [?] for help
size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x    
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 41.975307%

~$ cat b.srt
1
00:00:00,000 --> 00:10:00,000
<font face="Serif" size="18">The quick brown fox jumps
over the lazy dog.</font>

comment:5 by forthrin, 6 years ago

@cehoyos: I think this is two issues:

  1. An explicit style being applied when embedding mov_text format.
  2. Styles being applied when converting mov_text to srt.

For 1), I can't find any documentation for mov_text anywhere, but looking at text_sample_entry in movtextenc.c, the binary data seems to require explicit values/defaults for font-size, font-style, etc. If so, there is no way to prevent some kind of default being present in the file as this would corrupt the data layout. If so, it's up to the video player whether to favour them over its own font settings. If so, this issue would be a non-issue.

For 2) <font face="Serif" size="18"> is set because the defaults embedded in the mov_text data differ from the ASS defaults. See if (st->font_name && strcmp(st->font_name, ASS_DEFAULT_FONT) || st->font_size != ASS_DEFAULT_FONT_SIZE || c != ASS_DEFAULT_COLOR) in srtenc.c. The patch below resolves this. (Unless the mov_text format has some predefined values of its own that are required/recommended as defaults?)

diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c
index c19ef384b..f98857c51 100644
--- a/libavcodec/movtextenc.c
+++ b/libavcodec/movtextenc.c
@@ -176,3 +176,3 @@ static av_cold int mov_text_encode_init(AVCodecContext *avctx)
         0x00,                   // uint8_t face-style-flags
-        0x12,                   // uint8_t font-size
+        0x10,                   // uint8_t font-size // ASS_DEFAULT_FONT_SIZE
         0xFF, 0xFF, 0xFF, 0xFF, // uint8_t text-color-rgba[4]
@@ -186,3 +186,3 @@ static av_cold int mov_text_encode_init(AVCodecContext *avctx)
         0x05,                   // uint8_t font-name-length
-        'S', 'e', 'r', 'i', 'f',// uint8_t font[font-name-length]
+        'A', 'r', 'i', 'a', 'l',// uint8_t font[font-name-length] // ASS_DEFAULT_FONT
         // };
Last edited 6 years ago by forthrin (previous) (diff)

comment:6 by Carl Eugen Hoyos, 6 years ago

Patches are ignored on this bug tracker but please use the defines instead of mentioning them.

comment:7 by forthrin, 6 years ago

@cehoyos: Do you know the C syntax for inserting #define ASS_DEFAULT_FONT "Arial" into the byte array text_sample_entry?

comment:8 by Carl Eugen Hoyos, 6 years ago

Try to change the code.

comment:9 by forthrin, 6 years ago

Version 1, edited 6 years ago by forthrin (previous) (next) (diff)
Note: See TracTickets for help on using tickets.