From 3bc63f08981bbe5cb5582aba2eabf8eabcbbcd28 Mon Sep 17 00:00:00 2001 From: zlice Date: Wed, 22 Mar 2023 20:01:46 -0400 Subject: [PATCH] ccextractor: revbump for ffmpeg6 --- ...5-and-tesseract-5-compatibility-1479.patch | 168 ++++++++++++++++++ srcpkgs/ccextractor/template | 4 +- 2 files changed, 170 insertions(+), 2 deletions(-) create mode 100644 srcpkgs/ccextractor/patches/0001-fix-ffmpeg-5-and-tesseract-5-compatibility-1479.patch diff --git a/srcpkgs/ccextractor/patches/0001-fix-ffmpeg-5-and-tesseract-5-compatibility-1479.patch b/srcpkgs/ccextractor/patches/0001-fix-ffmpeg-5-and-tesseract-5-compatibility-1479.patch new file mode 100644 index 00000000000..bcab4890554 --- /dev/null +++ b/srcpkgs/ccextractor/patches/0001-fix-ffmpeg-5-and-tesseract-5-compatibility-1479.patch @@ -0,0 +1,168 @@ +From b1cbfcea9b9c687143bf0d80bc179b563e99d025 Mon Sep 17 00:00:00 2001 +From: Prateek Sunal +Date: Thu, 9 Mar 2023 01:44:53 +0530 +Subject: [PATCH] fix: ffmpeg 5 and tesseract 5 compatibility (#1479) + +* fix: replace deprecated `codec` property with `codecpar` + +* fix: replace deprecated method `avcodec_decode_video2` with `avcodec_receive_frame` and `avcodec_send_packet` + +* Update CHANGES.TXT + +* fix: remove deprecated `av_register_all` function + +* fix: formatting + +* fix: add support for tesseract 5 + +* fix: tesseract v5 + +* fix: hardsubx codec context error + +* fix: lint const warning +--- + docs/CHANGES.TXT | 1 + + src/lib_ccx/ffmpeg_intgr.c | 7 +++--- + src/lib_ccx/hardsubx.c | 25 ++++++++++++------ + src/lib_ccx/hardsubx_decoder.c | 27 ++++++++------------ + src/lib_ccx/ocr.c | 46 ++++++++++++---------------------- + 5 files changed, 47 insertions(+), 59 deletions(-) + +diff --git a/src/lib_ccx/ffmpeg_intgr.c b/src/lib_ccx/ffmpeg_intgr.c +index be988890..e6f21e20 100644 +--- a/src/lib_ccx/ffmpeg_intgr.c ++++ b/src/lib_ccx/ffmpeg_intgr.c +@@ -66,7 +66,6 @@ void *init_ffmpeg(const char *path) + struct ffmpeg_ctx *ctx; + AVCodec *dec = NULL; + avcodec_register_all(); +- av_register_all(); + + if (ccx_options.debug_mask & CCX_DMT_VERBOSE) + av_log_set_level(AV_LOG_INFO); +@@ -133,7 +132,6 @@ int ff_get_ccframe(void *arg, unsigned char *data, int maxlen) + struct ffmpeg_ctx *ctx = arg; + int len = 0; + int ret = 0; +- int got_frame; + AVPacket packet; + + ret = av_read_frame(ctx->ifmt, &packet); +@@ -151,12 +149,13 @@ int ff_get_ccframe(void *arg, unsigned char *data, int maxlen) + return AVERROR(EAGAIN); + } + +- ret = avcodec_decode_video2(ctx->dec_ctx, ctx->frame, &got_frame, &packet); ++ avcodec_send_packet(ctx->codec_ctx, &ctx->packet); ++ ret = avcodec_receive_frame(ctx->dec_ctx, ctx->frame); + if (ret < 0) + { + av_log(NULL, AV_LOG_ERROR, "unable to decode packet\n"); + } +- else if (!got_frame) ++ else if (ret != 0) + { + return AVERROR(EAGAIN); + } +diff --git a/src/lib_ccx/hardsubx.c b/src/lib_ccx/hardsubx.c +index 411377f9..fb844c91 100644 +--- a/src/lib_ccx/hardsubx.c ++++ b/src/lib_ccx/hardsubx.c +@@ -12,9 +12,6 @@ + + int hardsubx_process_data(struct lib_hardsubx_ctx *ctx) + { +- // Get the required media attributes and initialize structures +- av_register_all(); +- + if (avformat_open_input(&ctx->format_ctx, ctx->inputfile[0], NULL, NULL) != 0) + { + fatal(EXIT_READ_ERROR, "Error reading input file!\n"); +@@ -32,7 +29,7 @@ + ctx->video_stream_id = -1; + for (int i = 0; i < ctx->format_ctx->nb_streams; i++) + { +- if (ctx->format_ctx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) ++ if (ctx->format_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) + { + ctx->video_stream_id = i; + break; +@@ -43,8 +40,21 @@ + fatal(EXIT_READ_ERROR, "Video Stream not found!\n"); + } + +- ctx->codec_ctx = ctx->format_ctx->streams[ctx->video_stream_id]->codec; +- ctx->codec = avcodec_find_decoder(ctx->codec_ctx->codec_id); ++ ctx->codec_ctx = avcodec_alloc_context3(NULL); ++ if (!ctx->codec_ctx) ++ { ++ fatal(EXIT_NOT_ENOUGH_MEMORY, "Could not allocate codec context!\n"); ++ } ++ ++ // Assign codec parameters to codec context ++ if (avcodec_parameters_to_context(ctx->codec_ctx, ctx->format_ctx->streams[ctx->video_stream_id]->codecpar) < 0) ++ { ++ fatal(EXIT_READ_ERROR, "Could not initialize codec context!\n"); ++ } ++ ++ // Find decoder for the codec context ++ ctx->codec = (AVCodec *)avcodec_find_decoder(ctx->codec_ctx->codec_id); ++ + if (ctx->codec == NULL) + { + fatal(EXIT_READ_ERROR, "Input codec is not supported!\n"); +diff --git a/src/lib_ccx/hardsubx_decoder.c b/src/lib_ccx/hardsubx_decoder.c +index bd9b0980..b5dfaec4 100644 +--- a/src/lib_ccx/hardsubx_decoder.c ++++ b/src/lib_ccx/hardsubx_decoder.c +@@ -371,7 +371,6 @@ + int hardsubx_process_frames_tickertext(struct lib_hardsubx_ctx *ctx, struct encoder_ctx *enc_ctx) + { + // Search for ticker text at the bottom of the screen, such as in Russia TV1 or stock prices +- int got_frame; + int cur_sec = 0, total_sec, progress; + int frame_number = 0; + char *ticker_text = NULL; +@@ -382,8 +381,8 @@ + { + frame_number++; + //Decode the video stream packet +- avcodec_decode_video2(ctx->codec_ctx, ctx->frame, &got_frame, &ctx->packet); +- if (got_frame && frame_number % 1000 == 0) ++ avcodec_send_packet(ctx->codec_ctx, &ctx->packet); ++ if (avcodec_receive_frame(ctx->codec_ctx, ctx->frame) == 0 && frame_number % 1000 == 0) + { + // sws_scale is used to convert the pixel format to RGB24 from all other cases + sws_scale( +@@ -434,9 +433,8 @@ + frame_number++; + + //Decode the video stream packet +- avcodec_decode_video2(ctx->codec_ctx, ctx->frame, &got_frame, &ctx->packet); +- +- if (got_frame && frame_number % 25 == 0) ++ avcodec_send_packet(ctx->codec_ctx, &ctx->packet); ++ if (avcodec_receive_frame(ctx->codec_ctx, ctx->frame) == 0 && frame_number % 25 == 0) + { + float diff = (float)convert_pts_to_ms(ctx->packet.pts - prev_packet_pts, ctx->format_ctx->streams[ctx->video_stream_id]->time_base); + if (fabsf(diff) < 1000 * ctx->min_sub_duration) //If the minimum duration of a subtitle line is exceeded, process packet +@@ -548,7 +546,6 @@ + { + // Do a binary search over the input video for faster processing + // printf("Duration: %d\n", (int)ctx->format_ctx->duration); +- int got_frame; + int seconds_time = 0; + for (seconds_time = 0; seconds_time < 20; seconds_time++) + { +@@ -568,8 +565,9 @@ + { + if (ctx->packet.stream_index == ctx->video_stream_id) + { +- avcodec_decode_video2(ctx->codec_ctx, ctx->frame, &got_frame, &ctx->packet); +- if (got_frame) ++ avcodec_send_packet(ctx->codec_ctx, &ctx->packet); ++ if (avcodec_receive_frame(ctx->codec_ctx, ctx->frame) == 0) ++ + { + // printf("%d\n", seek_time); + if (ctx->packet.pts < seek_time) diff --git a/srcpkgs/ccextractor/template b/srcpkgs/ccextractor/template index 659af7e64fe..5d922ac0e44 100644 --- a/srcpkgs/ccextractor/template +++ b/srcpkgs/ccextractor/template @@ -1,12 +1,12 @@ # Template file for 'ccextractor' pkgname=ccextractor version=0.93 -revision=2 +revision=3 build_wrksrc="linux" build_style=gnu-configure configure_args="--enable-ocr --enable-hardsubx" hostmakedepends="automake pkg-config tesseract-ocr-devel" -makedepends="leptonica-devel tesseract-ocr-devel ffmpeg-devel" +makedepends="leptonica-devel tesseract-ocr-devel ffmpeg6-devel" short_desc="Extract subtitles from video streams" maintainer="newbluemoon " license="GPL-2.0-or-later"