Control: tags 1004793 + patch Control: tags 1004793 + pending Dear maintainer,
I've prepared an NMU for vtk7 (versioned as 7.1.1+dfsg2-10.2) and uploaded it to DELAYED/2. Please feel free to tell me if I should delay it longer. Cheers -- Sebastian Ramacher
diff -Nru vtk7-7.1.1+dfsg2/debian/changelog vtk7-7.1.1+dfsg2/debian/changelog --- vtk7-7.1.1+dfsg2/debian/changelog 2021-12-23 10:00:11.000000000 +0100 +++ vtk7-7.1.1+dfsg2/debian/changelog 2022-08-03 21:41:56.000000000 +0200 @@ -1,3 +1,11 @@ +vtk7 (7.1.1+dfsg2-10.2) unstable; urgency=medium + + * Non-maintainer upload. + * debian/patches: Update vtkFFMPEGWriter.cxx to version from vtk9 including + fixes for ffmpeg 5 support (Closes: #1004793) + + -- Sebastian Ramacher <sramac...@debian.org> Wed, 03 Aug 2022 21:41:56 +0200 + vtk7 (7.1.1+dfsg2-10.1) unstable; urgency=medium * Non-maintainer upload. diff -Nru vtk7-7.1.1+dfsg2/debian/control vtk7-7.1.1+dfsg2/debian/control --- vtk7-7.1.1+dfsg2/debian/control 2020-12-15 18:57:51.000000000 +0100 +++ vtk7-7.1.1+dfsg2/debian/control 2022-08-03 19:39:40.000000000 +0200 @@ -43,6 +43,7 @@ libqt5x11extras5-dev, libsqlite3-dev, libswscale-dev, + libswresample-dev, libtheora-dev, libtiff-dev, libutfcpp-dev, diff -Nru vtk7-7.1.1+dfsg2/debian/patches/ffmpeg-5.patch vtk7-7.1.1+dfsg2/debian/patches/ffmpeg-5.patch --- vtk7-7.1.1+dfsg2/debian/patches/ffmpeg-5.patch 1970-01-01 01:00:00.000000000 +0100 +++ vtk7-7.1.1+dfsg2/debian/patches/ffmpeg-5.patch 2022-08-03 21:41:14.000000000 +0200 @@ -0,0 +1,1034 @@ +Description: Support ffmpeg 5. + Update vtkFFMPEGWriter.cxx to the version from vtk9 including the + fixes for ffmpeg 5 support. Based on an initial patch by Peter Green. +Author: Sebastian Ramacher <sramac...@debian.org> + +--- a/CMake/FindFFMPEG.cmake ++++ b/CMake/FindFFMPEG.cmake +@@ -107,13 +107,14 @@ + FFMPEG_FIND(LIBAVDEVICE avdevice avdevice.h) + FFMPEG_FIND(LIBAVCODEC avcodec avcodec.h) + FFMPEG_FIND(LIBAVUTIL avutil avutil.h) ++FFMPEG_FIND(LIBSWRESAMPLE swresample swresample.h) + FFMPEG_FIND(LIBSWSCALE swscale swscale.h) # not sure about the header to look for here. + + SET(FFMPEG_FOUND "NO") + + # Note we don't check FFMPEG_LIBSWSCALE_FOUND, FFMPEG_LIBAVDEVICE_FOUND, + # and FFMPEG_LIBAVUTIL_FOUND as they are optional. +-IF (FFMPEG_LIBAVFORMAT_FOUND AND FFMPEG_LIBAVCODEC_FOUND AND STDINT_OK) ++IF (FFMPEG_LIBAVFORMAT_FOUND AND FFMPEG_LIBAVCODEC_FOUND AND FFMPEG_LIBSWRESAMPLE_FOUND AND STDINT_OK) + + SET(FFMPEG_FOUND "YES") + +--- a/IO/FFMPEG/CMakeLists.txt ++++ b/IO/FFMPEG/CMakeLists.txt +@@ -22,7 +22,7 @@ + ) + + set(_ffmpeg_libs ${FFMPEG_LIBAVFORMAT_LIBRARIES} ${FFMPEG_LIBAVCODEC_LIBRARIES} +- ${FFMPEG_LIBAVUTIL_LIBRARIES} ++ ${FFMPEG_LIBAVUTIL_LIBRARIES} ${FFMPEG_LIBSWRESAMPLE_LIBRARIES} + ) + + if(NOT VTK_FFMPEG_HAS_IMG_CONVERT) +--- a/IO/FFMPEG/vtkFFMPEGWriter.cxx ++++ b/IO/FFMPEG/vtkFFMPEGWriter.cxx +@@ -15,99 +15,77 @@ + + #include "vtkFFMPEGWriter.h" + ++#include "vtkErrorCode.h" + #include "vtkImageData.h" + #include "vtkObjectFactory.h" +-#include "vtkErrorCode.h" +-#include "vtkFFMPEGConfig.h" + +-extern "C" { +-#ifdef VTK_FFMPEG_HAS_OLD_HEADER +-# include <ffmpeg/avformat.h> +-#else +-# include <libavformat/avformat.h> +-#endif +- +-#ifndef VTK_FFMPEG_HAS_IMG_CONVERT +-# ifdef VTK_FFMPEG_HAS_OLD_HEADER +-# include <ffmpeg/swscale.h> +-# else +-# include <libswscale/swscale.h> +-# endif +-#endif ++extern "C" ++{ ++#include <libavcodec/avcodec.h> ++#include <libavformat/avformat.h> ++#include <libswscale/swscale.h> + } + +-#ifdef __GNUC__ +-#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +-#endif +- +-#if LIBAVCODEC_VERSION_MAJOR < 55 +-# define AV_CODEC_ID_MJPEG CODEC_ID_MJPEG +-# define AV_CODEC_ID_RAWVIDEO CODEC_ID_RAWVIDEO +-# define AV_PIX_FMT_BGR24 PIX_FMT_BGR24 +-# define AV_PIX_FMT_RGB24 PIX_FMT_RGB24 +-# define AV_PIX_FMT_YUVJ422P PIX_FMT_YUVJ422P ++#if LIBAVFORMAT_VERSION_MAJOR < 59 ++#define vtk_ff_const59 ++#else ++#define vtk_ff_const59 const + #endif + +-#if LIBAVCODEC_VERSION_MAJOR < 56 || \ +- LIBAVCODEC_VERSION_MAJOR == 55 && LIBAVCODEC_VERSION_MINOR < 28 || \ +- LIBAVCODEC_VERSION_MAJOR == 55 && LIBAVCODEC_VERSION_MINOR == 28 && LIBAVCODEC_VERSION_MICRO < 1 +-# define av_frame_alloc avcodec_alloc_frame ++#if defined(LIBAVFORMAT_VERSION_MAJOR) && LIBAVFORMAT_VERSION_MAJOR >= 57 ++extern "C" ++{ ++#include <libavutil/imgutils.h> ++} + #endif + +-//--------------------------------------------------------------------------- ++//------------------------------------------------------------------------------ + class vtkFFMPEGWriterInternal +- { ++{ + public: +- vtkFFMPEGWriterInternal(vtkFFMPEGWriter *creator); ++ vtkFFMPEGWriterInternal(vtkFFMPEGWriter* creator); + ~vtkFFMPEGWriterInternal(); + + int Start(); +- int Write(vtkImageData *id); ++ int Write(vtkImageData* id); + void End(); + + int Dim[2]; + int FrameRate; + + private: ++ vtkFFMPEGWriter* Writer; + +- vtkFFMPEGWriter *Writer; ++ AVFormatContext* avFormatContext; + +- AVFormatContext *avFormatContext; ++ vtk_ff_const59 AVOutputFormat* avOutputFormat; + +- AVOutputFormat *avOutputFormat; ++ AVStream* avStream; + +- AVStream *avStream; ++ AVFrame* rgbInput; ++ AVFrame* yuvOutput; + +-#if LIBAVFORMAT_VERSION_MAJOR < 54 +- unsigned char *codecBuf; +- int codecBufSize; +-#endif +- +- AVFrame *rgbInput; +- AVFrame *yuvOutput; ++ AVCodecContext* avCodecContext; + + int openedFile; + int closedFile; +- }; ++}; + +-//--------------------------------------------------------------------------- +-vtkFFMPEGWriterInternal::vtkFFMPEGWriterInternal(vtkFFMPEGWriter *creator) ++//------------------------------------------------------------------------------ ++vtkFFMPEGWriterInternal::vtkFFMPEGWriterInternal(vtkFFMPEGWriter* creator) + { + this->Writer = creator; + this->Dim[0] = 0; + this->Dim[1] = 0; + +- this->avFormatContext = NULL; ++ this->avFormatContext = nullptr; + +- this->avOutputFormat = NULL; ++ this->avOutputFormat = nullptr; + +- this->avStream = NULL; ++ this->avStream = nullptr; + +-#if LIBAVFORMAT_VERSION_MAJOR < 54 +- this->codecBuf = NULL; +-#endif +- this->rgbInput = NULL; +- this->yuvOutput = NULL; ++ this->rgbInput = nullptr; ++ this->yuvOutput = nullptr; + + this->openedFile = 0; + this->closedFile = 1; +@@ -115,7 +93,7 @@ + this->FrameRate = 25; + } + +-//--------------------------------------------------------------------------- ++//------------------------------------------------------------------------------ + vtkFFMPEGWriterInternal::~vtkFFMPEGWriterInternal() + { + if (!this->closedFile) +@@ -124,41 +102,316 @@ + } + } + +-//--------------------------------------------------------------------------- ++// for newer versions of ffmpeg use the new API as the old has been deprecated ++#if defined(LIBAVFORMAT_VERSION_MAJOR) && LIBAVFORMAT_VERSION_MAJOR >= 57 ++ ++//------------------------------------------------------------------------------ + int vtkFFMPEGWriterInternal::Start() + { + this->closedFile = 0; + +- //initialize libavcodec, and register all codecs and formats ++#ifdef NDEBUG ++ av_log_set_level(AV_LOG_ERROR); ++#endif ++ ++ // choose avi media file format ++ this->avOutputFormat = av_guess_format("avi", nullptr, nullptr); ++ if (!this->avOutputFormat) ++ { ++ vtkGenericWarningMacro(<< "Could not open the avi media file format."); ++ return 0; ++ } ++ ++ enum AVCodecID video_codec = this->Writer->GetCompression() ++ ? AV_CODEC_ID_MJPEG // choose a codec that is easily playable on windows ++ : AV_CODEC_ID_RAWVIDEO; ++ ++ // create the format context that wraps all of the media output structures ++ if (avformat_alloc_output_context2( ++ &this->avFormatContext, this->avOutputFormat, nullptr, this->Writer->GetFileName()) < 0) ++ { ++ vtkGenericWarningMacro(<< "Could not open the format context."); ++ return 0; ++ } ++ ++ vtk_ff_const59 AVCodec* codec; ++ if (!(codec = avcodec_find_encoder(video_codec))) ++ { ++ vtkGenericWarningMacro(<< "Failed to get video codec."); ++ return 0; ++ } ++ ++ // create a stream for that file ++ this->avStream = avformat_new_stream(this->avFormatContext, codec); ++ if (!this->avStream) ++ { ++ vtkGenericWarningMacro(<< "Could not create video stream."); ++ return 0; ++ } ++ ++ // Set up the codec. ++ if (!(this->avCodecContext = avcodec_alloc_context3(codec))) ++ { ++ vtkGenericWarningMacro(<< "Failed to allocate codec context."); ++ return 0; ++ } ++ ++ this->avStream->codecpar->codec_id = video_codec; ++ this->avStream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; ++ this->avStream->codecpar->width = this->Dim[0]; ++ this->avStream->codecpar->height = this->Dim[1]; ++ if (this->Writer->GetCompression()) ++ { ++ this->avStream->codecpar->format = AV_PIX_FMT_YUVJ420P; ++ } ++ else ++ { ++ this->avStream->codecpar->format = AV_PIX_FMT_BGR24; ++ } ++ this->avStream->time_base.den = this->FrameRate; ++ this->avStream->time_base.num = 1; ++ ++ if (!this->Writer->GetBitRate()) ++ { ++ // allow a variable quality/size tradeoff ++ switch (this->Writer->GetQuality()) ++ { ++ case 0: ++ this->avStream->codecpar->bit_rate = 3 * 1024 * 1024; ++ break; ++ case 1: ++ this->avStream->codecpar->bit_rate = 6 * 1024 * 1024; ++ break; ++ default: ++ this->avStream->codecpar->bit_rate = 12 * 1024 * 1024; ++ break; ++ } ++ } ++ else ++ { ++ this->avStream->codecpar->bit_rate = this->Writer->GetBitRate(); ++ } ++ ++ // to do playback at actual recorded rate, this will need more work see also below ++ avcodec_parameters_to_context(this->avCodecContext, this->avStream->codecpar); ++ this->avCodecContext->time_base.den = this->FrameRate; ++ this->avCodecContext->time_base.num = 1; ++ // this->avCodecContext->max_b_frames = 2; ++ // about one full frame per second ++ this->avCodecContext->gop_size = this->FrameRate; ++ if (this->avFormatContext->oformat->flags & AVFMT_GLOBALHEADER) ++ { ++ this->avCodecContext->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; ++ } ++ if (!this->Writer->GetBitRateTolerance()) ++ { ++ this->avCodecContext->bit_rate_tolerance = ++ this->avCodecContext->bit_rate; // ffmpeg won't create a codec if brt<br ++ } ++ else ++ { ++ this->avCodecContext->bit_rate_tolerance = this->Writer->GetBitRateTolerance(); ++ } ++ avcodec_parameters_from_context(this->avStream->codecpar, this->avCodecContext); ++ ++ if (avcodec_open2(this->avCodecContext, codec, nullptr) < 0) ++ { ++ vtkGenericWarningMacro(<< "Could not open codec."); ++ return 0; ++ } ++ ++ // for the output of the writer's input... ++ this->rgbInput = av_frame_alloc(); ++ if (!this->rgbInput) ++ { ++ vtkGenericWarningMacro(<< "Could not make rgbInput avframe."); ++ return 0; ++ } ++ this->rgbInput->format = AV_PIX_FMT_RGB24; ++ this->rgbInput->width = this->avCodecContext->width; ++ this->rgbInput->height = this->avCodecContext->height; ++ av_frame_get_buffer(this->rgbInput, 1); ++ ++ // and for the output to the codec's input. ++ this->yuvOutput = av_frame_alloc(); ++ if (!this->yuvOutput) ++ { ++ vtkGenericWarningMacro(<< "Could not make yuvOutput avframe."); ++ return 0; ++ } ++ this->yuvOutput->format = this->avCodecContext->pix_fmt; ++ this->yuvOutput->width = this->avCodecContext->width; ++ this->yuvOutput->height = this->avCodecContext->height; ++ this->yuvOutput->pts = 0; ++ av_frame_get_buffer(this->yuvOutput, 1); ++ ++ // Finally, open the file and start it off. ++ if (!(this->avOutputFormat->flags & AVFMT_NOFILE)) ++ { ++ if (avio_open(&this->avFormatContext->pb, this->Writer->GetFileName(), AVIO_FLAG_WRITE) < 0) ++ { ++ vtkGenericWarningMacro(<< "Could not open " << this->Writer->GetFileName() << "."); ++ return 0; ++ } ++ } ++ this->openedFile = 1; ++ ++ if (avformat_write_header(this->avFormatContext, nullptr) < 0) ++ { ++ vtkGenericWarningMacro(<< "Could not allocate avcodec private data."); ++ return 0; ++ } ++ return 1; ++} ++ ++//------------------------------------------------------------------------------ ++int vtkFFMPEGWriterInternal::Write(vtkImageData* id) ++{ ++ this->Writer->GetInputAlgorithm(0, 0)->UpdateWholeExtent(); ++ ++ // copy the image from the input to the RGB buffer while flipping Y ++ unsigned char* rgb = (unsigned char*)id->GetScalarPointer(); ++ unsigned char* src; ++ for (int y = 0; y < this->avCodecContext->height; y++) ++ { ++ src = rgb + (this->avCodecContext->height - y - 1) * this->avCodecContext->width * 3; // flip Y ++ unsigned char* dest = &this->rgbInput->data[0][y * this->rgbInput->linesize[0]]; ++ memcpy((void*)dest, (void*)src, this->avCodecContext->width * 3); ++ } ++ ++ // convert that to YUV for input to the codec ++ SwsContext* convert_ctx = ++ sws_getContext(this->avCodecContext->width, this->avCodecContext->height, AV_PIX_FMT_RGB24, ++ this->avCodecContext->width, this->avCodecContext->height, this->avCodecContext->pix_fmt, ++ SWS_BICUBIC, nullptr, nullptr, nullptr); ++ ++ if (convert_ctx == nullptr) ++ { ++ vtkGenericWarningMacro(<< "swscale context initialization failed"); ++ return 0; ++ } ++ ++ int result = sws_scale(convert_ctx, this->rgbInput->data, this->rgbInput->linesize, 0, ++ this->avCodecContext->height, this->yuvOutput->data, this->yuvOutput->linesize); ++ ++ sws_freeContext(convert_ctx); ++ ++ if (!result) ++ { ++ vtkGenericWarningMacro(<< "sws_scale() failed"); ++ return 0; ++ } ++ ++ int ret = avcodec_send_frame(this->avCodecContext, this->yuvOutput); ++ this->yuvOutput->pts++; ++ ++ if (ret < 0) ++ { ++ return 1; ++ } ++ ++ // run the encoder ++ AVPacket pkt; ++ av_init_packet(&pkt); ++ pkt.data = nullptr; ++ pkt.size = 0; ++ ++ while (!ret) ++ { ++ // dump the compressed result to file ++ ret = avcodec_receive_packet(this->avCodecContext, &pkt); ++ if (!ret) ++ { ++ pkt.stream_index = this->avStream->index; ++ int wret = av_write_frame(this->avFormatContext, &pkt); ++ if (wret < 0) ++ { ++ vtkGenericWarningMacro(<< "Problem encoding frame."); ++ return 0; ++ } ++ } ++ } ++ ++ return 1; ++} ++ ++//------------------------------------------------------------------------------ ++void vtkFFMPEGWriterInternal::End() ++{ ++ if (this->yuvOutput) ++ { ++ av_frame_free(&this->yuvOutput); ++ this->yuvOutput = nullptr; ++ } ++ ++ if (this->rgbInput) ++ { ++ av_frame_free(&this->rgbInput); ++ this->rgbInput = nullptr; ++ } ++ ++ if (this->avFormatContext) ++ { ++ if (this->openedFile) ++ { ++ av_write_trailer(this->avFormatContext); ++ avio_close(this->avFormatContext->pb); ++ this->openedFile = 0; ++ } ++ ++ avformat_free_context(this->avFormatContext); ++ this->avFormatContext = nullptr; ++ } ++ ++ if (this->avOutputFormat) ++ { ++ // Next line was done inside av_free(this->avFormatContext). ++ // av_free(this->avOutputFormat); ++ ++ this->avOutputFormat = nullptr; ++ } ++ ++ if (this->avCodecContext) ++ { ++ avcodec_close(this->avCodecContext); ++ avcodec_free_context(&this->avCodecContext); ++ this->avCodecContext = nullptr; ++ } ++ ++ this->closedFile = 1; ++} ++ ++// for old versions of ffmpeg use the old API, eventually remove this code ++// The new API was introduced around 2016 ++#else ++ ++//------------------------------------------------------------------------------ ++int vtkFFMPEGWriterInternal::Start() ++{ ++ this->closedFile = 0; ++ ++ // initialize libavcodec, and register all codecs and formats + av_register_all(); + +- //create the format context that wraps all of the media output structures +-#if LIBAVFORMAT_VERSION_MAJOR >= 52 ++ // create the format context that wraps all of the media output structures + this->avFormatContext = avformat_alloc_context(); +-#else +- this->avFormatContext = av_alloc_format_context(); +-#endif + if (!this->avFormatContext) + { +- vtkGenericWarningMacro (<< "Coult not open the format context."); ++ vtkGenericWarningMacro(<< "Could not open the format context."); + return 0; + } + +- //choose avi media file format +-#ifdef VTK_FFMPEG_HAS_OLD_HEADER +- this->avOutputFormat = guess_format("avi", NULL, NULL); +-#else +- this->avOutputFormat = av_guess_format("avi", NULL, NULL); +-#endif ++ // choose avi media file format ++ this->avOutputFormat = av_guess_format("avi", nullptr, nullptr); + if (!this->avOutputFormat) + { +- vtkGenericWarningMacro (<< "Could not open the avi media file format."); ++ vtkGenericWarningMacro(<< "Could not open the avi media file format."); + return 0; + } + + if (this->Writer->GetCompression()) + { +- //choose a codec that is easily playable on windows ++ // choose a codec that is easily playable on windows + this->avOutputFormat->video_codec = AV_CODEC_ID_MJPEG; + } + else +@@ -166,36 +419,24 @@ + this->avOutputFormat->video_codec = AV_CODEC_ID_RAWVIDEO; + } + +- //assign the format to the context ++ // assign the format to the context + this->avFormatContext->oformat = this->avOutputFormat; + +- //choose a filename for the output ++ // choose a filename for the output + strcpy(this->avFormatContext->filename, this->Writer->GetFileName()); + +- //create a stream for that file +-#if LIBAVFORMAT_VERSION_MAJOR < 54 +- this->avStream = av_new_stream(this->avFormatContext, 0); +-#else ++ // create a stream for that file + this->avStream = avformat_new_stream(this->avFormatContext, 0); +-#endif + if (!this->avStream) + { +- vtkGenericWarningMacro (<< "Could not create video stream."); ++ vtkGenericWarningMacro(<< "Could not create video stream."); + return 0; + } + +- //Set up the codec. +- AVCodecContext *c = this->avStream->codec; +-#ifdef VTK_FFMPEG_AVCODECID ++ // Set up the codec. ++ AVCodecContext* c = this->avStream->codec; + c->codec_id = static_cast<AVCodecID>(this->avOutputFormat->video_codec); +-#else +- c->codec_id = static_cast<CodecID>(this->avOutputFormat->video_codec); +-#endif +-#ifdef VTK_FFMPEG_HAS_OLD_HEADER +- c->codec_type = CODEC_TYPE_VIDEO; +-#else +- c->codec_type = AVMEDIA_TYPE_VIDEO; +-#endif ++ c->codec_type = AVMEDIA_TYPE_VIDEO; + c->width = this->Dim[0]; + c->height = this->Dim[1]; + if (this->Writer->GetCompression()) +@@ -207,25 +448,25 @@ + c->pix_fmt = AV_PIX_FMT_BGR24; + } + +- //to do playback at actual recorded rate, this will need more work see also below ++ // to do playback at actual recorded rate, this will need more work see also below + c->time_base.den = this->FrameRate; + c->time_base.num = 1; +- //about one full frame per second ++ // about one full frame per second + c->gop_size = this->FrameRate; + +- if( !this->Writer->GetBitRate() ) ++ if (!this->Writer->GetBitRate()) + { +- //allow a variable quality/size tradeoff ++ // allow a variable quality/size tradeoff + switch (this->Writer->GetQuality()) + { + case 0: +- c->bit_rate = 3*1024*1024; ++ c->bit_rate = 3 * 1024 * 1024; + break; + case 1: +- c->bit_rate = 6*1024*1024; ++ c->bit_rate = 6 * 1024 * 1024; + break; + default: +- c->bit_rate = 12*1024*1024; ++ c->bit_rate = 12 * 1024 * 1024; + break; + } + } +@@ -234,262 +475,164 @@ + c->bit_rate = this->Writer->GetBitRate(); + } + +- if(!this->Writer->GetBitRateTolerance()) ++ if (!this->Writer->GetBitRateTolerance()) + { +- c->bit_rate_tolerance = c->bit_rate; //ffmpeg won't create a codec if brt<br ++ c->bit_rate_tolerance = c->bit_rate; // ffmpeg won't create a codec if brt<br + } + else + { + c->bit_rate_tolerance = this->Writer->GetBitRateTolerance(); + } + +-#if LIBAVFORMAT_VERSION_MAJOR < 54 +- //apply the chosen parameters +- if (av_set_parameters(this->avFormatContext, NULL) < 0) +- { +- vtkGenericWarningMacro (<< "Invalid output format parameters." ); +- return 0; +- } +-#endif +- +- //manufacture a codec with the chosen parameters +- AVCodec *codec = avcodec_find_encoder(c->codec_id); ++ // manufacture a codec with the chosen parameters ++ AVCodec* codec = avcodec_find_encoder(c->codec_id); + if (!codec) + { +- vtkGenericWarningMacro (<< "Codec not found." ); +- return 0; +- } +-#if LIBAVFORMAT_VERSION_MAJOR < 54 +- if (avcodec_open(c, codec) < 0) +-#else +- if (avcodec_open2(c, codec, NULL) < 0) +-#endif +- { +- vtkGenericWarningMacro (<< "Could not open codec."); ++ vtkGenericWarningMacro(<< "Codec not found."); + return 0; + } +- +- //create buffers for the codec to work with. +- +-#if LIBAVFORMAT_VERSION_MAJOR < 54 +- //working compression space +- this->codecBufSize = 2*c->width*c->height*4; //hopefully this is enough +- this->codecBuf = new unsigned char[this->codecBufSize]; +- if (!this->codecBuf) ++ if (avcodec_open2(c, codec, nullptr) < 0) + { +- vtkGenericWarningMacro (<< "Could not make codec working space." ); ++ vtkGenericWarningMacro(<< "Could not open codec."); + return 0; + } +-#endif + +- //for the output of the writer's input... ++ // for the output of the writer's input... + this->rgbInput = av_frame_alloc(); + if (!this->rgbInput) + { +- vtkGenericWarningMacro (<< "Could not make rgbInput avframe." ); ++ vtkGenericWarningMacro(<< "Could not make rgbInput avframe."); + return 0; + } + int RGBsize = avpicture_get_size(AV_PIX_FMT_RGB24, c->width, c->height); +- unsigned char *rgb = (unsigned char *)av_malloc(sizeof(unsigned char) * RGBsize); ++ unsigned char* rgb = (unsigned char*)av_malloc(sizeof(unsigned char) * RGBsize); + if (!rgb) + { +- vtkGenericWarningMacro (<< "Could not make rgbInput's buffer." ); ++ vtkGenericWarningMacro(<< "Could not make rgbInput's buffer."); + return 0; + } +- //The rgb buffer should get deleted when this->rgbInput is. +- avpicture_fill((AVPicture *)this->rgbInput, rgb, AV_PIX_FMT_RGB24, c->width, c->height); ++ // The rgb buffer should get deleted when this->rgbInput is. ++ avpicture_fill((AVPicture*)this->rgbInput, rgb, AV_PIX_FMT_RGB24, c->width, c->height); + +- //and for the output to the codec's input. ++ // and for the output to the codec's input. + this->yuvOutput = av_frame_alloc(); + if (!this->yuvOutput) + { +- vtkGenericWarningMacro (<< "Could not make yuvOutput avframe." ); ++ vtkGenericWarningMacro(<< "Could not make yuvOutput avframe."); + return 0; + } + int YUVsize = avpicture_get_size(c->pix_fmt, c->width, c->height); +- unsigned char *yuv = (unsigned char *)av_malloc(sizeof(unsigned char) * YUVsize); ++ unsigned char* yuv = (unsigned char*)av_malloc(sizeof(unsigned char) * YUVsize); + if (!yuv) + { +- vtkGenericWarningMacro (<< "Could not make yuvOutput's buffer." ); ++ vtkGenericWarningMacro(<< "Could not make yuvOutput's buffer."); + return 0; + } +- //The yuv buffer should get deleted when this->yuv_input is. +- avpicture_fill((AVPicture *)this->yuvOutput, yuv, c->pix_fmt, c->width, c->height); +- ++ // The yuv buffer should get deleted when this->yuv_input is. ++ avpicture_fill((AVPicture*)this->yuvOutput, yuv, c->pix_fmt, c->width, c->height); + +- //Finally, open the file and start it off. +-#if LIBAVFORMAT_VERSION_MAJOR < 54 +- if (url_fopen(&this->avFormatContext->pb, this->avFormatContext->filename, URL_WRONLY) < 0) +-#else ++ // Finally, open the file and start it off. + if (avio_open(&this->avFormatContext->pb, this->avFormatContext->filename, AVIO_FLAG_WRITE) < 0) +-#endif + { +- vtkGenericWarningMacro (<< "Could not open " << this->Writer->GetFileName() << "." ); ++ vtkGenericWarningMacro(<< "Could not open " << this->Writer->GetFileName() << "."); + return 0; + } + this->openedFile = 1; + +-#if LIBAVFORMAT_VERSION_MAJOR < 54 +- av_write_header(this->avFormatContext); +-#else +- if (avformat_write_header(this->avFormatContext, NULL) < 0) ++ if (avformat_write_header(this->avFormatContext, nullptr) < 0) + { +- vtkGenericWarningMacro (<< "Could not allocate avcodec private data."); ++ vtkGenericWarningMacro(<< "Could not allocate avcodec private data."); + return 0; + } +-#endif + return 1; + } + +-//--------------------------------------------------------------------------- +-int vtkFFMPEGWriterInternal::Write(vtkImageData *id) ++//------------------------------------------------------------------------------ ++int vtkFFMPEGWriterInternal::Write(vtkImageData* id) + { + this->Writer->GetInputAlgorithm(0, 0)->UpdateWholeExtent(); + +- AVCodecContext *cc = this->avStream->codec; ++ AVCodecContext* cc = this->avStream->codec; + +- //copy the image from the input to the RGB buffer while flipping Y +- unsigned char *rgb = (unsigned char*)id->GetScalarPointer(); +- unsigned char *src; ++ // copy the image from the input to the RGB buffer while flipping Y ++ unsigned char* rgb = (unsigned char*)id->GetScalarPointer(); ++ unsigned char* src; + for (int y = 0; y < cc->height; y++) + { +- src = rgb + (cc->height-y-1) * cc->width * 3; //flip Y +- unsigned char *dest = +- &this->rgbInput->data[0][y*this->rgbInput->linesize[0]]; +- memcpy((void*)dest, (void*)src, cc->width*3); ++ src = rgb + (cc->height - y - 1) * cc->width * 3; // flip Y ++ unsigned char* dest = &this->rgbInput->data[0][y * this->rgbInput->linesize[0]]; ++ memcpy((void*)dest, (void*)src, cc->width * 3); + } + +- //convert that to YUV for input to the codec +-#ifdef VTK_FFMPEG_HAS_IMG_CONVERT +- img_convert((AVPicture *)this->yuvOutput, cc->pix_fmt, +- (AVPicture *)this->rgbInput, AV_PIX_FMT_RGB24, +- cc->width, cc->height); +-#else +- //convert that to YUV for input to the codec +- SwsContext* convert_ctx = sws_getContext( +- cc->width, cc->height, AV_PIX_FMT_RGB24, +- cc->width, cc->height, cc->pix_fmt, +- SWS_BICUBIC, NULL, NULL, NULL); ++ // convert that to YUV for input to the codec ++ SwsContext* convert_ctx = sws_getContext(cc->width, cc->height, AV_PIX_FMT_RGB24, cc->width, ++ cc->height, cc->pix_fmt, SWS_BICUBIC, nullptr, nullptr, nullptr); + +- if(convert_ctx == NULL) ++ if (convert_ctx == nullptr) + { + vtkGenericWarningMacro(<< "swscale context initialization failed"); + return 0; + } + +- int result = sws_scale(convert_ctx, +- this->rgbInput->data, this->rgbInput->linesize, +- 0, cc->height, +- this->yuvOutput->data, this->yuvOutput->linesize +- ); ++ int result = sws_scale(convert_ctx, this->rgbInput->data, this->rgbInput->linesize, 0, cc->height, ++ this->yuvOutput->data, this->yuvOutput->linesize); + + sws_freeContext(convert_ctx); + +- if(!result) ++ if (!result) + { + vtkGenericWarningMacro(<< "sws_scale() failed"); + return 0; + } +-#endif + +- //run the encoder ++ // run the encoder + AVPacket pkt; + av_init_packet(&pkt); +- pkt.data = NULL; ++ pkt.data = nullptr; + pkt.size = 0; + +-#if LIBAVFORMAT_VERSION_MAJOR < 54 +- int toAdd = avcodec_encode_video(cc, +- this->codecBuf, +- this->codecBufSize, +- this->yuvOutput); +- if (toAdd) +- { +- //to do playback at actual recorded rate, this will need more work +- pkt.pts = cc->coded_frame->pts; +- //pkt.dts = ?; not dure what decompression time stamp should be +- pkt.data = this->codecBuf; +- pkt.size = toAdd; +- pkt.stream_index = this->avStream->index; +- if (cc->coded_frame->key_frame) //treat keyframes well +- { +-#ifdef VTK_FFMPEG_HAS_OLD_HEADER +- pkt.flags |= PKT_FLAG_KEY; +-#else +- pkt.flags |= AV_PKT_FLAG_KEY; +-#endif +- } +- pkt.duration = 0; //presentation duration in time_base units or 0 if NA +- pkt.pos = -1; //byte position in stream or -1 if NA +- +- toAdd = av_write_frame(this->avFormatContext, &pkt); +- } +- if (toAdd) //should not have anything left over +- { +- vtkGenericWarningMacro (<< "Problem encoding frame." ); +- return 0; +- } +- +-#else + int got_frame; +- int ret = avcodec_encode_video2(cc, +- &pkt, +- this->yuvOutput, +- &got_frame); ++ int ret = avcodec_encode_video2(cc, &pkt, this->yuvOutput, &got_frame); + +- //dump the compressed result to file ++ // dump the compressed result to file + if (got_frame) + { + pkt.stream_index = this->avStream->index; + ret = av_write_frame(this->avFormatContext, &pkt); + } + +- if (ret<0) ++ if (ret < 0) + { +- vtkGenericWarningMacro (<< "Problem encoding frame." ); ++ vtkGenericWarningMacro(<< "Problem encoding frame."); + return 0; + } +-#endif + + return 1; + } + +-//--------------------------------------------------------------------------- ++//------------------------------------------------------------------------------ + void vtkFFMPEGWriterInternal::End() + { + if (this->yuvOutput) + { + av_free(this->yuvOutput->data[0]); + av_free(this->yuvOutput); +- this->yuvOutput = NULL; ++ this->yuvOutput = nullptr; + } + + if (this->rgbInput) + { + av_free(this->rgbInput->data[0]); + av_free(this->rgbInput); +- this->rgbInput = NULL; ++ this->rgbInput = nullptr; + } + +- +-#if LIBAVFORMAT_VERSION_MAJOR < 54 +- if (this->codecBuf) +- { +- av_free(this->codecBuf); +- this->codecBuf = NULL; +- } +-#endif +- + if (this->avFormatContext) + { + if (this->openedFile) + { + av_write_trailer(this->avFormatContext); +-#if LIBAVFORMAT_VERSION_MAJOR < 54 +- url_fclose(this->avFormatContext->pb); +-#else + avio_close(this->avFormatContext->pb); +-#endif + this->openedFile = 0; + } + +@@ -500,13 +643,13 @@ + if (this->avStream) + { + av_free(this->avStream); +- this->avStream = NULL; ++ this->avStream = nullptr; + } + + if (this->avOutputFormat) + { +- //Next line was done inside av_free(this->avFormatContext). +- //av_free(this->avOutputFormat); ++ // Next line was done inside av_free(this->avFormatContext). ++ // av_free(this->avOutputFormat); + + this->avOutputFormat = 0; + } +@@ -514,14 +657,15 @@ + this->closedFile = 1; + } + ++#endif + +-//--------------------------------------------------------------------------- ++//------------------------------------------------------------------------------ + vtkStandardNewMacro(vtkFFMPEGWriter); + +-//--------------------------------------------------------------------------- ++//------------------------------------------------------------------------------ + vtkFFMPEGWriter::vtkFFMPEGWriter() + { +- this->Internals = 0; ++ this->Internals = nullptr; + this->Quality = 2; + this->Compression = true; + this->Rate = 25; +@@ -529,24 +673,24 @@ + this->BitRateTolerance = 0; + } + +-//--------------------------------------------------------------------------- ++//------------------------------------------------------------------------------ + vtkFFMPEGWriter::~vtkFFMPEGWriter() + { + delete this->Internals; + } + +-//--------------------------------------------------------------------------- ++//------------------------------------------------------------------------------ + void vtkFFMPEGWriter::Start() + { + this->Error = 1; + +- if ( this->Internals ) ++ if (this->Internals) + { + vtkErrorMacro("Movie already started."); + this->SetErrorCode(vtkGenericMovieWriter::InitError); + return; + } +- if ( this->GetInput() == NULL ) ++ if (this->GetInput() == nullptr) + { + vtkErrorMacro("Please specify an input."); + this->SetErrorCode(vtkGenericMovieWriter::NoInputError); +@@ -566,7 +710,7 @@ + this->Initialized = 0; + } + +-//--------------------------------------------------------------------------- ++//------------------------------------------------------------------------------ + void vtkFFMPEGWriter::Write() + { + if (this->Error) +@@ -574,7 +718,7 @@ + return; + } + +- if ( !this->Internals ) ++ if (!this->Internals) + { + vtkErrorMacro("Movie not started."); + this->Error = 1; +@@ -588,13 +732,13 @@ + + int dim[4]; + input->GetDimensions(dim); +- if ( this->Internals->Dim[0] == 0 && this->Internals->Dim[1] == 0 ) ++ if (this->Internals->Dim[0] == 0 && this->Internals->Dim[1] == 0) + { + this->Internals->Dim[0] = dim[0]; + this->Internals->Dim[1] = dim[1]; + } + +- if (this->Internals->Dim[0]!= dim[0] || this->Internals->Dim[1]!= dim[1]) ++ if (this->Internals->Dim[0] != dim[0] || this->Internals->Dim[1] != dim[1]) + { + vtkErrorMacro("Image not of the same size."); + this->Error = 1; +@@ -602,7 +746,7 @@ + return; + } + +- if ( !this->Initialized ) ++ if (!this->Initialized) + { + this->Internals->FrameRate = this->Rate; + if (!this->Internals->Start()) +@@ -623,21 +767,21 @@ + } + } + +-//--------------------------------------------------------------------------- ++//------------------------------------------------------------------------------ + void vtkFFMPEGWriter::End() + { + this->Internals->End(); + + delete this->Internals; +- this->Internals = 0; ++ this->Internals = nullptr; + } + +-//--------------------------------------------------------------------------- ++//------------------------------------------------------------------------------ + void vtkFFMPEGWriter::PrintSelf(ostream& os, vtkIndent indent) + { + this->Superclass::PrintSelf(os, indent); + os << indent << "Quality: " << this->Quality << endl; +- os << indent << "Compression: " << (this->Compression?"true":"false") << endl; ++ os << indent << "Compression: " << (this->Compression ? "true" : "false") << endl; + os << indent << "Rate: " << this->Rate << endl; + os << indent << "BitRate: " << this->BitRate << endl; + os << indent << "BitRateTolerance: " << this->BitRateTolerance << endl; diff -Nru vtk7-7.1.1+dfsg2/debian/patches/series vtk7-7.1.1+dfsg2/debian/patches/series --- vtk7-7.1.1+dfsg2/debian/patches/series 2021-12-23 09:59:32.000000000 +0100 +++ vtk7-7.1.1+dfsg2/debian/patches/series 2022-08-03 19:37:41.000000000 +0200 @@ -24,3 +24,4 @@ 3edc0de2b04ae1e100c229e592d6b9fa94f2915a.patch 581d9eb874b2b80a3fb21c739a96fa6f955ffb5e.patch gcc-11.patch +ffmpeg-5.patch
signature.asc
Description: PGP signature