git - 如何自动将提交信息嵌入到我正在跟踪的字幕文件中?

标签 git ffmpeg

我使用git来跟踪*.ass字幕文件。 以下是 *.ass 文件的示例:

[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)}бывший министр

提交后,我将字幕刻录到视频中:

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

我的目标是在电影开始时显示提交日期 10 秒。这应该自动完成。

1)通过修改subtitle.ass本身就可以轻松完成,但是commit后却无法完成,还有其他原因。

2) 可以通过命令行中的ffmpeg来完成:How to use ffmpeg to add a text to avi video?

问题是在这种情况下,文本将显示整个电影长度。

3) 我可以将 *.ass 文件复制到临时目录、插入日期、渲染和删除 *.ass 文件。

有没有更简单的方法?

最佳答案

你的第三种方法似乎很简单。这是它的一个可能的实现。

enter image description here

我使用的树结构是

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

哪里

  • burn_sub_w_commit_date 是一个 shell (bash) 脚本,
  • sub.ass 是您在问题中发布的原始字幕文件,
  • sub_repo 是一个 Git 存储库,用于跟踪您在 sub.ass 上的工作(并且至少包含一次提交),
  • test_video.avi 只是我在 Youtube 上找到的一些视频。

以下是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

现在,如果您 cdtest_video/sub_repo 并运行

sh ../burn_sub_w_commit_date

在我的例子中,字幕将被刻录到视频中以及当前分支上最后一次提交的日期

Sun, 24 Aug 2014 00:01:23

一开始会显示10秒。

当然,您可能希望提高自动化程度;使脚本可执行并让它接受相关路径作为参数似乎是下一个明显的步骤......但基本思想就在那里。

关于git - 如何自动将提交信息嵌入到我正在跟踪的字幕文件中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25464162/

相关文章:

git tag -l 不删除已删除的标签

android - FFmpeg:如何使输出视频与输入视频具有相同的宽度、高度和 SAR

unity3d - 在 UWP 的 Unity 插件中使用 DirectX11 的硬件加速 H264 解码

git - 在 git 中转义在文件名中添加前导 "-"?

git - 您的分支比 'origin/cherryPick' 领先 1 次提交。为什么?

git - 推送一个 'unchecked out' 分支

c# - 在 c# 中使用 ffmpeg 时遇到问题如何正确格式化字符串以升级视频?

c++ - 如何将静音音频数据写入音频流?

android - 从 AVFrame 数据中获取单个缓冲区并在 Android Bitmap/Surface/SurfaceView 上显示

python - 从多个 git 开发分支测试 numpy python 库