[Libav-user] facing an issue with avcodec_decode_subtitle2
nair.sre at gmail.com
Thu Jan 3 05:02:27 CET 2013
I am working on an assignment (using C/C++) to decode all the subtitle
streams present in a m2ts file using libav.
I have a m2ts file with one video stream (video stream index = 0), one
audio stream (audio stream index = 1) and 5 subtitle streams ( stream
indices = 2, 3, 4, 5).
I first noticed the problem when I compared the position (x, y, w, h) I got
from the decoded subtitle against the actual subtitle position from its
*The details of the actual events*
Event1 (X="607" Y="780" START_FRAME="764")
Event1 (X="575" Y="780" START_FRAME="764")
Event1 (X="701" Y="780" START_FRAME="764")
Event1 (X="483" Y="777" START_FRAME="765")
Please note Event1 of SUBTITLE_STREAM_INDEX_2, SUBTITLE_STREAM_INDEX_3,
SUBTITLE_STREAM_INDEX_4 start at frame no 764.
When I ran the application, it first decoded Event1 of
SUBTITLE_STREAM_INDEX_4 and I got the position values from the decoded
subtitle as (701, 780, 507, 133).
Next it decoded Event1 of SUBTITLE_STREAM_INDEX_2 and the position values
decoded were as follows (701, 780, 507, 133). Please note the mismatch in
The values were same for decoded subtitle of SUBTITLE_STREAM_INDEX_3.
AS the next step I am decoding the subtitle and generating a png file. This
is when I noticed the issue.
For example I am decoding SUBTITLE_STREAM_INDEX_4 at frame no = 764. I
generated the image using the subtitle->rects->pict.data. This is
correct subtitle. (Assume the dialog to be "hi there").
Now I have another subtitle stream (index = 2) which also starts from the
same frame number (frame no = 764). Now when I generate a png using this
decoded subtitle it has the same subtitle text as the one decoded from
previous index. (the actual dialog is "hola", but the png generated had the
dialog as "hi there").
It is basically giving me the position and data of the subtitle decoded
from the first SUBTITLE_STREAM encountered for a particular frame number.
I am posting the part of code:
//looping till end of file
if((packet.stream_index == m_subtitleStreamIndex) ||
(packet.stream_index == m_subtitleStreamIndex) || (packet.stream_index
== m_subtitleStreamIndex) || (packet.stream_index ==
int has_subtitle = 0;
AVSubtitle* subtitle = new AVSubtitle;
if (has_subtitle != 0)
struct SwsContext *mSwsContext =
SWS_BICUBIC, NULL, NULL, NULL);
AVFrame *pPicture = AllocatePicture(PIX_FMT_RGBA,
/* convert to RGB */
sws_scale(mSwsContext, (const uint8_t **)
subtitle->rects->pict.data, subtitle->rects->pict.linesize, 0,
//code to generate png
Could anyone please advice if I am doing something wrong here or suggest a
solution to this problem? I am expecting your priceless guidance and help.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Libav-user