2

I use git to track *.ass subtitle files. Here is example of *.ass file:

[Script Info]
; Script generated by Aegisub 3.1.2
; http://www.aegisub.org/
Title: Default Aegisub file
ScriptType: v4.00+

[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour,    BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: Default,Arial,20,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,2,2,2,10,10,10,1
Style: titr,DejaVu     

Sans,20,&H007DDBFA,&H000000FF,&H00000000,&HFF000000,0,0,0,0,100,100,0,0,1,2,2,1,10,10,10,1

[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:00:00.46,0:00:11.22,Default,,0,0,0,,Если это можно было бы
Dialogue: 0,0:00:03.44,0:00:08.96,titr,,0,0,0,,{\pos(20,240)\fad(600,600)}бывший министр

After commit I burn subtitles into video:

ffmpeg -i video.avi -vf "ass=subtitle.ass" out.avi

My goal is to show commit date for 10 second at the start of movie. This should be done automatically.

1) It can be easily done with by modifying subtitle.ass itself, but I can't do it after commit and there are other reasons.

2) It can be done by ffmpeg from command line: How to use ffmpeg to add a text to avi video?

Problem is that in this case text will be shown for the whole lenght of movie.

3) I can copy *.ass file to temporary directory, insert date, render and delete *.ass file.

Is there a simpler way?

Community
  • 1
  • 1
microspace
  • 386
  • 1
  • 5
  • 18
  • The third approach (add the commit date to a temporary file, use it, then delete it) seems to be the easiest. Could you edit your question to add the head (first 20 lines, say) of one of your `*.ass` files, so we know what they're made of? – jub0bs Aug 23 '14 at 17:44

1 Answers1

2

Your third approach seems easy enough. Here is a possible implementation of it.

enter image description here

The tree structure I used is

$ tree
.
├── burn_sub_w_commit_date
├── sub_repo
│   └── sub.ass
└── test_video.avi

where

  • burn_sub_w_commit_date is a shell (bash) script,
  • sub.ass is the original subtitles file you posted in your question,
  • sub_repo is a Git repository that keeps track of your work on sub.ass (and that contains at least one commit),
  • test_video.avi is just some video I found on Youtube.

Here are the contents of burn_sub_w_commit_date:

#!/bin/sh
# burn last commit date with subtitles in video

# exit on any errors
set -e

# extract the head of test.ass and copy it to a temporary file
sed '/Dialogue:/,$d' sub.ass > temp_head.ass

# extract the tail of test.ass and copy it to a second temporary file
sed -n '/Dialogue:/,$p' sub.ass > temp_tail.ass

# write the commit date to a third temporary file
printf "Dialogue: 0,0:00:00.00,0:00:10.00,Default,,0,0,0,,`git log -1 --format="%cD" | sed 's/ [+\-][0-9]\{4\}//'`\n" > temp_mid.ass

# concatenate all three temporary files into a fourth one
cat temp_head.ass temp_mid.ass temp_tail.ass > temp.ass

# clean up (delete the first three temporary files)
rm temp_head.ass temp_tail.ass temp_mid.ass

# burn subtitles into the video
ffmpeg -i "../test_video.avi" -vf "ass='temp.ass'" "../test_video_out.avi"

# clean up (delete the last temporary file)
rm temp.ass

Now, if you cd to test_video/sub_repo and run

sh ../burn_sub_w_commit_date

the subtitles will be burn into the video and the date of the last commit on the current branch, in my case

Sun, 24 Aug 2014 00:01:23

will be shown for 10 seconds at the very beginning.

Of course, you may want to improve automation; making the script executable and let it accepts the relevant paths as arguments seems like the next obvious step... but the basic idea is there.

jub0bs
  • 60,866
  • 25
  • 183
  • 186