Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > General > Subtitles

Reply
 
Thread Tools Search this Thread Display Modes
Old 26th December 2012, 08:06   #1  |  Link
srijithv
Registered User
 
Join Date: Dec 2012
Posts: 2
facing an issue with avcodec_decode_subtitle2

Hello,

I am working on an assignment (using 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 control file.

The details of the actual events
SUBTITLE_STREAM_INDEX_2
Event1 (X="607" Y="780" START_FRAME="764")

SUBTITLE_STREAM_INDEX_3
Event1 (X="575" Y="780" START_FRAME="764")

SUBTITLE_STREAM_INDEX_4
Event1 (X="701" Y="780" START_FRAME="764")

SUBTITLE_STREAM_INDEX_5
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 values.
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[0]->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:



Code:
Code:
AVPacket packet;   
//looping till end of file
{   
   av_init_packet(&packet);
    av_read_frame(pFormatContext, &packet);
   
if((packet.stream_index == m_subtitleStreamIndex[0]) || (packet.stream_index == m_subtitleStreamIndex[1]) || (packet.stream_index == m_subtitleStreamIndex[2]) || (packet.stream_index == m_subtitleStreamIndex[3]))
{
   int has_subtitle = 0;
    AVSubtitle* subtitle = new AVSubtitle;
    avcodec_decode_subtitle2(pSubtitleCodecContext, subtitle, &has_subtitle, &packet);

    if (has_subtitle != 0)
    {    
        if (subtitle->rects)
            {
                struct SwsContext *mSwsContext = sws_getContext(subtitle->rects[0]->w, subtitle->rects[0]->h, pSubtitleCodecContext->pix_fmt,
                                        subtitle->rects[0]->w, subtitle->rects[0]->h, PIX_FMT_RGBA,
                                        SWS_BICUBIC, NULL, NULL, NULL);
                AVFrame     *pPicture = AllocatePicture(PIX_FMT_RGBA, subtitle->rects[0]->w, subtitle->rects[0]->h);

                /* convert to RGB */
                sws_scale(mSwsContext, (const uint8_t **) subtitle->rects[0]->pict.data, subtitle->rects[0]->pict.linesize, 0, subtitle->rects[0]->h,
                                        pPicture->data, pPicture->linesize);
                                       
                //code to generate png
                                               
                av_free(pPicture);
                sws_freeContext(mSwsContext);
            }
        }
   }
    avsubtitle_free(subtitle);
}   
}


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.

Thanks,
Srijith
srijithv is offline   Reply With Quote
Reply

Tags
subtitle

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:27.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.