从文件中的AVSubtitle转储字幕 [英] Dump subtitle from AVSubtitle in the file

查看:105
本文介绍了从文件中的AVSubtitle转储字幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在FFMPEG软件中,AVPicture用于通过数据指针和行大小存储图像数据,这意味着所有字幕都以图片形式存储在ffmpeg中.现在我有了DVB字幕,我想将存储在AVPicture中的字幕图片转储到缓冲区中.我知道这些图像字幕可以使用for,fopen和sprintf进行转储.但是不知道如何转储字幕.我必须转储.ppm文件格式的字幕.

In FFMPEG sofftware, AVPicture is used to store image data using data pointer and linesizes.It means all subtitles are stored in the form of picture inside ffmpeg. Now I have DVB subtitle and I want to dump picture of subtitles stored in AVPicture in a buffer. I know these images subtitles can be dump using for, fopen and sprintf. But do not know how to dump Subtitle.I have to dump subtitles in .ppm file format.

谁能帮我从AVSubtitle转储字幕图片.

Can anyone help me to dump picture of subtitles in buffer from AVSubtitle .

推荐答案

此过程看起来很复杂,但实际上非常简单.
AVSubtitle 是通用格式,支持文本和位图模式.仅dvbsub格式afaik位图,并且位图格式可以不同,例如16color或256color模式,称为 CLUT_DEPTH .
我相信(在当前ffmpeg中)存储在 AVSubtitleRect 结构中的位图,该结构是 AVSubtitle 的成员.
我假设您有一个有效的 AVSubtitle 数据包,如果我理解正确,您可以执行以下操作,并且应该可以正常工作:
1)检查 pkt-> rect [0]->类型.此处的pkt是有效的 AVSubtitle 数据包.它必须是 SUBTITLE_BITMAP 的类型.
2)如果是这样,可以从 pkt-> rects [0]-> w pkt-> rects [0]-> h 中读取具有和高度的位图.代码>.
3)位图数据本身将是 pkt-> rects [0]-> data [0] .
4)可以从 pkt-> rects [0]-> nb_colors 中读取CLUT_DEPTH.
5)CLUT本身(颜色表)将位于 pkt-> rects [0]-> data [1] 中.

This process looks complex but actually very simple.
AVSubtitle is generic format, supports text and bitmap modes. Dvbsub format afaik bitmap only and the bitmap format can be differ like 16color or 256color mode as called CLUT_DEPTH.
I believe (in current ffmpeg) the bitmaps stored in AVSubtitleRect structure, which is member of AVSubtitle.
I assume you have a valid AVSubtitle packet(s) and if I understand correctly you can do these and it should work:
1) Check pkt->rect[0]->type. The pkt here is a valid AVSubtitle packet. It must be type of SUBTITLE_BITMAP.
2) If so, bitmap with and height can be read from pkt->rects[0]->w and pkt->rects[0]->h.
3) Bitmap data itself in will be pkt->rects[0]->data[0].
4) CLUT_DEPTH can be read from pkt->rects[0]->nb_colors.
5) And CLUT itself (color table) will be in pkt->rects[0]->data[1].

使用这些数据,您可以构建一个有效的 .bmp 文件,该文件可以在Windows或linux桌面上查看,但是我把这部分留给了您.

With these data, you can construct a valid .bmp file that can be viewable on windows or linux desktop, but I left this part to you.

PPM信息

首先检查有关PPM格式的信息:
https://www.cs.swarthmore.edu/〜soni/cs35/f13/Labs/extras/01/ppm_info.html

First check this info about PPM format:
https://www.cs.swarthmore.edu/~soni/cs35/f13/Labs/extras/01/ppm_info.html

我了解的是PPM格式使用RGB值(24位/3字节).在我看来,您要做的就是根据从上面的 AVSubtitle 数据包获得的数据构造一个标头.并将dvbsub的索引颜色缓冲区转换为RGB的转换函数.我很确定某个地方有一些随时可以使用的代码,但是我还是会解释.
在图像数据中,Dvbsub使用的是线性数据,每个像素为1字节(即使在16色模式下).此字节值实际上是与存储在颜色查找表(CLUT)中的RGB(?)值相对应的索引值,在16色模式下,每个16个索引中的每个4个字节,前3个是R,G,B值,第4个是alpha(透明度值,如果PPM不支持此值,则将其忽略).

What I understand is PPM format uses RGB values (24bit/3bytes). It looks like to me all you have to do is construct a header according to data obtained from AVSubtitle packet above. And write a conversion function for dvbsub's indexed color buffer to RGB. I'm pretty sure somewhere there are some ready to use codes out there but I'll explain anyway.
In the picture frame data Dvbsub uses is liner and every pixel is 1 byte (even in 16color mode). This byte value is actually index value that correspond RGB (?) values stored in Color Look-Up Table (CLUT), in 16 color mode there are 16 index each 4 bytes, first 3 are R, G, B values and 4th one is alpha (transparency values, if PPM doesn't support this, ignore it).

我不确定解码字幕是否仍具有已编码的YUV值.我记得它应该是纯RGBA格式.

I'm not sure if decoded subtitle still has encoded YUV values. I remember it should be plain RGBA format.

encode_dvb_subtitles 函数显示了此编码的完成方式.如果需要的话.
https://github.com/FFmpeg/FFmpeg/blob/a0ac49e38e7dlibavcodec/dvbsub.c

encode_dvb_subtitles function on ffmpeg shows how this encoding done. If you need it.
https://github.com/FFmpeg/FFmpeg/blob/a0ac49e38ee1d1011c394d7be67d0f08b2281526/libavcodec/dvbsub.c

希望有帮助.

这篇关于从文件中的AVSubtitle转储字幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆