[FFmpeg-trac] #9995(undetermined:new): AVSubtitle structure has rectangles outside screen

FFmpeg trac at avcodec.org
Fri Oct 28 14:46:42 EEST 2022


#9995: AVSubtitle structure has rectangles outside screen
-------------------------------------+-------------------------------------
             Reporter:  Peter        |                    Owner:  (none)
  Krefting                           |
                 Type:  defect       |                   Status:  new
             Priority:  normal       |                Component:
                                     |  undetermined
              Version:  unspecified  |               Resolution:
             Keywords:  dvdsub       |               Blocked By:
             Blocking:               |  Reproduced by developer:  0
Analyzed by developer:  0            |
-------------------------------------+-------------------------------------
Comment (by Peter Krefting):

 Boiling down the basics and linking with the latest master, I get this
 output:

 {{{
 $ ./ffmpeg-ticket-9995 ffmpeg-ticket-9995.ts
 Using N-108886-g79508ee523
 Received subtitle frame with 2 rectangles
 Using screen 720×576
 Subtitle rectangle 0 is 720×40 at 0,556 with 16 colours
  - vertical overflow
 Subtitle rectangle 1 is 720×40 at 0,516 with 16 colours
 }}}

 Source:

 {{{#!c
 #include <iostream>

 extern "C"{
 #include <libavformat/avformat.h>
 #include <libavcodec/avcodec.h>
 }

 int main(int argc, char *argv[])
 {
     if (argc < 2) {
         std::cerr << "Usage: " << argv[0] << " filename" << std::endl;
         return 1;
     }

     std::cout << "Using " << av_version_info() << std::endl;

     AVFormatContext* avf_ctx = avformat_alloc_context();
     std::string url = "file:";
     url += argv[1];
     if (avformat_open_input(&avf_ctx, url.c_str(), nullptr, nullptr) != 0)
 {
         std::cerr << "Unable to open " << url << std::endl;
         return 1;
     }

     AVPacket avpkt = { 0 };

     av_read_frame(avf_ctx, &avpkt);
     AVStream* stream = avf_ctx->streams[avpkt.stream_index];
     AVCodecParameters* par = stream->codecpar;
     const AVCodec* codec = avcodec_find_decoder(par->codec_id);
     AVCodecContext* decoder = avcodec_alloc_context3(codec);
     avcodec_parameters_to_context(decoder, par);
     avcodec_open2(decoder, codec, nullptr);

     AVSubtitle sub{};
     int got = 0;
     avcodec_decode_subtitle2(decoder, &sub, &got, &avpkt);

     std::cout << "Received subtitle frame with " << sub.num_rects << "
 rectangles" << std::endl;

     // Find full dimensions
     // Use values from Display Definition Segment, if any,
     // otherwise 720 by 576 (ETSI EN 300 743 V1.61 §5.1.3)
     int screen_height = decoder->coded_height ? decoder->coded_height :
 576;
     int screen_width  = decoder->coded_width  ? decoder->coded_width  :
 720;

     std::cout << "Using screen " << screen_width << "×" << screen_height
 << std::endl;
     for (unsigned int i = 0; i < sub.num_rects; ++ i) {
         AVSubtitleRect* rect = sub.rects[i];
         std::cout << "Subtitle rectangle " << i << " is "
                   << sub.rects[i]->w << "×" << sub.rects[i]->h << "@"
                   << sub.rects[i]->x << "," << sub.rects[i]->y << " with "
                   << sub.rects[i]->nb_colors << " colours" << std::endl;
         if (sub.rects[i]->x + sub.rects[i]->w > screen_width) {
             std::cout << " - horizontal overflow" << std::endl;
         }
         if (sub.rects[i]->y + sub.rects[i]->h > screen_height) {
             std::cout << " - vertical overflow" << std::endl;
         }
     }
     avsubtitle_free(&sub);
     av_packet_unref(&avpkt);
     avformat_close_input(&avf_ctx);
     return 0;
 }
 }}}
-- 
Ticket URL: <https://trac.ffmpeg.org/ticket/9995#comment:2>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker


More information about the FFmpeg-trac mailing list