Compare commits

..

No commits in common. "49071365f7ed0316000077f989fdca5cbf5939ba" and "41c291f51ccd4b9579e4268f6d3cab3cbf1b659a" have entirely different histories.

7 changed files with 30 additions and 73 deletions

View file

@ -40,6 +40,3 @@ target_link_libraries(DitheringProject PUBLIC
${PNG_LIBRARIES}
${FFMPEG_LIBAVCODEC_LINK_LIBRARIES}
)
target_compile_definitions(DitheringProject PRIVATE
CL_TARGET_OPENCL_VERSION=300)

View file

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2021-2024 Stephen Seo
Copyright (c) 2021 Stephen Seo
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View file

@ -6,9 +6,9 @@
of the course. Newer versions are meant to be maintenance releases; fixes that
keep the project working. As of 2022-01-18, there may be (after now) a version
`1.1.0` or `1.0.1` due to keeping up to date with the FFmpeg dependency as a new
major version of FFmpeg was released (version `5.0`).~~
major version of FFmpeg was released (version `5.0`).
~~To be clear, version `1.0.0` of this project is expected to work with FFmpeg
To be clear, version `1.0.0` of this project is expected to work with FFmpeg
version `4.4`.~~
Fixes were applied for FFmpeg version 5. A macro is used to change incompatible

View file

@ -7,7 +7,6 @@ Args::Args()
: do_dither_image_(true),
do_dither_grayscaled_(false),
do_overwrite_(false),
do_video_pngs_(false),
input_filename(),
output_filename() {}

View file

@ -694,33 +694,18 @@ OpenCLContext::OpenCLContext() : context_(nullptr), queue_(nullptr) {
//////////////////// set up cl_context
cl_int err_num;
cl_uint num_platforms;
std::vector<cl_platform_id> platform_ids;
cl_platform_id first_platform_id;
err_num = clGetPlatformIDs(0, nullptr, &num_platforms);
if (err_num != CL_SUCCESS) {
std::cout << "ERROR: OpenCLContext: Failed to query OpenCL platforms"
<< std::endl;
return;
} else if (num_platforms == 0) {
err_num = clGetPlatformIDs(1, &first_platform_id, &num_platforms);
if (err_num != CL_SUCCESS || num_platforms == 0) {
std::cout << "ERROR: OpenCLContext: Failed to find any OpenCL platforms"
<< std::endl;
return;
}
platform_ids.resize(num_platforms);
err_num = clGetPlatformIDs(num_platforms, platform_ids.data(), nullptr);
if (err_num != CL_SUCCESS) {
std::cout << "ERROR: OpenCLContext: Failed to get OpenCL platform id(s)"
<< std::endl;
return;
}
bool success = false;
for (cl_uint i = 0; i < num_platforms; ++i) {
cl_context_properties context_properties[] = {
CL_CONTEXT_PLATFORM,
reinterpret_cast<cl_context_properties>(platform_ids[i]), 0};
reinterpret_cast<cl_context_properties>(first_platform_id), 0};
context_ = clCreateContextFromType(context_properties, CL_DEVICE_TYPE_GPU,
nullptr, nullptr, &err_num);
@ -734,19 +719,8 @@ OpenCLContext::OpenCLContext() : context_(nullptr), queue_(nullptr) {
std::cout << "ERROR: OpenCLContext: Failed to create CPU context"
<< std::endl;
context_ = nullptr;
continue;
} else {
success = true;
break;
return;
}
} else {
success = true;
break;
}
}
if (!success) {
std::cout << "ERROR: OpenCLContext: Failed to find a valid OpenCL context!"
<< std::endl;
}
//////////////////// end set up cl context
@ -780,8 +754,7 @@ OpenCLContext::OpenCLContext() : context_(nullptr), queue_(nullptr) {
}
// uses first available device
queue_ = clCreateCommandQueueWithProperties(context_, devices.at(0), nullptr,
&err_num);
queue_ = clCreateCommandQueue(context_, devices.at(0), 0, &err_num);
if (err_num != CL_SUCCESS) {
std::cout << "ERROR: OpenCLContext: Failed to create command queue"
<< std::endl;

View file

@ -265,7 +265,7 @@ bool Video::DitherVideo(const std::string &output_filename, Image *blue_noise,
return_value = avcodec_open2(enc_codec_context, enc_codec, nullptr);
if (return_value != 0) {
std::cout << "ERROR: Failed to init enc_codec_context" << std::endl;
IGPUP_DITHERING_avcodec_close_ctx(&enc_codec_context);
avcodec_close(enc_codec_context);
avformat_free_context(avf_enc_context);
av_frame_free(&frame);
av_packet_free(&pkt);
@ -279,7 +279,7 @@ bool Video::DitherVideo(const std::string &output_filename, Image *blue_noise,
if (return_value < 0) {
std::cout << "ERROR: Failed to set encoding codec parameters in stream"
<< std::endl;
IGPUP_DITHERING_avcodec_close_ctx(&enc_codec_context);
avcodec_close(enc_codec_context);
avformat_free_context(avf_enc_context);
av_frame_free(&frame);
av_packet_free(&pkt);
@ -298,7 +298,7 @@ bool Video::DitherVideo(const std::string &output_filename, Image *blue_noise,
if (return_value < 0) {
std::cout << "ERROR: Failed to open file \"" << output_filename
<< "\" for writing" << std::endl;
IGPUP_DITHERING_avcodec_close_ctx(&enc_codec_context);
avcodec_close(enc_codec_context);
avformat_free_context(avf_enc_context);
av_frame_free(&frame);
av_packet_free(&pkt);
@ -313,7 +313,7 @@ bool Video::DitherVideo(const std::string &output_filename, Image *blue_noise,
if (return_value < 0) {
std::cout << "ERROR: Failed to write header in output video file"
<< std::endl;
IGPUP_DITHERING_avcodec_close_ctx(&enc_codec_context);
avcodec_close(enc_codec_context);
avformat_free_context(avf_enc_context);
av_frame_free(&frame);
av_packet_free(&pkt);
@ -332,7 +332,7 @@ bool Video::DitherVideo(const std::string &output_filename, Image *blue_noise,
HandleDecodingPacket(codec_ctx, pkt, frame, blue_noise, grayscale,
color_changed, output_as_pngs);
if (!std::get<0>(ret_tuple)) {
IGPUP_DITHERING_avcodec_close_ctx(&enc_codec_context);
avcodec_close(enc_codec_context);
avformat_free_context(avf_enc_context);
av_frame_free(&frame);
av_packet_unref(pkt);
@ -345,7 +345,7 @@ bool Video::DitherVideo(const std::string &output_filename, Image *blue_noise,
if (!HandleEncodingFrame(avf_enc_context, enc_codec_context,
yuv_frame, enc_stream)) {
av_frame_free(&yuv_frame);
IGPUP_DITHERING_avcodec_close_ctx(&enc_codec_context);
avcodec_close(enc_codec_context);
avformat_free_context(avf_enc_context);
av_frame_free(&frame);
av_packet_unref(pkt);
@ -366,7 +366,7 @@ bool Video::DitherVideo(const std::string &output_filename, Image *blue_noise,
HandleDecodingPacket(codec_ctx, nullptr, frame, blue_noise, grayscale,
color_changed, output_as_pngs);
if (!std::get<0>(ret_tuple)) {
IGPUP_DITHERING_avcodec_close_ctx(&enc_codec_context);
avcodec_close(enc_codec_context);
avformat_free_context(avf_enc_context);
av_frame_free(&frame);
av_packet_free(&pkt);
@ -378,7 +378,7 @@ bool Video::DitherVideo(const std::string &output_filename, Image *blue_noise,
if (!HandleEncodingFrame(avf_enc_context, enc_codec_context, yuv_frame,
enc_stream)) {
av_frame_free(&yuv_frame);
IGPUP_DITHERING_avcodec_close_ctx(&enc_codec_context);
avcodec_close(enc_codec_context);
avformat_free_context(avf_enc_context);
av_frame_free(&frame);
av_packet_free(&pkt);
@ -394,7 +394,7 @@ bool Video::DitherVideo(const std::string &output_filename, Image *blue_noise,
// flush encoder
if (!HandleEncodingFrame(avf_enc_context, enc_codec_context, nullptr,
enc_stream)) {
IGPUP_DITHERING_avcodec_close_ctx(&enc_codec_context);
avcodec_close(enc_codec_context);
avformat_free_context(avf_enc_context);
av_frame_free(&frame);
av_packet_free(&pkt);
@ -409,7 +409,7 @@ bool Video::DitherVideo(const std::string &output_filename, Image *blue_noise,
// cleanup
if (enc_codec_context) {
IGPUP_DITHERING_avcodec_close_ctx(&enc_codec_context);
avcodec_close(enc_codec_context);
}
if (!output_as_pngs && !(avf_enc_context->oformat->flags & AVFMT_NOFILE)) {
avio_closep(&avf_enc_context->pb);
@ -614,11 +614,7 @@ std::tuple<bool, std::vector<AVFrame *>> Video::HandleDecodingPacket(
// cleanup
av_frame_free(&temp_frame);
yuv_frame->pts = frame_count_ - 1;
#if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(58, 2, 100)
yuv_frame->pkt_duration = 1;
#else
yuv_frame->duration = 1;
#endif
return_frames.push_back(yuv_frame);
} // else (!output_as_pngs)
} // while (return_value >= 0)

View file

@ -11,14 +11,6 @@ extern "C" {
#include "image.h"
inline void IGPUP_DITHERING_avcodec_close_ctx(AVCodecContext **avctx) {
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 3, 100)
avcodec_free_context(avctx);
#else
avcodec_close(*avctx);
#endif
}
constexpr unsigned int kReadBufSize = 4096;
constexpr unsigned int kReadBufPaddingSize = AV_INPUT_BUFFER_PADDING_SIZE;
constexpr unsigned int kReadBufSizeWithPadding =