【发布时间】:2018-05-20 08:46:17
【问题描述】:
我找到了一些代码,对其进行了一些编辑以打印字幕文本,但我不确定如何将字幕保存到文件中(从视频文件中提取,例如 mkv)
接下来的代码只是打印了很多行,并不是所有的都包含字幕文本
std::ofstream out ("/path/to/extracted/subtitles.srt");
while(av_read_frame(pFormatCtx, &pkt) == 0) {
int got_frame = 0;
int ret = avcodec_decode_subtitle2(aCodecCtx, subtitle, &got_frame, &pkt);
if (ret >= 0 && got_frame) {
AVSubtitleRect **rects = subtitle->rects;
for (i = 0; i < subtitle->num_rects; i++) {
AVSubtitleRect rect = *rects[i];
if (rect.type == SUBTITLE_ASS) {
printf("ASS %s", rect.ass);
} else if (rect.x == SUBTITLE_TEXT) {;
printf("TEXT %s", rect.text);
}
}
// it just writes some big file (similar to videofile size)
//out.write((char*)pkt.data, pkt.size);
}
}
out.close();
//...
【问题讨论】:
标签: c++ ffmpeg ifstream subtitle