Tech/CnSiE Subtitle Panel and Nametag Generation Scripts >

I finally made scripts to generate the panels I described in my previous CnSiE subtitling article Subtitling techniques used for CnSiE Videos.

Just as a reminder, the method being described here is using Aegisub's Draw command to create a textbox background to help blend subtitle content in with a game's interface.

Example:

Original:

Ss 2015-11-03-21h55m22s792.png

Subtitled with Boxes:

Ss 2015-11-03-21h55m07s791.png

Linux BASH/Shell Scripting, Not LUA

So these are not Aegisub plugins. Sorry. I really need to learn LUA and the Aegisub LUA APIs because it would probably make a LOT of different things MUCH easier. But I wanted to do it now, without learning something new, so these are bash shells. Anyone wanting to use these in a Windows environment could install Cygwin, but I only tested these on GNU Bash v4 so cross compat is questionable.

Logic Flow

  • Read Aegisub Dialogue lines in as LINE
  • Grep to downselect for non-comment Dialogue lines with style name set to panel text style name "storymode_text"
  • Use awk to check for a regex match for content like "fad( followed by )
  • Set text found between those markers to FADE
    • If FADE has a value, BG/Name generation needs to include a \fad(x,y) command set to FADE
  • Output BG name Aegisub line

- Repeat for Nametags

Two different scripts are used for Ciel nosurge Story mode UI and a second for Ciel nosurge Ion Room mode UI (different dimensions, positions, colors).


cnsie_mkstory_names_bgs.sh

Begin by creating a file called ./input_story containing the Aegisub content. I like to just copy the lines from Aegisub, then run cat and paste them in...

# cat > input
Comment: 0,0:00:00.00,0:00:05.00,storymode_text,[story/text],0,0,0,,|===========================================================================================
Dialogue: 0,0:00:11.62,0:00:12.72,storymode_text,Security Guard,0,0,0,,.... Hmm?
Dialogue: 0,0:00:13.54,0:00:17.17,storymode_text,Security Guard,0,0,0,,It kind of seemed like someone was over there...
Dialogue: 0,0:00:17.17,0:00:22.24,storymode_text,Security Guard,0,0,0,,Actually, this place is really close to where that really huge accident happened, isn't it.
Dialogue: 0,0:00:22.24,0:00:25.39,storymode_text,Security Guard,0,0,0,,It couldn't be a... ghost?
Dialogue: 0,0:00:25.39,0:00:29.52,storymode_text,Security Guard,0,0,0,,{\fad(0,1950)}Heh, no way...
Dialogue: 0,0:00:33.00,0:00:39.79,storymode_text,Clacket,0,0,0,,Hmm.  With the gum-base that I borrowed from the food warehouse, that means...
Dialogue: 0,0:00:39.79,0:00:44.39,storymode_text,Clacket,0,0,0,,Yes, yes! \NIt's finally, finally finished!!
Dialogue: 0,0:00:44.39,0:00:49.67,storymode_text,Clacket,0,0,0,,With seven different flavors all combined into a single stick, I'll call it "Rainbow Gum"!
Dialogue: 0,0:00:49.67,0:00:58.59,storymode_text,Clacket,0,0,0,,Hmm, it does have a stink to it, but it's within permissible limits.  Besides, mixed oils are used in tons of other places too!
...

Do a new line (press Enter) and then Control+D to finish and save the file.


Make Storymode Names and Background Panels Script:

#!/bin/bash
# cnsie_mkstory_names_bgs.sh
#
# - Script to create STORYMODE Name-tags and BG Panels for CnSiE
#
# USAGE:
#		Place dialog lines in "./input_story"
#		Comments will be filtered so block copy is fine


# Setup BG and Nametag block comment separators
STORYNAME="Comment: 0,0:00:00.00,0:00:05.00,storymode_name,[story/name],0,0,0,,|===================================================================================="
STORYBG="Comment: 0,0:00:00.00,0:00:05.00,storymode_bg,[story/bg],0,0,0,,|===================================================================================="

# Check that input lines is there and looks valid
if [ ! -f ./input_story ]; then
	echo "ERROR: ./input_story doesn't exist."
	exit 1
else
	# okay, it exists, let's do a quick format check for valid contents
	# this is pretty basic, but see if there are ASS dialogue lines
	if [ ! `cat ./input_story | egrep "^Dialogue.+storymode_text" | wc -l` -gt 0 ]; then
		# No valid CnSiE dialogue lines found
		echo "ERROR: ./input_story does not contain valid dialogue lines."
                echo " = Script is for CnSiE::STORYMODE dialogue"
		exit 2
	fi
fi

# create a few lines of space to help with block copy
for i in {1..5}; do echo; done

# == Create BackGround
# output the BG block comment marker
echo "$STORYBG"

# read input in and set it to variable line (excluding any Comment lines)
cat input_story | grep -v "^Comment" | while read line
do
  # Note that match here excludes the backslash
	# echoing line is stripping it for some reason
	# fad(...) matching should be solid enough
	FADE="`echo $line | awk '{ where = match($0,/fad\((.+)\).+/, outstring); print outstring[1]}'`"

	if [ "$FADE" ]; then
                # Line has a fad value.  Create appropriate \fad(x,y) insert
		echo $line | awk -F"," -v fadeline="{\\\\fad($FADE)}" '{print $1","$2","$3",storymode_bg,"$5",0,0,0,,"fadeline"{\\blur1}{\\pos(0,0)}{\\p1}m 193 404 l 767 404 l 773 417 l 779 446 l 785 540 175 540 l 179 475 l 183 442 l 186 423"}'

	else
                # No fade.  Output panel without the fad  tag
		echo $line | awk -F"," '{print $1","$2","$3",storymode_bg,"$5",0,0,0,,{\\blur1}{\\pos(0,0)}{\\p1}m 193 404 l 767 404 l 773 417 l 779 446 l 785 540 175 540 l 179 475 l 183 442 l 186 423"}'
	fi
done


# == Create NameTags
echo "$STORYNAME"
cat input_story | grep -v "^Comment" | while read line
do
  # Note that match here excludes the backslash
  # echoing line is stripping it for some reason
  # fad(...) matching should be solid enough
  FADE="`echo $line | awk '{ where = match($0,/fad\((.+)\).+/, outstring); print outstring[1]}'`"

  if [ "$FADE" ]; then
		echo $line | awk -F"," -v fadeline="{\\\\fad($FADE)}" '{print "Dialogue: 2,"$2","$3",storymode_name,"$5",0,0,0,,"fadeline$5}'
  else
		echo $line | awk -F"," '{print "Dialogue: 2,"$2","$3",storymode_name,"$5",0,0,0,,"$5}'
	fi
done

When this script is run, it will simply run through the ./input_story file line by line and output first the BG dialogue lines, then again for the name tags. Output looks like this:

cnsie_mkstory_names_bgs.sh output

Comment: 0,0:00:00.00,0:00:05.00,storymode_bg,[story/bg],0,0,0,,|====================================================================================
Dialogue: 0,0:00:11.62,0:00:12.72,storymode_bg,Security Guard,0,0,0,,{\blur1}{\pos(0,0)}{\p1}m 193 404 l 767 404 l 773 417 l 779 446 l 785 540 175 540 l 179 475 l 183 442 l 186 423
Dialogue: 0,0:00:13.54,0:00:17.17,storymode_bg,Security Guard,0,0,0,,{\blur1}{\pos(0,0)}{\p1}m 193 404 l 767 404 l 773 417 l 779 446 l 785 540 175 540 l 179 475 l 183 442 l 186 423
Dialogue: 0,0:00:17.17,0:00:22.24,storymode_bg,Security Guard,0,0,0,,{\blur1}{\pos(0,0)}{\p1}m 193 404 l 767 404 l 773 417 l 779 446 l 785 540 175 540 l 179 475 l 183 442 l 186 423
Dialogue: 0,0:00:22.24,0:00:25.39,storymode_bg,Security Guard,0,0,0,,{\blur1}{\pos(0,0)}{\p1}m 193 404 l 767 404 l 773 417 l 779 446 l 785 540 175 540 l 179 475 l 183 442 l 186 423
Dialogue: 0,0:00:25.39,0:00:29.52,storymode_bg,Security Guard,0,0,0,,{\fad(0,1950)}{\blur1}{\pos(0,0)}{\p1}m 193 404 l 767 404 l 773 417 l 779 446 l 785 540 175 540 l 179 475 l 183 442 l 186 423
Dialogue: 0,0:00:33.00,0:00:39.79,storymode_bg,Clacket,0,0,0,,{\blur1}{\pos(0,0)}{\p1}m 193 404 l 767 404 l 773 417 l 779 446 l 785 540 175 540 l 179 475 l 183 442 l 186 423
Dialogue: 0,0:00:39.79,0:00:44.39,storymode_bg,Clacket,0,0,0,,{\blur1}{\pos(0,0)}{\p1}m 193 404 l 767 404 l 773 417 l 779 446 l 785 540 175 540 l 179 475 l 183 442 l 186 423
...
Comment: 0,0:00:00.00,0:00:05.00,storymode_name,[story/name],0,0,0,,|====================================================================================
Dialogue: 2,0:00:11.62,0:00:12.72,storymode_name,Security Guard,0,0,0,,Security Guard
Dialogue: 2,0:00:13.54,0:00:17.17,storymode_name,Security Guard,0,0,0,,Security Guard
Dialogue: 2,0:00:17.17,0:00:22.24,storymode_name,Security Guard,0,0,0,,Security Guard
Dialogue: 2,0:00:22.24,0:00:25.39,storymode_name,Security Guard,0,0,0,,Security Guard
Dialogue: 2,0:00:25.39,0:00:29.52,storymode_name,Security Guard,0,0,0,,{\fad(0,1950)}Security Guard
Dialogue: 2,0:00:33.00,0:00:39.79,storymode_name,Clacket,0,0,0,,Clacket
Dialogue: 2,0:00:39.79,0:00:44.39,storymode_name,Clacket,0,0,0,,Clacket
...

The output can then just be copied and pasted into Aegisub. Note that the script is also automatically setting layers 0 for the BG panel and 2 for the nametags. Original content would optimally be set to layer 1 or 3+, but as long as the BG panel text is pasted BEFORE the actual subtitles, the {\pos(0,0)} override will cause them to layer automatically.


cnsie_mkionroom_names_bgs.sh

The script for creating the Ion Room text works the same. Place the Aegisub subtitle lines in a file called ./input_ionroom first.

# cat > ./input_ionroom
omment: 0,0:00:00.00,0:00:03.99,ionroom_text,[ionroom/text],0,0,0,,|==========================================================================================
Dialogue: 0,0:00:00.00,0:00:03.99,ionroom_text,Ion,0,0,0,,Oh, you're here, you're here!
Dialogue: 0,0:00:07.14,0:00:09.55,ionroom_text,Ion,0,0,0,,Hehehe{\fnCalibri\b1}♪{\fnLivingston Md\b0}  Thanks for coming!
Comment: 0,0:00:09.55,0:00:18.22,ionroom_text,[tlnote],0,0,0,,// I'm going to make a small note in the video description so anybody that hears the "mou sugu" doesn't spaz out.
Dialogue: 0,0:00:09.55,0:00:18.22,ionroom_text,Ion,0,0,0,,It's Valentine's Day, isn't it? \NI'm getting pretty excited.
Dialogue: 0,0:00:18.22,0:00:21.14,ionroom_text,Ion,0,0,0,,Nelico told me about it.
Dialogue: 0,0:00:21.14,0:00:30.74,ionroom_text,Ion,0,0,0,,She said that in your world, there's an event held today called Valentine's Day where you give chocolate to the person that you love.
Dialogue: 0,0:00:30.74,0:00:41.39,ionroom_text,Ion,0,0,0,,.... You didn't by any chance get any chocolate from somebody, did you?
...

Again, enter and control+d will save the file.


Make Ion Room Nametag and BG Panel Script:

#!/bin/bash
# cnsie_mkionroom_names_bgs.sh
#
# - Script to create IONROOM Name-tags and BG Panels for CnSiE
#
# USAGE:
#		Place dialog lines in "./input_ionroom"
#		Comments will be filtered so block copy is fine

# Setup BG and Nametag block comment separators
LABELNAME="Comment: 0,0:00:00.00,0:00:05.00,ionroom_name,[ionroom/name],0,0,0,,|===================================================================================="
LABELBG="Comment: 0,0:00:00.00,0:00:05.00,ionroom_bg,[ionroom/bg],0,0,0,,|===================================================================================="

# Check that input lines is there and looks valid
if [ ! -f ./input_ionroom ]; then
	echo "ERROR: ./input_ionroom doesn't exist."
	exit 1
else
	# okay, it exists, let's do a quick format check for valid contents
	# this is pretty basic, but see if there are ASS dialogue lines
	if [ ! `cat ./input_ionroom | egrep "^Dialogue.+ionroom_text" | wc -l` -gt 0 ]; then
		# No valid CnSiE dialogue lines found
		echo "ERROR: ./input_ionroom does not contain valid dialogue lines."
		echo " = Script is for CnSiE::IONROOM dialogue"
		exit 2
	fi
fi

# create a few lines of space to help with block copy
for i in {1..5}
do
	echo
done


# == Create BackGround
echo "$LABELBG"
cat input_ionroom | grep -v "^Comment" | while read line
do
  # Note that match here excludes the backslash
	# echoing line is stripping it for some reason
	# fad(...) matching should be solid enough
	FADE="`echo $line | awk '{ where = match($0,/fad\((.+)\).+/, outstring); print outstring[1]}'`"


	if [ "$FADE" ]; then
		# echo $line | awk -F"," -v fadeline="{\\\\fad($FADE)}" '{print $1","$2","$3",storymode_bg,"$5",0,0,0,,"fadeline"{\\blur1}{\\pos(0,0)}{\\p1}m 193 404 l 767 404 l 773 417 l 779 446 l 785 540 175 540 l 179 475 l 183 442 l 186 423"}'
		echo $line | awk -F"," -v fadeline="{\\\\fad($FADE)}" '{print $1","$2","$3",ionroom_bg,"$5",0,0,0,,"fadeline"{\\blur2}{\\pos(0,0)}{\\p1}m 199 410 l 205 396 l 752 396 l 760 403 l 760 516 l 752 520 l 205 520 l 199 516"}'
	else

		echo $line | awk -F"," '{print $1","$2","$3",ionroom_bg,"$5",0,0,0,,{\\blur2}{\\pos(0,0)}{\\p1}m 199 410 l 205 396 l 752 396 l 760 403 l 760 516 l 752 520 l 205 520 l 199 516"}'

	fi
done

# == Create NameTags
echo "$LABELNAME"
cat input_ionroom | grep -v "^Comment" | while read line
do
  # Note that match here excludes the backslash
  # echoing line is stripping it for some reason
  # fad(...) matching should be solid enough
  FADE="`echo $line | awk '{ where = match($0,/fad\((.+)\).+/, outstring); print outstring[1]}'`"

  if [ "$FADE" ]; then
		echo $line | awk -F"," -v fadeline="{\\\\fad($FADE)}" '{print "Dialogue: 2,"$2","$3",ionroom_name,"$5",0,0,0,,"fadeline$5}'
  else
		echo $line | awk -F"," '{print "Dialogue: 2,"$2","$3",ionroom_name,"$5",0,0,0,,"$5}'
	fi
done

# add a trailing newline just to make it easy to select block
echo

Want To Use This?

Fine by me. Of course, you'll need to customize and modify to work for you, which means you'd probably already have to know how to do this on your own anyways, and you probably have a better way to do it to.

I'll make an Aegisub LUA plugin some day to do this. I will. Just not right now. Or even soon.