[arch-commits] Commit in unpaper/repos (3 files)
Antonio Rojas
arojas at gemini.archlinux.org
Fri Jan 28 18:27:46 UTC 2022
Date: Friday, January 28, 2022 @ 18:27:46
Author: arojas
Revision: 1118376
archrelease: copy trunk to community-staging-x86_64
Added:
unpaper/repos/community-staging-x86_64/
unpaper/repos/community-staging-x86_64/PKGBUILD
(from rev 1118375, unpaper/trunk/PKGBUILD)
unpaper/repos/community-staging-x86_64/ffmpeg5.patch
(from rev 1118375, unpaper/trunk/ffmpeg5.patch)
---------------+
PKGBUILD | 37 +++++++++
ffmpeg5.patch | 225 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 262 insertions(+)
Copied: unpaper/repos/community-staging-x86_64/PKGBUILD (from rev 1118375, unpaper/trunk/PKGBUILD)
===================================================================
--- community-staging-x86_64/PKGBUILD (rev 0)
+++ community-staging-x86_64/PKGBUILD 2022-01-28 18:27:46 UTC (rev 1118376)
@@ -0,0 +1,37 @@
+# Maintainer: Sergej Pupykin <pupykin.s+arch at gmail.com>
+# Contributor: Andreas Hauser <andy-aur at splashground.de>
+
+pkgname=unpaper
+pkgver=6.1
+pkgrel=8
+pkgdesc="post-processing tool for scanned sheets of paper"
+arch=('x86_64')
+url="https://github.com/Flameeyes/unpaper"
+license=("GPL")
+depends=('ffmpeg')
+makedepends=('libxslt')
+source=("$pkgname-${pkgver}.tar.gz::https://github.com/Flameeyes/unpaper/archive/unpaper-$pkgver.tar.gz"
+ ffmpeg5.patch)
+sha256sums=('213f8143b3361dde3286537eb66aaf7cdd7e4f5e7bde42ac6e91020997a81f1d'
+ '4bc67a04e5305c983dc973ef99628259a0f93e7b153ff4996bd73ece3c7698b1')
+
+prepare() {
+ cd "$srcdir"/unpaper-unpaper-$pkgver
+ aclocal
+ automake --add-missing
+ autoconf
+
+# Fix build with FFmpeg 5
+ patch -p1 -i ../ffmpeg5.patch
+}
+
+build() {
+ cd "$srcdir"/unpaper-unpaper-$pkgver
+ ./configure --prefix=/usr
+ make
+}
+
+package() {
+ cd "$srcdir"/unpaper-unpaper-$pkgver
+ make install DESTDIR="$pkgdir"
+}
Copied: unpaper/repos/community-staging-x86_64/ffmpeg5.patch (from rev 1118375, unpaper/trunk/ffmpeg5.patch)
===================================================================
--- community-staging-x86_64/ffmpeg5.patch (rev 0)
+++ community-staging-x86_64/ffmpeg5.patch 2022-01-28 18:27:46 UTC (rev 1118376)
@@ -0,0 +1,225 @@
+diff --git a/file.c b/file.c
+index c92994d..f75dc82 100644
+--- a/file.c
++++ b/file.c
+@@ -19,11 +19,9 @@
+
+ /* --- tool functions for file handling ------------------------------------ */
+
+-#include <stdlib.h>
+ #include <stdint.h>
+ #include <stdio.h>
+ #include <string.h>
+-#include <assert.h>
+
+ #include <libavcodec/avcodec.h>
+ #include <libavformat/avformat.h>
+@@ -40,17 +38,14 @@
+ * @param type returns the type of the loaded image
+ */
+ void loadImage(const char *filename, AVFrame **image) {
+- int ret, got_frame = 0;
+ AVFormatContext *s = NULL;
+- AVCodecContext *avctx = avcodec_alloc_context3(NULL);
+- AVCodec *codec;
++ AVCodecContext *ctx = NULL;
++ const AVCodec *codec = NULL;
+ AVPacket pkt;
+ AVFrame *frame = av_frame_alloc();
++ int ret;
+ char errbuff[1024];
+
+- if (!avctx)
+- errOutput("cannot allocate a new context");
+-
+ ret = avformat_open_input(&s, filename, NULL, NULL);
+ if (ret < 0) {
+ av_strerror(ret, errbuff, sizeof(errbuff));
+@@ -65,20 +60,23 @@ void loadImage(const char *filename, AVFrame **image) {
+ if (s->nb_streams < 1)
+ errOutput("unable to open file %s: missing streams", filename);
+
+- if (s->streams[0]->codec->codec_type != AVMEDIA_TYPE_VIDEO)
+- errOutput("unable to open file %s: wrong stream", filename);
++ codec = avcodec_find_decoder(s->streams[0]->codecpar->codec_id);
++ if (!codec) {
++ errOutput("unable to open file %s: unsupported format", filename);
++ }
+
+- ret = avcodec_copy_context(avctx, s->streams[0]->codec);
+- if (ret < 0) {
+- av_strerror(ret, errbuff, sizeof(errbuff));
+- errOutput("cannot set the new context for %s: %s", filename, errbuff);
++ ctx = avcodec_alloc_context3(codec);
++ if (!ctx) {
++ errOutput("cannot allocate decoder context for %s", filename);
+ }
+
+- codec = avcodec_find_decoder(avctx->codec_id);
+- if (!codec)
+- errOutput("unable to open file %s: unsupported format", filename);
++ ret = avcodec_parameters_to_context(ctx, s->streams[0]->codecpar);
++ if (ret < 0) {
++ av_strerror(ret, errbuff, sizeof errbuff);
++ errOutput("unable to copy parameters to context: %s", errbuff);
++ }
+
+- ret = avcodec_open2(avctx, codec, NULL);
++ ret = avcodec_open2(ctx, codec, NULL);
+ if (ret < 0) {
+ av_strerror(ret, errbuff, sizeof(errbuff));
+ errOutput("unable to open file %s: %s", filename, errbuff);
+@@ -93,10 +91,16 @@ void loadImage(const char *filename, AVFrame **image) {
+ if (pkt.stream_index != 0)
+ errOutput("unable to open file %s: invalid stream.", filename);
+
+- ret = avcodec_decode_video2(avctx, frame, &got_frame, &pkt);
++ ret = avcodec_send_packet(ctx, &pkt);
+ if (ret < 0) {
+- av_strerror(ret, errbuff, sizeof(errbuff));
+- errOutput("unable to open file %s: %s", filename, errbuff);
++ av_strerror(ret, errbuff, sizeof errbuff);
++ errOutput("cannot send packet to decoder: %s", errbuff);
++ }
++
++ ret = avcodec_receive_frame(ctx, frame);
++ if (ret < 0) {
++ av_strerror(ret, errbuff, sizeof errbuff);
++ errOutput("error while receiving frame from decoder: %s", errbuff);
+ }
+
+ switch(frame->format) {
+@@ -123,6 +127,7 @@ void loadImage(const char *filename, AVFrame **image) {
+ default:
+ errOutput("unable to open file %s: unsupported pixel format", filename);
+ }
++ avcodec_free_context(&ctx);
+ }
+
+
+@@ -135,12 +140,13 @@ void loadImage(const char *filename, AVFrame **image) {
+ * @return true on success, false on failure
+ */
+ void saveImage(char *filename, AVFrame *image, int outputPixFmt) {
+- AVOutputFormat *fmt = NULL;
+- enum AVCodecID output_codec = -1;
+- AVCodec *codec;
+- AVFormatContext *out_ctx;
+- AVCodecContext *codec_ctx;
+- AVStream *video_st;
++ const AVOutputFormat *fmt = NULL;
++ enum AVCodecID output_codec;
++ const AVCodec *codec = NULL;
++ AVFormatContext *out_ctx = NULL;
++ AVCodecContext *codec_ctx = NULL;
++ AVStream *video_st = NULL;
++ AVPacket *pkt = NULL;
+ int ret;
+ char errbuff[1024];
+
+@@ -156,7 +162,7 @@ void saveImage(char *filename, AVFrame *image, int outputPixFmt) {
+ }
+
+ out_ctx->oformat = fmt;
+- snprintf(out_ctx->filename, sizeof(out_ctx->filename), "%s", filename);
++ out_ctx->url = av_strdup(filename);
+
+ switch (outputPixFmt) {
+ case AV_PIX_FMT_RGB24:
+@@ -193,10 +199,17 @@ void saveImage(char *filename, AVFrame *image, int outputPixFmt) {
+ errOutput("could not alloc output stream");
+ }
+
+- codec_ctx = video_st->codec;
++ codec_ctx = avcodec_alloc_context3(codec);
++ if (!codec_ctx) {
++ errOutput("could not alloc codec context");
++ }
++
+ codec_ctx->width = image->width;
+ codec_ctx->height = image->height;
+ codec_ctx->pix_fmt = image->format;
++ video_st->codecpar->width = image->width;
++ video_st->codecpar->height = image->height;
++ video_st->codecpar->format = image->format;
+ video_st->time_base.den = codec_ctx->time_base.den = 1;
+ video_st->time_base.num = codec_ctx->time_base.num = 1;
+
+@@ -210,33 +223,38 @@ void saveImage(char *filename, AVFrame *image, int outputPixFmt) {
+ if (verbose >= VERBOSE_MORE)
+ av_dump_format(out_ctx, 0, filename, 1);
+
+- if (avio_open(&out_ctx->pb, filename, AVIO_FLAG_WRITE) < 0) {
+- errOutput("could not open '%s'", filename);
++ if ((ret = avio_open(&out_ctx->pb, filename, AVIO_FLAG_WRITE)) < 0) {
++ av_strerror(ret, errbuff, sizeof errbuff);
++ errOutput("cannot alloc I/O context for %s: %s", filename, errbuff);
+ }
+
+- avformat_write_header(out_ctx, NULL);
++ if ((ret = avformat_write_header(out_ctx, NULL)) < 0) {
++ av_strerror(ret, errbuff, sizeof errbuff);
++ errOutput("error writing header to '%s': %s", filename, errbuff);
+
+- AVPacket pkt = { 0 };
+- int got_packet;
+- av_init_packet(&pkt);
++ pkt = av_packet_alloc();
++ if (!pkt) {
++ errOutput("unable to allocate output packet");
++ }
+
+- /* encode the image */
+- ret = avcodec_encode_video2(video_st->codec, &pkt, image, &got_packet);
++ ret = avcodec_send_frame(codec_ctx, image);
++ if (ret < 0) {
++ av_strerror(ret, errbuff, sizeof errbuff);
++ errOutput("unable to send frame to encoder: %s", errbuff);
++ }
+
++ ret = avcodec_receive_packet(codec_ctx, pkt);
+ if (ret < 0) {
+ av_strerror(ret, errbuff, sizeof(errbuff));
+ errOutput("unable to write file %s: %s", filename, errbuff);
+ }
+- av_write_frame(out_ctx, &pkt);
++ av_write_frame(out_ctx, pkt);
+
+ av_write_trailer(out_ctx);
+- avcodec_close(codec_ctx);
+-
+- av_free(codec_ctx);
+- av_free(video_st);
+-
+- avio_close(out_ctx->pb);
+- av_free(out_ctx);
++ av_packet_free(&pkt);
++ avcodec_free_context(&codec_ctx);
++ avformat_free_context(out_ctx);
++ }
+ }
+
+ /**
+diff --git a/unpaper.c b/unpaper.c
+index d3d91ad..0220f70 100644
+--- a/unpaper.c
++++ b/unpaper.c
+@@ -28,8 +28,6 @@
+
+ #include <sys/stat.h>
+
+-#include <libavcodec/avcodec.h>
+-#include <libavformat/avformat.h>
+ #include <libavutil/avutil.h>
+
+ #include "unpaper.h"
+@@ -944,9 +942,6 @@ int main(int argc, char* argv[]) {
+ deskewScanStepRad = degreesToRadians(deskewScanStep);
+ deskewScanDeviationRad = degreesToRadians(deskewScanDeviation);
+
+- avcodec_register_all();
+- av_register_all();
+-
+ for (int nr = startSheet; (endSheet == -1) || (nr <= endSheet); nr++) {
+ char inputFilesBuffer[2][255];
+ char outputFilesBuffer[2][255];
More information about the arch-commits
mailing list