Skip to content

Instantly share code, notes, and snippets.

@yjlcoder
Last active March 17, 2020 17:51
Show Gist options
  • Select an option

  • Save yjlcoder/4bf2fb5e4a674e39c7070bb4b77a89d8 to your computer and use it in GitHub Desktop.

Select an option

Save yjlcoder/4bf2fb5e4a674e39c7070bb4b77a89d8 to your computer and use it in GitHub Desktop.
Git patch to port qpsnr to ubuntu 18.04 (Used on bsv9/qpsnr, commit 131275c)
Package: libavformat-dev
Version: 7:4.2.2-0york0~18.04
Package: libavcodec-dev
Version: 7:4.2.2-0york0~18.04
Package: libswscale-dev
Version: 7:4.2.2-0york0~18.04
diff --git a/Makefile b/Makefile
index 9a7d8b7..13c245f 100644
--- a/Makefile
+++ b/Makefile
@@ -7,8 +7,8 @@ CPPC=g++
LINK=g++
SRCDIR=src
OBJDIR=obj
-FLAGS=-O2 -g -pthread -Wdeprecated-declarations -D__STDC_CONSTANT_MACROS -I /usr/include/ffmpeg
-LIBS=-lavcodec -lavformat -lswscale -lavutil
+FLAGS=-O2 -pthread -Wdeprecated-declarations -D__STDC_CONSTANT_MACROS -Idependencies/ffmpeg/include
+LIBS=-lswscale -lavdevice -lavformat -lavcodec -lswresample -lavutil -lrt -lz -lc -llzma -lbz2 -Idependencies/ffmpeg/include -Ldependencies/ffmpeg/lib
OBJS=$(OBJDIR)/qav.o $(OBJDIR)/stats.o $(OBJDIR)/main.o $(OBJDIR)/settings.o
EXEC=qpsnr
diff --git a/src/qav.cpp b/src/qav.cpp
index 403dc69..8780af3 100644
--- a/src/qav.cpp
+++ b/src/qav.cpp
@@ -84,7 +84,7 @@ out_height(_out_height), pFormatCtx(NULL), pCodecCtx(NULL), pCodec(NULL), pFrame
if (out_width!=pCodecCtx->width || out_height!=pCodecCtx->height)
LOG_WARNING << "Video (" << file <<") will get scaled: " << pCodecCtx->width << 'x' << pCodecCtx->height << " (in), " << out_width << 'x' << out_height << " (out)" << std::endl;
- img_convert_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt, out_width, out_height, PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL);
+ img_convert_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt, out_width, out_height, AV_PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL);
if (!img_convert_ctx) {
free_resources();
throw std::runtime_error("Can't allocated sw_scale context");
@@ -102,7 +102,7 @@ int qav::qvideo::get_fps_k(void) const {
}
bool qav::qvideo::get_frame(std::vector<unsigned char>& out, int *_frnum, const bool skip) {
- out.resize(avpicture_get_size(PIX_FMT_RGB24, out_width, out_height));
+ out.resize(avpicture_get_size(AV_PIX_FMT_RGB24, out_width, out_height));
AVPacket packet;
bool is_read = false;
av_init_packet(&packet);
@@ -119,7 +119,7 @@ bool qav::qvideo::get_frame(std::vector<unsigned char>& out, int *_frnum, const
if (!skip) {
AVPicture picRGB;
// Assign appropriate parts of buffer to image planes in pFrameRGB
- avpicture_fill((AVPicture*)&picRGB, (unsigned char*)&out[0], PIX_FMT_RGB24, out_width, out_height);
+ avpicture_fill((AVPicture*)&picRGB, (unsigned char*)&out[0], AV_PIX_FMT_RGB24, out_width, out_height);
// Convert the image from its native format to RGB
sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height, picRGB.data, picRGB.linesize);
if (settings::SAVE_IMAGES)
diff --git a/src/qav.h b/src/qav.h
index e1cdfc4..57e4db4 100644
--- a/src/qav.h
+++ b/src/qav.h
@@ -30,6 +30,8 @@ extern "C" {
#include <string>
#include <vector>
+#define avcodec_alloc_frame av_frame_alloc
+
namespace qav {
struct scr_size {
int x;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment