Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] FreeType-based text renderer (-out=spupng with teletext/EIA608) #877

Merged
merged 8 commits into from
Jan 9, 2018

Conversation

harrynull
Copy link
Contributor

@harrynull harrynull commented Jan 5, 2018

Please prefix your pull request with one of the following: [FEATURE] [FIX] [IMPROVEMENT].

In raising this pull request, I confirm the following (please check boxes):

  • I have read and understood the contributors guide.
  • I have checked that another pull request for this purpose does not exist.
  • I have considered, and confirmed that this submission will be valuable to others.
  • I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
  • I give this submission freely, and claim no ownership to its content.

My familiarity with the project is as follows (check one):

  • I have never used CCExtractor.
  • I have used CCExtractor just a couple of times.
  • I absolutely love CCExtractor, but have not contributed previously.
  • I am an active contributor to CCExtractor.

ABSTRACT
The pull request implements a FreeType-based text renderer, which can be used to generate the bitmaps for spupng in the case of teletext/EIA608.

CHANGES

  • Remove "ccx_encoders_spupng.h" (The old implementation of it) and "spupng_encoder.h" (encoders don't usually have header files)
  • Rename "spupng_encoder.c" to "ccx_encoders_spupng.c" (For consistency).
  • Add new implementation based on FreeType to "ccx_encoders_spupng.c".
  • Add a lot comments/document to the code.

KNOWN ISSUES
Note that the issues will also affect EIA-608 which may not have these issues before (But the new implementation is generally much cleaner, easier to maintain and more extensible and customizable than the old one).

  • Font needs to be manually set. FIXED (New option -font added to specify font)
  • No color: tag is rendered as-is.
  • XML position may be not correct.
  • Characters like "$" will be cut. FIXED
  • Accented letters don't render. (could be encoding problem) FIXED

NOTE
Please merge this PR after #876 , or it won't compile.

EXAMPLES
Note that the preview is not latest. Please refer to comments for the latest preview.
sub0001
Example of a good output.

sub0060
Example of tag rendered as-is.

![sub0000](https://user-images.githubusercontent.com/7413706/34639001-3e7d4ae2-f312-11e7-806b-b92c4d739b7b.png) (original generated png file) ![sub0000](https://user-images.githubusercontent.com/7413706/34639115-71ab680c-f314-11e7-8c70-5f75801d7dbe.jpg) (transparency is replaced by black) Example of "$" being cut.

FIXED

@harrynull harrynull mentioned this pull request Jan 5, 2018
9 tasks
@saurabhshri
Copy link
Member

This is looking good. 🙂 Okay, so couple of questions and points :

  1. Could you please also attach the generate XML file?

  2. Does the program generate the png with transparent background or black?

This question is important because these are directly displayed as it is by video players at the position defined by the XML file. For example :

image

So, if they are of transparent bg, they might not be visible properly, and if the complete rectangular frame is black : they might cover full regions.

This is how usual SPUPNG png looks :

sub0020

Notice how only the text has filled bg?

  1. The rendering of tags, is it the limitation of library or it can be implemented later? Because they can definitely have style in them.

sub0003

  1. I did not understand "Example of "$" being cut.". I can see the $ symbol, what does being cut mean?

  2. "Note that the issues will also affect EIA-608 which may not have these issues before" could you please point to specifics about what might get broken if this is added. It'll be an important criteria as we'd not like avoid breaking stuff as much as possible.

@harrynull
Copy link
Contributor Author

harrynull commented Jan 7, 2018

Could you please also attach the generate XML file?

I just noticed that the generated xml has incorrect offset values. I will upload them as soon as I fix them.

Does the program generate the png with transparent background or black?

The program generates png with transparent background. But it won't be hard to change it to black.
I can also clip the png so that it only contains the text.
So which is the one that we want?
transparent background + fixed width
Like sub0000
OR
text with black background + fixed width + transparent background where no text?
Like sub0060
(The old implementation)

The rendering of tags, is it the limitation of library or it can be implemented later? Because they can definitely have style in them.

FreeType can support colors, styles (bold/italic, by using different .tts), as long as you can parse these styles from tags.

I did not understand "Example of "$" being cut.". I can see the $ symbol, what does being cut mean?

Although it may be not that obvious, "$" is actually cut a little bit, depending on what font you use.
I've changed a new font which can demonstrate the issue more clearly.
sub0000

"Note that the issues will also affect EIA-608 which may not have these issues before" could you please point to specifics about what might get broken if this is added. It'll be an important criteria as we'd not like avoid breaking stuff as much as possible.

All the issues that I mentioned.

  • Font needs to be manually set.

This one is reasonable I think, since we don't know what font the user wants to use, and we can't specify a default font since we don't know if the user has it.

  • Characters like "$" will be cut.

Not really hard to fix. I will see if I can fix it.

  • Accented letters don't render. (could be encoding problem)

Same.

  • No color: tags are rendered as-is.

It needs parse of tags. I will see how the old code did it.

I'd open a new branch for it and merge it when everything works if we don't want to break anything.

@saurabhshri
Copy link
Member

I just noticed that the generated xml has incorrect offset values. I will upload them as soon as I fix them.

Sure!

So which is the one that we want?

I think the PNGs like the following would be perfect. They can then be placed anywhere on the screen (with the help of respective XML file).

sub0001

sub0002

sub0003

sub0004

FreeType can support colors, styles (bold/italic, by using different .tts), as long as you can parse these styles from tags.

If you're not including those changes in this PR, do remember to raise an issue once this is merged so that we don't forget it later on. 😉

@harrynull
Copy link
Contributor Author

A sample of generated xml is attached.
Note that the positioning may be not correct. The offset values are constant now. To get it work, we maybe need to know the size of the video.
I cannot make a video with SPUPNG subtitles because spumux somewhy didn't work for me so I can't test it.
COMEDY.zip

@saurabhshri
Copy link
Member

Please use relative path in XML instead of full path :

/mnt/d/Tests/EIA608/COMEDY.d/sub0000.png --> COMEDY.d/sub0000.png

Also, could you also show how the new pngs look? Attach them here.

@harrynull
Copy link
Contributor Author

harrynull commented Jan 8, 2018

The images in the PR has updated to the new pngs.
Relative path issue fixed (though it's not me who introduced the issue)

New xml file sample: teletext.zip

@@ -52,6 +52,7 @@ include_directories ("${PROJECT_SOURCE_DIR}/extractors/")
include_directories ("${PROJECT_SOURCE_DIR}/wrappers/")
include_directories ("${PROJECT_SOURCE_DIR}/libpng/")
include_directories ("${PROJECT_SOURCE_DIR}/zlib/")
include_directories ("${PROJECT_SOURCE_DIR}/freetype/include")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add trailing slash. It doesn't include all files without it.

#define FONT_PATH "C:\\Windows\\Fonts\\calibri.ttf"
#else
#define FONT_PATH "/usr/share/fonts/truetype/noto/NotoSans-Regular.ttf"
#endif
Copy link
Member

@saurabhshri saurabhshri Jan 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing font for macOS. Results in

Failed to init freetype when trying to init face, error code: 1
Error: Cannot write teletext2.d/sub0000.png: No such file or directory

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The font problem is actually one of the issue. I didn't fix it because I think it's part of customization. But yeah, I will fix it now, by adding an option.

Copy link
Member

@saurabhshri saurabhshri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please allow a parameter to pass the path of font in case the default one is missing, changing path in code is not desirable.

I tried couple of fonts and for some reason the pngs generated were quite pixelated - is it normal?

sub0001

Looks like text justification is not really making things neat. It leads to words breaking in newlines which doesn't contribute much to readability.

sub0010
sub0012

Let the text be as it is, do not justify it.

@saurabhshri
Copy link
Member

saurabhshri commented Jan 8, 2018

@harrynull Also it'd would have been better if you commented instead of changing description because, first, it tampers the history and comments seem senseless, and second it's easier to follow things. From next time always comment.

@harrynull
Copy link
Contributor Author

@saurabhshri
Text justification does not break words in newlines. Words are break simply because the given space is not enough to contain them so I break them to a new line so that no subtitles will be lost.
To solve it, you can either make the font smaller, or make the canvas bigger, by changing the value of FONT_SIZE and CANVAS_WIDTH.
The pixelated output issue is not expected. Could you tell me what font and FONT_SIZE and CANVAS_WIDTH values you are using?

@harrynull
Copy link
Contributor Author

Nevermind, it's a bug related to my black background algorithm. I've fixed it.

@harrynull
Copy link
Contributor Author

sub0000
The latest preview.

mprint (" comments in the XML file.\n");
mprint (" -font: Specify the font that is used when generating png files\n");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change it to Specify the full path of the font that is to be used when generating SPUPNG files.

@saurabhshri
Copy link
Member

@cfsmp3 Once that parameter description is edited, it's good for merge, thanks @harrynull - nice job! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants