Commit 391eba6c authored by Dmitry Kazakov's avatar Dmitry Kazakov
Browse files

Implement a skeleton for the Video export plugin

Ref T116
parent 90e2662a
# AvTranscoder_FOUND
# AvTranscoder_INCLUDE_DIR
# AvTranscoder_LIBRARIES
# AvTranscoder_DEFINITIONS
# AvTranscoder_VERSION_MAJOR
# AvTranscoder_VERSION_MINOR
# AvTranscoder_VERSION_PATCH
# AvTranscoder_VERSION
# AvTranscoder_VERSION_STRING
# AvTranscoder_INSTALL_DIR
# AvTranscoder_LIB_DIR
# AvTranscoder_CMAKE_MODULES_DIR
find_package(AvTranscoder ${AvTranscoder_FIND_VERSION} QUIET NO_MODULE PATHS $ENV{HOME} /opt/AvTranscoder)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(AvTranscoder CONFIG_MODE REQUIRED_VARS AvTranscoder_LIBRARIES)
......@@ -44,3 +44,4 @@ add_subdirectory(tga)
add_subdirectory(heightmap)
add_subdirectory(brush)
add_subdirectory(spriter)
add_subdirectory(video)
macro_optional_find_package(AvTranscoder)
macro_log_feature(AvTranscoder_FOUND "AvTranscoder" "AvTranscoder Library" "https://github.com/avTranscoder/avTranscoder" FALSE "0.9.5" "Required for converting animations to video files")
if (AvTranscoder_FOUND)
message("Found AvTranscoder")
else (AvTranscoder_FOUND)
message("Can't find AvTranscoder. Video export plugin will be skipped!")
return()
endif (AvTranscoder_FOUND)
## If the necessary libraries are present, continue with building the
## plugin
add_subdirectory(tests)
include_directories(SYSTEM
${AvTranscoder_INCLUDE_DIR}
)
# export
set(kritavideoexport_SOURCES
kis_video_export.cpp
video_saver.cpp
)
add_library(kritavideoexport MODULE ${kritavideoexport_SOURCES})
generate_export_header(kritavideoexport BASE_NAME kritavideoexport)
target_link_libraries(kritavideoexport kritaui ${AvTranscoder_LIBRARIES})
install(TARGETS kritavideoexport DESTINATION ${KRITA_PLUGIN_INSTALL_DIR})
/*
* Copyright (c) 2016 Laszlo Fazekas <mneko@freemail.hu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "kis_video_export.h"
#include <QCheckBox>
#include <QSlider>
#include <QMessageBox>
#include <kpluginfactory.h>
#include <QFileInfo>
#include <QApplication>
#include <KisImportExportManager.h>
#include <KisFilterChain.h>
#include <KoColorSpaceConstants.h>
#include <KisDocument.h>
#include <kis_image.h>
#include <kis_group_layer.h>
#include <kis_paint_layer.h>
#include <kis_paint_device.h>
#include "video_saver.h"
K_PLUGIN_FACTORY_WITH_JSON(KisVideoExportFactory, "krita_video_export.json", registerPlugin<KisVideoExport>();)
KisVideoExport::KisVideoExport(QObject *parent, const QVariantList &) : KisImportExportFilter(parent)
{
}
KisVideoExport::~KisVideoExport()
{
}
KisImportExportFilter::ConversionStatus KisVideoExport::convert(const QByteArray& from, const QByteArray& to)
{
dbgFile << "Video export! From:" << from << ", To:" << to << "";
if (from != "application/x-krita")
return KisImportExportFilter::NotImplemented;
KisDocument* input = inputDocument();
QString filename = outputFile();
if (!input)
return KisImportExportFilter::NoDocumentCreated;
if (filename.isEmpty()) return KisImportExportFilter::FileNotFound;
VideoSaver kpc(input, getBatchMode());
KisImageBuilder_Result res;
// if ((res = kpc.buildAnimation(filename)) == KisImageBuilder_RESULT_OK) {
// dbgFile <<"success !";
// return KisImportExportFilter::OK;
// }
// dbgFile <<" Result =" << res;
if (res == KisImageBuilder_RESULT_CANCEL)
return KisImportExportFilter::ProgressCancelled;
return KisImportExportFilter::InternalError;
}
#include "kis_video_export.moc"
/*
* Copyright (c) 2016 Laszlo Fazekas <mneko@freemail.hu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef _KIS_VIDEO_EXPORT_H_
#define _KIS_VIDEO_EXPORT_H_
#include <QVariant>
#include <KisImportExportFilter.h>
class KisVideoExport : public KisImportExportFilter
{
Q_OBJECT
public:
KisVideoExport(QObject *parent, const QVariantList &);
virtual ~KisVideoExport();
public:
virtual KisImportExportFilter::ConversionStatus convert(const QByteArray& from, const QByteArray& to);
};
#endif
{
"Id": "Krita Video Export Filter",
"NoDisplay": "true",
"Type": "Service",
"X-KDE-Export": "video/x-matroska"
"X-KDE-Import": "application/x-krita",
"X-KDE-Library": "kritavideoexport",
"X-KDE-ServiceTypes": [
"Krita/FileFilter"
],
"X-KDE-Weight": "1",
"X-KDE-Extensions" : "mkv"
}
set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} )
include_directories( ${CMAKE_SOURCE_DIR}/sdk/tests )
macro_add_unittest_definitions()
########### next target ###############
set(kis_video_plugin_test_SRCS kis_video_plugin_test.cpp )
kde4_add_unit_test(kis_video_plugin_test TESTNAME krita-plugins-formats-video_test ${kis_video_plugin_test_SRCS})
target_link_libraries(kis_video_plugin_test kritavideoexport kritaui Qt5::Test)
/*
* Copyright (c) 2016 Dmitry Kazakov <dimula73@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "kis_video_plugin_test.h"
#include <QTest>
#include <QCoreApplication>
#include <QTest>
#include "filestest.h"
#ifndef FILES_DATA_DIR
#error "FILES_DATA_DIR not set. A directory with the data used for testing the importing of files in krita"
#endif
#include "../video_saver.h"
void KisVideoPluginTest::testFiles()
{
QString fname = QString(FILES_DATA_DIR) + QDir::separator() + "test_animation_small.kra";
KisDocument *doc = KisPart::instance()->createDocument();
doc->loadNativeFormat(fname);
VideoSaver saver(doc, false);
saver.encode("testfile.mkv");
}
QTEST_MAIN(KisVideoPluginTest)
/*
* Copyright (c) 2016 Dmitry Kazakov <dimula73@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _KIS_VIDEO_PLUGIN_TEST_H_
#define _KIS_VIDEO_PLUGIN_TEST_H_
#include <QtTest>
class KisVideoPluginTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void testFiles();
};
#endif
/*
* Copyright (c) 2016 Dmitry Kazakov <dimula73@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "video_saver.h"
#include <QDebug>
// #include <QApplication>
// #include <QFileInfo>
// #include <QFile>
// #include <QDir>
// #include <QVector>
// #include <QIODevice>
// #include <QRect>
// #include <KisMimeDatabase.h>
// #include <KisPart.h>
#include <KisDocument.h>
// #include <KoColorSpace.h>
// #include <KoColorSpaceRegistry.h>
// #include <KoColorModelStandardIds.h>
// #include <kis_annotation.h>
// #include <kis_types.h>
// #include <kis_debug.h>
#include <kis_image.h>
// #include <kis_group_layer.h>
// #include <kis_paint_layer.h>
// #include <kis_paint_device.h>
// #include <kis_raster_keyframe_channel.h>
// #include <kis_image_animation_interface.h>
// #include <kis_time_range.h>
// #include <kis_iterator_ng.h>
#include <AvTranscoder/transcoder/Transcoder.hpp>
#include <AvTranscoder/file/OutputFile.hpp>
#include <AvTranscoder/progress/ConsoleProgress.hpp>
#include <AvTranscoder/decoder/VideoGenerator.hpp>
#include <AvTranscoder/data/decoded/VideoFrame.hpp>
VideoSaver::VideoSaver(KisDocument *doc, bool batchMode)
: m_image(doc->image())
, m_doc(doc)
, m_batchMode(batchMode)
, m_stop(false)
{
}
VideoSaver::~VideoSaver()
{
}
KisImageWSP VideoSaver::image()
{
return m_image;
}
KisImageBuilder_Result VideoSaver::encode(const QString &filename1)
{
KisImageBuilder_Result retval= KisImageBuilder_RESULT_OK;
try {
avtranscoder::preloadCodecsAndFormats();
avtranscoder::Logger::setLogLevel(AV_LOG_DEBUG);
avtranscoder::OutputFile outputFile(filename1.toStdString());
using namespace avtranscoder::constants;
avtranscoder::ProfileLoader::Profile profile;
profile[avProfileIdentificator] = "mymkv";
profile[avProfileIdentificatorHuman] = "mymkv";
profile[avProfileType] = avProfileTypeFormat;
profile[avProfileFormat] = "mkv";
outputFile.setupWrapping(profile);
avtranscoder::VideoCodec inputCodec(avtranscoder::eCodecTypeDecoder, AV_CODEC_ID_RAWVIDEO);
avtranscoder::VideoFrameDesc imageDesc(1920, 1080, AV_PIX_FMT_RGBA);
imageDesc._fps = 25.0;
inputCodec.setImageParameters(imageDesc);
avtranscoder::ProfileLoader loader(true);
avtranscoder::ProfileLoader::Profile videoProfile = loader.getProfile("h264-lq");
videoProfile["profile"] = "main";
avtranscoder::StreamTranscoder transcoder(inputCodec, outputFile, videoProfile);
avtranscoder::VideoGenerator *generator =
dynamic_cast<avtranscoder::VideoGenerator*>(transcoder.getCurrentDecoder());
KIS_ASSERT_RECOVER_NOOP(generator);
QImage canvas(imageDesc._width, imageDesc._height, QImage::Format_RGBA8888);
QPainter gc(&canvas);
avtranscoder::VideoFrame intermediateBuffer(imageDesc);
{
outputFile.beginWrap();
transcoder.preProcessCodecLatency();
for (int i = 0; i < 50; i++) {
gc.fillRect(i * 10, i * 10, 50, 50, Qt::red);
intermediateBuffer.assign(canvas.constBits());
generator->setNextFrame(intermediateBuffer);
transcoder.processFrame();
}
outputFile.endWrap();
}
} catch(std::exception& e) {
std::cerr << "ERROR: during process, an error occured: " << e.what() << std::endl;
}
catch(...) {
std::cerr << "ERROR: during process, an unknown error occured" << std::endl;
}
return retval;
}
void VideoSaver::cancel()
{
m_stop = true;
}
/*
* Copyright (c) 2016 Dmitry Kazakov <dimula73@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef VIDEO_SAVER_H_
#define VIDEO_SAVER_H_
#include <QObject>
#include "kis_types.h"
#include "KisImageBuilderResult.h"
#include "kritavideoexport_export.h"
/* The KisImageBuilder_Result definitions come from kis_png_converter.h here */
class KisDocument;
class KRITAVIDEOEXPORT_EXPORT VideoSaver : public QObject {
Q_OBJECT
public:
VideoSaver(KisDocument* doc, bool batchMode);
virtual ~VideoSaver();
KisImageWSP image();
KisImageBuilder_Result encode(const QString &filename);
private Q_SLOTS:
void cancel();
private:
KisImageSP m_image;
KisDocument* m_doc;
bool m_batchMode;
bool m_stop;
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment