Browse Source

old changes

master
Joshua Moerman 4 years ago
parent
commit
92afb8ee8a
  1. 27
      CMakeLists.txt
  2. 2
      lib/CMakeLists.txt
  3. 30
      lib/image_io.cpp
  4. 2
      src/CMakeLists.txt

27
CMakeLists.txt

@ -1,15 +1,28 @@
project(Mozaic) project(Mozaic)
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 2.8)
add_definitions(-std=c++1y) set(CMAKE_CXX_STANDARD 14)
find_path(AVCODEC_INCLUDE_DIR libavcodec/avcodec.h)
find_library(AVCODEC_LIBRARY avcodec)
find_path(AVFORMAT_INCLUDE_DIR libavformat/avformat.h)
find_library(AVFORMAT_LIBRARY avformat)
find_path(AVUTIL_INCLUDE_DIR libavutil/avutil.h)
find_library(AVUTIL_LIBRARY avutil)
find_path(AVDEVICE_INCLUDE_DIR libavdevice/avdevice.h)
find_library(AVDEVICE_LIBRARY avdevice)
find_path(SWSCALE_INCLUDE_DIR libswscale/swscale.h)
find_library(SWSCALE_LIBRARY swscale)
find_package(Boost REQUIRED COMPONENTS program_options filesystem system serialization) find_package(Boost REQUIRED COMPONENTS program_options filesystem system serialization)
include_directories(SYSTEM ${Boost_INCLUDE_DIRS}) include_directories(SYSTEM ${Boost_INCLUDE_DIRS} ${AVCODEC_INCLUDE_DIR} ${AVFORMAT_INCLUDE_DIR} ${AVUTIL_INCLUDE_DIR} ${AVDEVICE_INCLUDE_DIR} ${SWSCALE_INCLUDE_DIR})
set(libs ${libs} ${Boost_LIBRARIES}) set(libs ${libs} ${Boost_LIBRARIES} ${AVCODEC_LIBRARY} ${AVFORMAT_LIBRARY} ${AVUTIL_LIBRARY} ${AVDEVICE_LIBRARY} ${SWSCALE_LIBRARY})
# add_subdirectory("contrib")
add_subdirectory("lib") add_subdirectory("lib")
add_subdirectory("src") add_subdirectory("src")
# file(GLOB resources "resources/*")
# file(COPY ${resources} DESTINATION ${CMAKE_BINARY_DIR})

2
lib/CMakeLists.txt

@ -2,7 +2,7 @@
file(GLOB_RECURSE sources "*.cpp") file(GLOB_RECURSE sources "*.cpp")
file(GLOB_RECURSE headers "*.hpp") file(GLOB_RECURSE headers "*.hpp")
set(libs avformat avcodec avutil swscale) set(libs ${libs})
add_library(common ${headers} ${sources}) add_library(common ${headers} ${sources})
target_link_libraries(common ${libs}) target_link_libraries(common ${libs})

30
lib/image_io.cpp

@ -1,7 +1,7 @@
#include "image_io.hpp" #include "image_io.hpp"
#include "utilities.hpp" #include "utilities.hpp"
#include <av/sws.hpp> #include "av/sws.hpp"
extern "C" { extern "C" {
#include <libavutil/frame.h> #include <libavutil/frame.h>
@ -159,11 +159,29 @@ void encode_as_jpg(const av::frame& frame, const std::string& filename){
const auto opened_codec = av::codec_open(codec_ctx, codec, nullptr); const auto opened_codec = av::codec_open(codec_ctx, codec, nullptr);
const auto buffer_size = avpicture_get_size(pix_fmt, codec_ctx->width, codec_ctx->height); // const auto buffer_size = avpicture_get_size(pix_fmt, codec_ctx->width, codec_ctx->height);
std::vector<uint8_t> buffer(make_u(buffer_size), 0); // std::vector<uint8_t> buffer(make_u(buffer_size), 0);
const auto output_size = avcodec_encode_video(codec_ctx.get(), buffer.data(), buffer_size, frame.get()); // const auto output_size = avcodec_encode_video(codec_ctx.get(), buffer.data(), buffer_size, frame.get());
assert(output_size <= buffer_size); // assert(output_size <= buffer_size);
if(avcodec_send_frame(codec_ctx.get(), frame.get()) < 0) {
std::cerr << "Error when encoding frame" << std::endl;
}
AVPacket * p = av_packet_alloc();
std::ofstream file(filename); std::ofstream file(filename);
file.write(reinterpret_cast<char*>(buffer.data()), output_size);
int ret = 0;
while (ret >= 0) {
ret = avcodec_receive_packet(codec_ctx.get(), p);
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
return;
else if (ret < 0) {
std::cerr << "error" << std::endl;
return;
}
std::clog << "encoded frame " << p->pts << " of size " << p->size << std::endl;
file.write(reinterpret_cast<char*>(p->data), p->size);
av_packet_unref(p);
}
} }

2
src/CMakeLists.txt

@ -3,7 +3,7 @@ set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
file(GLOB sources "*.cpp") file(GLOB sources "*.cpp")
set(libs common avformat avcodec avutil swscale ${Boost_LIBRARIES}) set(libs common ${libs})
foreach(source ${sources}) foreach(source ${sources})
get_filename_component(exec ${source} NAME_WE) get_filename_component(exec ${source} NAME_WE)

Loading…
Cancel
Save