From patchwork Sun Sep 12 03:21:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Soft Works X-Patchwork-Id: 30170 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp2862967iov; Sat, 11 Sep 2021 20:22:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3cqaIEBmuRM6O1zWlHsNKNXaQxb0GpkbhVRDL/fWtP7xCZIPPp6I3S/rtwOcXi/L3oL1q X-Received: by 2002:a05:6402:2810:: with SMTP id h16mr6051176ede.133.1631416940125; Sat, 11 Sep 2021 20:22:20 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id i23si3386669edv.93.2021.09.11.20.22.19; Sat, 11 Sep 2021 20:22:20 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@hotmail.com header.s=selector1 header.b=jI4Im4gj; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=hotmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6AD7068A990; Sun, 12 Sep 2021 06:21:55 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10olkn2062.outbound.protection.outlook.com [40.92.41.62]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C61C168A927 for ; Sun, 12 Sep 2021 06:21:48 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cT6K3N2HVfs0Zy2ZwOvATBu065kGw18ypHcg8OZyTqA5qr+lrJR9uMUo9xui8d5Bhlglhaxzh+AT58hABMlzu5GdM/4JtAL/EQhVjveJcs7+PYmi3sYalIr4cgwsgSTy6OIQ5eM4eN0Izo1Tmip/G4kcfaSDCYJFgsdK+DWzr6IpvHWdSJ9MZvOItX6XFRZsAqfgTloVFyUN7zjddTcO3fTp7EW7kXCKwQCEcvC4gkabSsViGhvVkckPSmYoIbQanli+8+CBo4KZwpQwM5nuHBLTFuGYz9YheSkollwuR1RtW6p9HMLymi21vWnARPO9AvkMbr7a3EQ8FImeThTL6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=CTnr2xAACyWYuhVgVKxLbRv+CTzIHqRhTayCAOK/PiM=; b=Bb58Fr/Hs2oWWIIyE1K3iyFtyQ7R6p1RrYQt0y4xkBJbJDBJIFd3cqu1J+AJtlrdjgUbv5TE4FbZCoqSo18wcFdWgqzIOMn+YlVb+otrP7oyira5oM3TS9o/e810/sqk5LnULFS9Ebwvm1gUXbRVR/BwVbPede8nmMbvlZoGtgGi9rYkMpqF9fnMdeAxS8vk9zSRY3aMDKcw7Fu0mneceLdse0VXppVd8ZRNFgHrMl/jZvhGj85nqivcILX9+kGrIg7imiVDljrTMjfeZ4zJiVYy+8fQGl7F1f7owneFfTp0q9rPrb2x3SqW5dpCdCFhqTEw2uejbabN3p55zkVOxw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CTnr2xAACyWYuhVgVKxLbRv+CTzIHqRhTayCAOK/PiM=; b=jI4Im4gj5yHifH+UvgtoN1KFReBl/dmVaKyTHdniRU+3HgMlCG9sU4jUPMhPVpr1jrVVuW/whTxhUmMXVQ6dOZUP4aaG01UT/ZcbrBRLKeO1gISjsBZ2XNkDHXnfbQAAdtGCxIpjgsVWXnqXqbOCywbWKYH0yj3mp3zHQfA82apkGFXb/H4IxwWH1EqVGOWcmSRKrVd4tizq0D/PweNB1E7I46bUWkcq/aj/RvgepZ2YEzq7myBAkNwL2f87Xq2WIfrWz0gphVMz5r+TDzh3AMthywcQToKSmPR6vcPtWmXtqYob7V5w1lv7Guk80Jqp9WPprZD2LJsb/B+XQLJ6pg== Received: from MN2PR04MB5981.namprd04.prod.outlook.com (2603:10b6:208:da::10) by MN2PR04MB5728.namprd04.prod.outlook.com (2603:10b6:208:3d::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14; Sun, 12 Sep 2021 03:21:40 +0000 Received: from MN2PR04MB5981.namprd04.prod.outlook.com ([fe80::ecfe:2528:2012:22cb]) by MN2PR04MB5981.namprd04.prod.outlook.com ([fe80::ecfe:2528:2012:22cb%5]) with mapi id 15.20.4500.018; Sun, 12 Sep 2021 03:21:40 +0000 From: Soft Works To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [PATCH v5 03/12] fftools/play, probe: Adjust for subtitle format type change Thread-Index: AQHXp4VNWN7hl5mljk2QvECa/KqKaA== Date: Sun, 12 Sep 2021 03:21:40 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [ZtFrtEOtlGU1EXSA0IxCskSYgBh7+a67939tK/XsTj8=] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 4f8127b6-831d-4843-dbe3-08d9759c6fec x-ms-traffictypediagnostic: MN2PR04MB5728: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: JjxTq/PmnitAYpAfK/aQMZy7X57DHgeGdZ0oe3yJTNNk2MeRsS1hSsBEHeFOjDtY1lpt3HpFzc3xAURSK9n7LJd7tA2BhRT8AEqC23mctnX+PtpNHUqXquoszjKiXAuuKqPflll0GpaCrr0xEr4ATQosogMQ/KcNrqVvJ2+meyglYC1Svz93/DjVgkF3HeEnMomIPlz+rI3+1WFKMHHDvn+et4Oxyovc5CjMz2O5ONwSl5Cxk0Hz5qMAqdQCirb1rmjI0p65YUkj/nF6EGy2CIoFIJMrDiu8X9nolGb6gpilvjM/M3hEYs2p9y4PC6hSYvrPVKuT4maqGTkCNzBete6OyBSJiwovY3kynV9/kZcSGOJhHTXwjTlc9m9XtSIDog3aSSNAC+6HygLv1tzZPD+E1KFwska5I2LoFrN9eOWFq0OqKxFbPz4/Ed+q/tyW x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: o1+itOcmrfDJ6ARVw5W8fwpIjlDl8LyBvTAu96xUVwznu2lIVV8ueobWJYwej4aULYHlZzkDNV7sazuKMLJlfhdgSuH027tPRX40wOo0srhssLcIjBHeEzNQQNUHaRRGqvPej+AUPCAcUEHEOQXjGQ== x-ms-exchange-transport-forked: True MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-3174-20-msonline-outlook-529c7.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MN2PR04MB5981.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 4f8127b6-831d-4843-dbe3-08d9759c6fec X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Sep 2021 03:21:40.2207 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR04MB5728 Subject: [FFmpeg-devel] [PATCH v5 03/12] fftools/play, probe: Adjust for subtitle format type change X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: mewjOoy6NphN Signed-off-by: softworkz --- fftools/ffplay.c | 30 ++++++++++++++--------------- fftools/ffprobe.c | 49 +++++++++++++++++++++++++++++++++++------------ 2 files changed, 51 insertions(+), 28 deletions(-) diff --git a/fftools/ffplay.c b/fftools/ffplay.c index 46758b9f55..b1cb44e804 100644 --- a/fftools/ffplay.c +++ b/fftools/ffplay.c @@ -152,7 +152,6 @@ typedef struct Clock { /* Common struct for handling all types of decoded data and allocated render buffers. */ typedef struct Frame { AVFrame *frame; - AVSubtitle sub; int serial; double pts; /* presentation timestamp for the frame */ double duration; /* estimated duration of the frame */ @@ -586,7 +585,7 @@ static int decoder_init(Decoder *d, AVCodecContext *avctx, PacketQueue *queue, S return 0; } -static int decoder_decode_frame(Decoder *d, AVFrame *frame, AVSubtitle *sub) { +static int decoder_decode_frame(Decoder *d, AVFrame *frame, AVFrame *sub) { int ret = AVERROR(EAGAIN); for (;;) { @@ -683,7 +682,6 @@ static void decoder_destroy(Decoder *d) { static void frame_queue_unref_item(Frame *vp) { av_frame_unref(vp->frame); - avsubtitle_free(&vp->sub); } static int frame_queue_init(FrameQueue *f, PacketQueue *pktq, int max_size, int keep_last) @@ -981,7 +979,7 @@ static void video_image_display(VideoState *is) if (frame_queue_nb_remaining(&is->subpq) > 0) { sp = frame_queue_peek(&is->subpq); - if (vp->pts >= sp->pts + ((float) sp->sub.start_display_time / 1000)) { + if (vp->pts >= sp->pts + ((float) sp->frame->subtitle_start_time / 1000)) { if (!sp->uploaded) { uint8_t* pixels[4]; int pitch[4]; @@ -993,8 +991,8 @@ static void video_image_display(VideoState *is) if (realloc_texture(&is->sub_texture, SDL_PIXELFORMAT_ARGB8888, sp->width, sp->height, SDL_BLENDMODE_BLEND, 1) < 0) return; - for (i = 0; i < sp->sub.num_rects; i++) { - AVSubtitleRect *sub_rect = sp->sub.rects[i]; + for (i = 0; i < sp->frame->num_subtitle_rects; i++) { + AVSubtitleRect *sub_rect = sp->frame->subtitle_rects[i]; sub_rect->x = av_clip(sub_rect->x, 0, sp->width ); sub_rect->y = av_clip(sub_rect->y, 0, sp->height); @@ -1041,7 +1039,7 @@ static void video_image_display(VideoState *is) int i; double xratio = (double)rect.w / (double)sp->width; double yratio = (double)rect.h / (double)sp->height; - for (i = 0; i < sp->sub.num_rects; i++) { + for (i = 0; i < sp->sub.num_subtitle_rects; i++) { SDL_Rect *sub_rect = (SDL_Rect*)sp->sub.rects[i]; SDL_Rect target = {.x = rect.x + sub_rect->x * xratio, .y = rect.y + sub_rect->y * yratio, @@ -1651,13 +1649,13 @@ retry: sp2 = NULL; if (sp->serial != is->subtitleq.serial - || (is->vidclk.pts > (sp->pts + ((float) sp->sub.end_display_time / 1000))) - || (sp2 && is->vidclk.pts > (sp2->pts + ((float) sp2->sub.start_display_time / 1000)))) + || (is->vidclk.pts > (sp->pts + ((float) sp->frame->subtitle_end_time / 1000))) + || (sp2 && is->vidclk.pts > (sp2->pts + ((float) sp2->frame->subtitle_start_time / 1000)))) { if (sp->uploaded) { int i; - for (i = 0; i < sp->sub.num_rects; i++) { - AVSubtitleRect *sub_rect = sp->sub.rects[i]; + for (i = 0; i < sp->frame->num_subtitle_rects; i++) { + AVSubtitleRect *sub_rect = sp->frame->subtitle_rects[i]; uint8_t *pixels; int pitch, j; @@ -2245,14 +2243,14 @@ static int subtitle_thread(void *arg) if (!(sp = frame_queue_peek_writable(&is->subpq))) return 0; - if ((got_subtitle = decoder_decode_frame(&is->subdec, NULL, &sp->sub)) < 0) + if ((got_subtitle = decoder_decode_frame(&is->subdec, NULL, sp->frame)) < 0) break; pts = 0; - if (got_subtitle && sp->sub.format == 0) { - if (sp->sub.pts != AV_NOPTS_VALUE) - pts = sp->sub.pts / (double)AV_TIME_BASE; + if (got_subtitle && sp->frame->format == AV_SUBTITLE_FMT_BITMAP) { + if (sp->frame->subtitle_pts != AV_NOPTS_VALUE) + pts = sp->frame->subtitle_pts / (double)AV_TIME_BASE; sp->pts = pts; sp->serial = is->subdec.pkt_serial; sp->width = is->subdec.avctx->width; @@ -2262,7 +2260,7 @@ static int subtitle_thread(void *arg) /* now we can update the picture count */ frame_queue_push(&is->subpq); } else if (got_subtitle) { - avsubtitle_free(&sp->sub); + av_frame_free(&sp->frame); } } return 0; diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index acfec09656..5e899a09db 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -2208,22 +2208,43 @@ static void show_packet(WriterContext *w, InputFile *ifile, AVPacket *pkt, int p fflush(stdout); } -static void show_subtitle(WriterContext *w, AVSubtitle *sub, AVStream *stream, +static void show_subtitle(WriterContext *w, AVFrame *sub, AVStream *stream, AVFormatContext *fmt_ctx) { AVBPrint pbuf; + const char *s; av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED); writer_print_section_header(w, SECTION_ID_SUBTITLE); print_str ("media_type", "subtitle"); - print_ts ("pts", sub->pts); - print_time("pts_time", sub->pts, &AV_TIME_BASE_Q); - print_int ("format", sub->format); - print_int ("start_display_time", sub->start_display_time); - print_int ("end_display_time", sub->end_display_time); - print_int ("num_rects", sub->num_rects); + print_ts ("pts", sub->subtitle_pts); + print_time("pts_time", sub->subtitle_pts, &AV_TIME_BASE_Q); + + // Remain compatible with previous outputs? + switch (sub->format) { + case AV_SUBTITLE_FMT_BITMAP: + print_int ("format", 0); + break; + case AV_SUBTITLE_FMT_TEXT: + print_int ("format", 1); + break; + case AV_SUBTITLE_FMT_ASS: + print_int ("format", 1); + break; + default: + print_int ("format", -1); + break; + } + + s = av_get_subtitle_fmt_name(sub->format); + if (s) print_str ("format_str", s); + else print_str_opt("format_str", "unknown"); + + print_int ("start_display_time", sub->subtitle_start_time); + print_int ("end_display_time", sub->subtitle_end_time); + print_int ("num_subtitle_rects", sub->num_subtitle_rects); writer_print_section_footer(w); @@ -2388,7 +2409,7 @@ static av_always_inline int process_frame(WriterContext *w, AVFormatContext *fmt_ctx = ifile->fmt_ctx; AVCodecContext *dec_ctx = ifile->streams[pkt->stream_index].dec_ctx; AVCodecParameters *par = ifile->streams[pkt->stream_index].st->codecpar; - AVSubtitle sub; + AVFrame *sub = NULL; int ret = 0, got_frame = 0; clear_log(1); @@ -2416,8 +2437,12 @@ static av_always_inline int process_frame(WriterContext *w, break; case AVMEDIA_TYPE_SUBTITLE: - if (*packet_new) - ret = avcodec_decode_subtitle2(dec_ctx, &sub, &got_frame, pkt); + if (*packet_new) { + sub = av_frame_alloc(); + if (!sub) + return AVERROR(ENOMEM); + ret = avcodec_decode_subtitle2(dec_ctx, sub, &got_frame, pkt); + } *packet_new = 0; break; default: @@ -2434,11 +2459,11 @@ static av_always_inline int process_frame(WriterContext *w, nb_streams_frames[pkt->stream_index]++; if (do_show_frames) if (is_sub) - show_subtitle(w, &sub, ifile->streams[pkt->stream_index].st, fmt_ctx); + show_subtitle(w, sub, ifile->streams[pkt->stream_index].st, fmt_ctx); else show_frame(w, frame, ifile->streams[pkt->stream_index].st, fmt_ctx); if (is_sub) - avsubtitle_free(&sub); + av_frame_free(&sub); } return got_frame || *packet_new; }