Package: libopenshot
Version: 0.2.7+dfsg1-2
Followup-For: Bug #1004763
User: ubuntu-de...@lists.ubuntu.com
Usertags: origin-ubuntu kinetic ubuntu-patch
Control: tags -1 patch

Please find attached a patch that cherry-picks support for ffmpeg 5.0 from
upstream.

This has been uploaded to Ubuntu as part of the ffmpeg 5.0 transition.

-- 
Steve Langasek                   Give me a lever long enough and a Free OS
Debian Developer                   to set it on, and I can move the world.
Ubuntu Developer                                   https://www.debian.org/
slanga...@ubuntu.com                                     vor...@debian.org
diff -Nru libopenshot-0.2.7+dfsg1/debian/control 
libopenshot-0.2.7+dfsg1/debian/control
--- libopenshot-0.2.7+dfsg1/debian/control      2022-07-19 05:56:48.000000000 
-0700
+++ libopenshot-0.2.7+dfsg1/debian/control      2022-07-22 16:15:39.000000000 
-0700
@@ -1,6 +1,5 @@
 Source: libopenshot
-Maintainer: Ubuntu Developers <ubuntu-devel-disc...@lists.ubuntu.com>
-XSBC-Original-Maintainer: Debian Multimedia Maintainers 
<debian-multimedia@lists.debian.org>
+Maintainer: Debian Multimedia Maintainers <debian-multimedia@lists.debian.org>
 Uploaders: Dr. Tobias Quathamer <to...@debian.org>,
            Anton Gladky <gl...@debian.org>
 Section: libs
diff -Nru 
libopenshot-0.2.7+dfsg1/debian/patches/0001-constify-some-AVCodecIDs-necessary-for-new-ffmpeg.patch
 
libopenshot-0.2.7+dfsg1/debian/patches/0001-constify-some-AVCodecIDs-necessary-for-new-ffmpeg.patch
--- 
libopenshot-0.2.7+dfsg1/debian/patches/0001-constify-some-AVCodecIDs-necessary-for-new-ffmpeg.patch
 1969-12-31 16:00:00.000000000 -0800
+++ 
libopenshot-0.2.7+dfsg1/debian/patches/0001-constify-some-AVCodecIDs-necessary-for-new-ffmpeg.patch
 2022-07-22 16:15:08.000000000 -0700
@@ -0,0 +1,98 @@
+From 99034feb4e5a00eeea90fc8c55ce1a511a3e9736 Mon Sep 17 00:00:00 2001
+From: nick black <dankamong...@gmail.com>
+Date: Sun, 21 Nov 2021 23:25:37 -0500
+Subject: [PATCH] constify some AVCodecIDs, necessary for new ffmpeg
+
+Signed-off-by: nick black <dankamong...@gmail.com>
+---
+ src/FFmpegReader.cpp |  6 +++---
+ src/FFmpegWriter.cpp | 12 ++++++------
+ 2 files changed, 9 insertions(+), 9 deletions(-)
+
+diff --git a/src/FFmpegReader.cpp b/src/FFmpegReader.cpp
+index 19d038bf..a0d4c183 100644
+--- a/src/FFmpegReader.cpp
++++ b/src/FFmpegReader.cpp
+@@ -241,10 +241,10 @@ void FFmpegReader::Open() {
+                       pStream = pFormatCtx->streams[videoStream];
+ 
+                       // Find the codec ID from stream
+-                      AVCodecID codecId = AV_FIND_DECODER_CODEC_ID(pStream);
++                      const AVCodecID codecId = 
AV_FIND_DECODER_CODEC_ID(pStream);
+ 
+                       // Get codec and codec context from stream
+-                      AVCodec *pCodec = avcodec_find_decoder(codecId);
++                      const AVCodec *pCodec = avcodec_find_decoder(codecId);
+                       AVDictionary *opts = NULL;
+                       int retry_decode_open = 2;
+                       // If hw accel is selected but hardware cannot handle 
repeat with software decoding
+@@ -498,7 +498,7 @@ void FFmpegReader::Open() {
+                       AVCodecID codecId = AV_FIND_DECODER_CODEC_ID(aStream);
+ 
+                       // Get codec and codec context from stream
+-                      AVCodec *aCodec = avcodec_find_decoder(codecId);
++                      const AVCodec *aCodec = avcodec_find_decoder(codecId);
+                       aCodecCtx = AV_GET_CODEC_CONTEXT(aStream, aCodec);
+ 
+                       // Set number of threads equal to number of processors 
(not to exceed 16)
+diff --git a/src/FFmpegWriter.cpp b/src/FFmpegWriter.cpp
+index a959fc4d..5662c271 100644
+--- a/src/FFmpegWriter.cpp
++++ b/src/FFmpegWriter.cpp
+@@ -151,7 +151,7 @@ void FFmpegWriter::initialize_streams() {
+ void FFmpegWriter::SetVideoOptions(bool has_video, std::string codec, 
Fraction fps, int width, int height, Fraction pixel_ratio, bool interlaced, 
bool top_field_first, int bit_rate) {
+       // Set the video options
+       if (codec.length() > 0) {
+-              AVCodec *new_codec;
++              const AVCodec *new_codec;
+               // Check if the codec selected is a hardware accelerated codec
+ #if USE_HW_ACCEL
+ #if defined(__linux__)
+@@ -273,7 +273,7 @@ void FFmpegWriter::SetVideoOptions(std::string codec, int 
width, int height,  Fr
+ void FFmpegWriter::SetAudioOptions(bool has_audio, std::string codec, int 
sample_rate, int channels, ChannelLayout channel_layout, int bit_rate) {
+       // Set audio options
+       if (codec.length() > 0) {
+-              AVCodec *new_codec = 
avcodec_find_encoder_by_name(codec.c_str());
++              const AVCodec *new_codec = 
avcodec_find_encoder_by_name(codec.c_str());
+               if (new_codec == NULL)
+                       throw InvalidCodec("A valid audio codec could not be 
found for this file.", path);
+               else {
+@@ -1033,7 +1033,7 @@ AVStream *FFmpegWriter::add_audio_stream() {
+       AVStream *st;
+ 
+       // Find the audio codec
+-      AVCodec *codec = avcodec_find_encoder_by_name(info.acodec.c_str());
++      const AVCodec *codec = 
avcodec_find_encoder_by_name(info.acodec.c_str());
+       if (codec == NULL)
+               throw InvalidCodec("A valid audio codec could not be found for 
this file.", path);
+ 
+@@ -1118,7 +1118,7 @@ AVStream *FFmpegWriter::add_video_stream() {
+       AVStream *st;
+ 
+       // Find the video codec
+-      AVCodec *codec = avcodec_find_encoder_by_name(info.vcodec.c_str());
++      const AVCodec *codec = 
avcodec_find_encoder_by_name(info.vcodec.c_str());
+       if (codec == NULL)
+               throw InvalidCodec("A valid video codec could not be found for 
this file.", path);
+ 
+@@ -1302,7 +1302,7 @@ AVStream *FFmpegWriter::add_video_stream() {
+ 
+ // open audio codec
+ void FFmpegWriter::open_audio(AVFormatContext *oc, AVStream *st) {
+-      AVCodec *codec;
++      const AVCodec *codec;
+       AV_GET_CODEC_FROM_STREAM(st, audio_codec_ctx)
+ 
+       // Set number of threads equal to number of processors (not to exceed 
16)
+@@ -1373,7 +1373,7 @@ void FFmpegWriter::open_audio(AVFormatContext *oc, 
AVStream *st) {
+ 
+ // open video codec
+ void FFmpegWriter::open_video(AVFormatContext *oc, AVStream *st) {
+-      AVCodec *codec;
++      const AVCodec *codec;
+       AV_GET_CODEC_FROM_STREAM(st, video_codec_ctx)
+ 
+       // Set number of threads equal to number of processors (not to exceed 
16)
+-- 
+2.34.1
+
diff -Nru 
libopenshot-0.2.7+dfsg1/debian/patches/0001-FFmpegWriter-Macro-member-cleanup.patch
 
libopenshot-0.2.7+dfsg1/debian/patches/0001-FFmpegWriter-Macro-member-cleanup.patch
--- 
libopenshot-0.2.7+dfsg1/debian/patches/0001-FFmpegWriter-Macro-member-cleanup.patch
 1969-12-31 16:00:00.000000000 -0800
+++ 
libopenshot-0.2.7+dfsg1/debian/patches/0001-FFmpegWriter-Macro-member-cleanup.patch
 2022-07-22 16:15:39.000000000 -0700
@@ -0,0 +1,346 @@
+From 93debab7c45f05752e52d4c602ec18ab25bc9997 Mon Sep 17 00:00:00 2001
+From: "FeRD (Frank Dana)" <ferd...@gmail.com>
+Date: Thu, 24 Feb 2022 07:29:08 -0500
+Subject: [PATCH] FFmpegWriter: Macro & member cleanup
+
+- The `fmt` class member, which was of type AVFormat*, was really
+  just an unnecessary copy of `(AVFormatContext*)oc->oformat`.
+  But we were ASSIGNING into its members, which we were definitely
+  not supposed to be doing. (And in recent FFmpegs, now that
+  `AVFormat` has been `const`d, we can't.) It's gone; now we just
+  use `oc->oformat` anywhere we used to access `fmt`.
+
+- The preprocessor macro to allocate a new _stream_ was a mess of
+  cross purposes: It did allocate a stream, but then it also
+  allocated a new AvCodecCtx on newer FFmpeg releases. Worse (and
+  always galling to me), it proceeded to assign to a variable
+  that WASN'T passed in to the macro, just taking it on faith that
+  it would only be used where that variable was defined. That's
+  just... ugh. So I broke it apart into two steps (stream creation
+  and context allocation), realized the stream creation code was
+  the same for all ffmpeg versions and didn't need to be a macro
+  at all, and now a 4-parameter, 6-line magical macro has been
+  replaced with a simple, zero-side-effect one-liner.
+
+- I also cleaned up the add_video_stream() code to be more like
+  the add_audio_stream() code, since they were bad-different for
+  no discernible reason.
+---
+ src/FFmpegUtilities.h |  37 ++++-----------
+ src/FFmpegWriter.cpp  | 103 ++++++++++++++++++++++++------------------
+ src/FFmpegWriter.h    |   3 +-
+ 3 files changed, 68 insertions(+), 75 deletions(-)
+
+Index: libopenshot-0.2.7+dfsg1/src/FFmpegUtilities.h
+===================================================================
+--- libopenshot-0.2.7+dfsg1.orig/src/FFmpegUtilities.h
++++ libopenshot-0.2.7+dfsg1/src/FFmpegUtilities.h
+@@ -200,13 +200,8 @@
+     #define AV_OPTION_SET( av_stream, priv_data, name, value, avcodec) \
+             av_opt_set(priv_data, name, value, 0); \
+             avcodec_parameters_from_context(av_stream->codecpar, avcodec);
+-    #define AV_FORMAT_NEW_STREAM(oc, st_codec_ctx, av_codec, av_st) \
+-            av_st = avformat_new_stream(oc, NULL);\
+-            if (!av_st) \
+-                throw OutOfMemory("Could not allocate memory for the video 
stream.", path); \
+-            c = avcodec_alloc_context3(av_codec); \
+-            st_codec_ctx = c; \
+-            av_st->codecpar->codec_id = av_codec->id;
++    #define ALLOC_CODEC_CTX(ctx, codec, stream) \
++            ctx = avcodec_alloc_context3(codec);
+     #define AV_COPY_PARAMS_FROM_CONTEXT(av_stream, av_codec_ctx) \
+             avcodec_parameters_from_context(av_stream->codecpar, 
av_codec_ctx);
+ 
+@@ -244,16 +239,8 @@
+     #define AV_OPTION_SET( av_stream, priv_data, name, value, avcodec) \
+             av_opt_set(priv_data, name, value, 0); \
+             avcodec_parameters_from_context(av_stream->codecpar, avcodec);
+-    #define AV_FORMAT_NEW_STREAM(oc, st_codec, av_codec, av_st) \
+-            av_st = avformat_new_stream(oc, NULL);\
+-            if (!av_st) \
+-                throw OutOfMemory("Could not allocate memory for the video 
stream.", path); \
+-            _Pragma ("GCC diagnostic push"); \
+-            _Pragma ("GCC diagnostic ignored \"-Wdeprecated-declarations\""); 
\
+-            avcodec_get_context_defaults3(av_st->codec, av_codec); \
+-            c = av_st->codec; \
+-            _Pragma ("GCC diagnostic pop"); \
+-            st_codec = c;
++    #define ALLOC_CODEC_CTX(ctx, codec, stream) \
++            ctx = avcodec_alloc_context3(codec);
+     #define AV_COPY_PARAMS_FROM_CONTEXT(av_stream, av_codec) \
+             avcodec_parameters_from_context(av_stream->codecpar, av_codec);
+ 
+@@ -284,12 +271,9 @@
+     #define AV_OUTPUT_CONTEXT(output_context, path) oc = 
avformat_alloc_context()
+     #define AV_OPTION_FIND(priv_data, name) av_opt_find(priv_data, name, 
NULL, 0, 0)
+     #define AV_OPTION_SET(av_stream, priv_data, name, value, avcodec) 
av_opt_set (priv_data, name, value, 0)
+-    #define AV_FORMAT_NEW_STREAM( oc,  av_context,  av_codec, av_st) \
+-            av_st = avformat_new_stream(oc, av_codec); \
+-            if (!av_st) \
+-                throw OutOfMemory("Could not allocate memory for the video 
stream.", path); \
++    #define ALLOC_CODEC_CTX(ctx, av_codec, stream) \
+             avcodec_get_context_defaults3(av_st->codec, av_codec); \
+-            c = av_st->codec;
++            ctx = av_st->codec;
+     #define AV_COPY_PARAMS_FROM_CONTEXT(av_stream, av_codec)
+ 
+ #else
+@@ -319,12 +303,9 @@
+     #define AV_OUTPUT_CONTEXT(output_context, path) oc = 
avformat_alloc_context()
+     #define AV_OPTION_FIND(priv_data, name) av_opt_find(priv_data, name, 
NULL, 0, 0)
+     #define AV_OPTION_SET(av_stream, priv_data, name, value, avcodec) 
av_opt_set (priv_data, name, value, 0)
+-    #define AV_FORMAT_NEW_STREAM( oc,  av_context,  av_codec, av_st) \
+-            av_st = avformat_new_stream(oc, av_codec); \
+-            if (!av_st) \
+-                throw OutOfMemory("Could not allocate memory for the video 
stream.", path); \
+-            avcodec_get_context_defaults3(av_st->codec, av_codec); \
+-            c = av_st->codec;
++    #define ALLOC_CODEC_CTX(ctx, av_codec, stream) \
++            avcodec_get_context_defaults3(stream->codec, av_codec); \
++            ctx = stream->codec;
+     #define AV_COPY_PARAMS_FROM_CONTEXT(av_stream, av_codec)
+ #endif
+ 
+Index: libopenshot-0.2.7+dfsg1/src/FFmpegWriter.cpp
+===================================================================
+--- libopenshot-0.2.7+dfsg1.orig/src/FFmpegWriter.cpp
++++ libopenshot-0.2.7+dfsg1/src/FFmpegWriter.cpp
+@@ -81,7 +81,7 @@
+ #endif // USE_HW_ACCEL
+ 
+ FFmpegWriter::FFmpegWriter(const std::string& path) :
+-              path(path), fmt(NULL), oc(NULL), audio_st(NULL), 
video_st(NULL), samples(NULL),
++              path(path), oc(NULL), audio_st(NULL), video_st(NULL), 
samples(NULL),
+               audio_outbuf(NULL), audio_outbuf_size(0), 
audio_input_frame_size(0), audio_input_position(0),
+               initial_audio_input_frame_size(0), img_convert_ctx(NULL), 
cache_size(8), num_of_rescalers(32),
+               rescaler_position(0), video_codec_ctx(NULL), 
audio_codec_ctx(NULL), is_writing(false), video_timestamp(0), 
audio_timestamp(0),
+@@ -123,41 +123,46 @@
+ 
+ // auto detect format (from path)
+ void FFmpegWriter::auto_detect_format() {
+-      // Auto detect the output format from the name. default is mpeg.
+-      fmt = av_guess_format(NULL, path.c_str(), NULL);
+-      if (!fmt)
+-              throw InvalidFormat("Could not deduce output format from file 
extension.", path);
+ 
+       // Allocate the output media context
+       AV_OUTPUT_CONTEXT(&oc, path.c_str());
+-      if (!oc)
+-              throw OutOfMemory("Could not allocate memory for 
AVFormatContext.", path);
++      if (!oc) {
++              throw OutOfMemory(
++                      "Could not allocate memory for AVFormatContext.", path);
++      }
++
++      // Determine what format to use when encoding this output filename
++      oc->oformat = av_guess_format(NULL, path.c_str(), NULL);
++      if (oc->oformat == nullptr) {
++              throw InvalidFormat(
++                      "Could not deduce output format from file extension.", 
path);
++      }
+ 
+-      // Set the AVOutputFormat for the current AVFormatContext
+-      oc->oformat = fmt;
++      // Update video codec name
++      if (oc->oformat->video_codec != AV_CODEC_ID_NONE && info.has_video)
++              info.vcodec = 
avcodec_find_encoder(oc->oformat->video_codec)->name;
+ 
+-      // Update codec names
+-      if (fmt->video_codec != AV_CODEC_ID_NONE && info.has_video)
+-              // Update video codec name
+-              info.vcodec = avcodec_find_encoder(fmt->video_codec)->name;
+-
+-      if (fmt->audio_codec != AV_CODEC_ID_NONE && info.has_audio)
+-              // Update audio codec name
+-              info.acodec = avcodec_find_encoder(fmt->audio_codec)->name;
++      // Update audio codec name
++      if (oc->oformat->audio_codec != AV_CODEC_ID_NONE && info.has_audio)
++              info.acodec = 
avcodec_find_encoder(oc->oformat->audio_codec)->name;
+ }
+ 
+ // initialize streams
+ void FFmpegWriter::initialize_streams() {
+-      
ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::initialize_streams", 
"fmt->video_codec", fmt->video_codec, "fmt->audio_codec", fmt->audio_codec, 
"AV_CODEC_ID_NONE", AV_CODEC_ID_NONE);
++      ZmqLogger::Instance()->AppendDebugMethod(
++              "FFmpegWriter::initialize_streams",
++              "oc->oformat->video_codec", oc->oformat->video_codec,
++              "oc->oformat->audio_codec", oc->oformat->audio_codec,
++              "AV_CODEC_ID_NONE", AV_CODEC_ID_NONE);
+ 
+       // Add the audio and video streams using the default format codecs and 
initialize the codecs
+       video_st = NULL;
+       audio_st = NULL;
+-      if (fmt->video_codec != AV_CODEC_ID_NONE && info.has_video)
++      if (oc->oformat->video_codec != AV_CODEC_ID_NONE && info.has_video)
+               // Add video stream
+               video_st = add_video_stream();
+ 
+-      if (fmt->audio_codec != AV_CODEC_ID_NONE && info.has_audio)
++      if (oc->oformat->audio_codec != AV_CODEC_ID_NONE && info.has_audio)
+               // Add audio stream
+               audio_st = add_audio_stream();
+ }
+@@ -228,9 +233,6 @@
+               else {
+                       // Set video codec
+                       info.vcodec = new_codec->name;
+-
+-                      // Update video codec in fmt
+-                      fmt->video_codec = new_codec->id;
+               }
+       }
+       if (fps.num > 0) {
+@@ -294,9 +296,6 @@
+               else {
+                       // Set audio codec
+                       info.acodec = new_codec->name;
+-
+-                      // Update audio codec in fmt
+-                      fmt->audio_codec = new_codec->id;
+               }
+       }
+       if (sample_rate > 7999)
+@@ -634,7 +633,7 @@
+               throw InvalidOptions("No video or audio options have been set.  
You must set has_video or has_audio (or both).", path);
+ 
+       // Open the output file, if needed
+-      if (!(fmt->flags & AVFMT_NOFILE)) {
++      if (!(oc->oformat->flags & AVFMT_NOFILE)) {
+               if (avio_open(&oc->pb, path.c_str(), AVIO_FLAG_WRITE) < 0)
+                       throw InvalidFile("Could not open or write file.", 
path);
+       }
+@@ -786,9 +785,9 @@
+     // Done writing
+     is_writing = false;
+ 
+-      // Raise exception from main thread
+-      if (has_error_encoding_video)
+-              throw ErrorEncodingVideo("Error while writing raw video frame", 
-1);
++    // Raise exception from main thread
++    if (has_error_encoding_video)
++        throw ErrorEncodingVideo("Error while writing raw video frame", -1);
+ }
+ 
+ // Write a block of frames from a reader
+@@ -1008,7 +1007,7 @@
+       if (image_rescalers.size() > 0)
+               RemoveScalers();
+ 
+-      if (!(fmt->flags & AVFMT_NOFILE)) {
++      if (!(oc->oformat->flags & AVFMT_NOFILE)) {
+               /* close the output file */
+               avio_close(oc->pb);
+       }
+@@ -1044,21 +1043,27 @@
+ 
+ // Add an audio output stream
+ AVStream *FFmpegWriter::add_audio_stream() {
+-      AVCodecContext *c;
+-      AVStream *st;
+-
+       // Find the audio codec
+       const AVCodec *codec = 
avcodec_find_encoder_by_name(info.acodec.c_str());
+       if (codec == NULL)
+               throw InvalidCodec("A valid audio codec could not be found for 
this file.", path);
+ 
+       // Free any previous memory allocations
+-      if (audio_codec_ctx != NULL) {
++      if (audio_codec_ctx != nullptr) {
+               AV_FREE_CONTEXT(audio_codec_ctx);
+       }
+ 
+       // Create a new audio stream
+-      AV_FORMAT_NEW_STREAM(oc, audio_codec_ctx, codec, st)
++      AVStream* st = avformat_new_stream(oc, codec);
++      if (!st)
++              throw OutOfMemory("Could not allocate memory for the video 
stream.", path);
++
++      // Allocate a new codec context for the stream
++      ALLOC_CODEC_CTX(audio_codec_ctx, codec, st)
++#if (LIBAVFORMAT_VERSION_MAJOR >= 58)
++      st->codecpar->codec_id = codec->id;
++#endif
++      AVCodecContext* c = audio_codec_ctx;
+ 
+       c->codec_id = codec->id;
+       c->codec_type = AVMEDIA_TYPE_AUDIO;
+@@ -1129,20 +1134,36 @@
+ 
+ // Add a video output stream
+ AVStream *FFmpegWriter::add_video_stream() {
+-      AVCodecContext *c;
+-      AVStream *st;
+-
+       // Find the video codec
+       const AVCodec *codec = 
avcodec_find_encoder_by_name(info.vcodec.c_str());
+       if (codec == NULL)
+               throw InvalidCodec("A valid video codec could not be found for 
this file.", path);
+ 
++      // Free any previous memory allocations
++      if (video_codec_ctx != nullptr) {
++              AV_FREE_CONTEXT(video_codec_ctx);
++      }
++
+       // Create a new video stream
+-      AV_FORMAT_NEW_STREAM(oc, video_codec_ctx, codec, st)
++      AVStream* st = avformat_new_stream(oc, codec);
++      if (!st)
++              throw OutOfMemory("Could not allocate memory for the video 
stream.", path);
++
++      // Allocate a new codec context for the stream
++      ALLOC_CODEC_CTX(video_codec_ctx, codec, st)
++#if (LIBAVFORMAT_VERSION_MAJOR >= 58)
++      st->codecpar->codec_id = codec->id;
++#endif
++
++      AVCodecContext* c = video_codec_ctx;
+ 
+       c->codec_id = codec->id;
+       c->codec_type = AVMEDIA_TYPE_VIDEO;
+ 
++      // Set sample aspect ratio
++      c->sample_aspect_ratio.num = info.pixel_ratio.num;
++      c->sample_aspect_ratio.den = info.pixel_ratio.den;
++
+       /* Init video encoder options */
+       if (info.video_bit_rate >= 1000
+ #if (LIBAVCODEC_VERSION_MAJOR >= 58)
+@@ -1283,13 +1304,13 @@
+ 
+       // Codec doesn't have any pix formats?
+       if (c->pix_fmt == PIX_FMT_NONE) {
+-              if (fmt->video_codec == AV_CODEC_ID_RAWVIDEO) {
++              if (oc->oformat->video_codec == AV_CODEC_ID_RAWVIDEO) {
+                       // Raw video should use RGB24
+                       c->pix_fmt = PIX_FMT_RGB24;
+ 
+ #if (LIBAVFORMAT_VERSION_MAJOR < 58)
+                       // FFmpeg < 4.0
+-                      if (strcmp(fmt->name, "gif") != 0)
++                      if (strcmp(oc->oformat->name, "gif") != 0)
+                               // If not GIF format, skip the encoding process
+                               // Set raw picture flag (so we don't encode 
this video)
+                               oc->oformat->flags |= AVFMT_RAWPICTURE;
+@@ -1305,7 +1326,7 @@
+       // FFmpeg < 4.0
+       
ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::add_video_stream (" + 
(std::string)fmt->name + " : " + (std::string)av_get_pix_fmt_name(c->pix_fmt) + 
")", "c->codec_id", c->codec_id, "c->bit_rate", c->bit_rate, "c->pix_fmt", 
c->pix_fmt, "oc->oformat->flags", oc->oformat->flags, "AVFMT_RAWPICTURE", 
AVFMT_RAWPICTURE);
+ #else
+-      
ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::add_video_stream (" + 
(std::string)fmt->name + " : " + (std::string)av_get_pix_fmt_name(c->pix_fmt) + 
")", "c->codec_id", c->codec_id, "c->bit_rate", c->bit_rate, "c->pix_fmt", 
c->pix_fmt, "oc->oformat->flags", oc->oformat->flags);
++      
ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::add_video_stream (" + 
(std::string)oc->oformat->name + " : " + 
(std::string)av_get_pix_fmt_name(c->pix_fmt) + ")", "c->codec_id", c->codec_id, 
"c->bit_rate", c->bit_rate, "c->pix_fmt", c->pix_fmt, "oc->oformat->flags", 
oc->oformat->flags);
+ #endif
+ 
+       return st;
+Index: libopenshot-0.2.7+dfsg1/src/FFmpegWriter.h
+===================================================================
+--- libopenshot-0.2.7+dfsg1.orig/src/FFmpegWriter.h
++++ libopenshot-0.2.7+dfsg1/src/FFmpegWriter.h
+@@ -158,8 +158,7 @@
+               bool write_header;
+               bool write_trailer;
+ 
+-              AVOutputFormat *fmt;
+-              AVFormatContext *oc;
++              AVFormatContext* oc;
+               AVStream *audio_st, *video_st;
+               AVCodecContext *video_codec_ctx;
+               AVCodecContext *audio_codec_ctx;
diff -Nru 
libopenshot-0.2.7+dfsg1/debian/patches/0002-FFmpegWriter-Don-t-force-deprecated-stream-member.patch
 
libopenshot-0.2.7+dfsg1/debian/patches/0002-FFmpegWriter-Don-t-force-deprecated-stream-member.patch
--- 
libopenshot-0.2.7+dfsg1/debian/patches/0002-FFmpegWriter-Don-t-force-deprecated-stream-member.patch
 1969-12-31 16:00:00.000000000 -0800
+++ 
libopenshot-0.2.7+dfsg1/debian/patches/0002-FFmpegWriter-Don-t-force-deprecated-stream-member.patch
 2022-07-22 16:15:39.000000000 -0700
@@ -0,0 +1,27 @@
+From eac566f81f3663b4ea7e52c953ce369ad93d2884 Mon Sep 17 00:00:00 2001
+From: "FeRD (Frank Dana)" <ferd...@gmail.com>
+Date: Thu, 24 Feb 2022 07:55:03 -0500
+Subject: [PATCH 2/3] FFmpegWriter: Don't force deprecated stream member
+
+---
+ src/FFmpegWriter.cpp | 7 -------
+ 1 file changed, 7 deletions(-)
+
+Index: libopenshot-0.2.7+dfsg1/src/FFmpegWriter.cpp
+===================================================================
+--- libopenshot-0.2.7+dfsg1.orig/src/FFmpegWriter.cpp
++++ libopenshot-0.2.7+dfsg1/src/FFmpegWriter.cpp
+@@ -1266,13 +1266,6 @@
+       st->avg_frame_rate = av_inv_q(c->time_base);
+       st->time_base.num = info.video_timebase.num;
+       st->time_base.den = info.video_timebase.den;
+-#if (LIBAVFORMAT_VERSION_MAJOR >= 58)
+-      #pragma GCC diagnostic push
+-      #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+-      st->codec->time_base.num = info.video_timebase.num;
+-      st->codec->time_base.den = info.video_timebase.den;
+-      #pragma GCC diagnostic pop
+-#endif
+ 
+       c->gop_size = 12; /* TODO: add this to "info"... emit one intra frame 
every twelve frames at most */
+       c->max_b_frames = 10;
diff -Nru 
libopenshot-0.2.7+dfsg1/debian/patches/0003-FFmpegWriter-Don-t-use-AVPicture-gone-in-5.0.patch
 
libopenshot-0.2.7+dfsg1/debian/patches/0003-FFmpegWriter-Don-t-use-AVPicture-gone-in-5.0.patch
--- 
libopenshot-0.2.7+dfsg1/debian/patches/0003-FFmpegWriter-Don-t-use-AVPicture-gone-in-5.0.patch
      1969-12-31 16:00:00.000000000 -0800
+++ 
libopenshot-0.2.7+dfsg1/debian/patches/0003-FFmpegWriter-Don-t-use-AVPicture-gone-in-5.0.patch
      2022-07-22 16:15:39.000000000 -0700
@@ -0,0 +1,58 @@
+From 2a93c0c3bf9a08273203a109e7a1db2476e0e8af Mon Sep 17 00:00:00 2001
+From: "FeRD (Frank Dana)" <ferd...@gmail.com>
+Date: Thu, 24 Feb 2022 10:34:41 -0500
+Subject: [PATCH] FFmpegWriter: Don't use AVPicture (gone in 5.0)
+
+---
+ src/FFmpegWriter.cpp | 20 ++++++++++----------
+ 1 file changed, 10 insertions(+), 10 deletions(-)
+
+Index: libopenshot-0.2.7+dfsg1/src/FFmpegWriter.cpp
+===================================================================
+--- libopenshot-0.2.7+dfsg1.orig/src/FFmpegWriter.cpp
++++ libopenshot-0.2.7+dfsg1/src/FFmpegWriter.cpp
+@@ -772,7 +772,7 @@
+             // Get AVFrame
+             AVFrame *av_frame = av_frames[frame];
+ 
+-            // Deallocate AVPicture and AVFrame
++            // Deallocate buffer and AVFrame
+             av_freep(&(av_frame->data[0]));
+             AV_FREE_FRAME(&av_frame);
+             av_frames.erase(frame);
+@@ -2035,26 +2035,26 @@
+       if (oc->oformat->flags & AVFMT_RAWPICTURE) {
+ #endif
+               // Raw video case.
+-              AVPacket pkt;
+-              av_init_packet(&pkt);
++              AVPacket* pkt;
++              av_packet_from_data(
++            pkt, frame_final->data[0],
++            frame_final->linesize[0] * frame_final->height);
+ 
+-              pkt.flags |= AV_PKT_FLAG_KEY;
+-              pkt.stream_index = video_st->index;
+-              pkt.data = (uint8_t *) frame_final->data;
+-              pkt.size = sizeof(AVPicture);
++              pkt->flags |= AV_PKT_FLAG_KEY;
++              pkt->stream_index = video_st->index;
+ 
+               // Set PTS (in frames and scaled to the codec's timebase)
+-              pkt.pts = video_timestamp;
++              pkt->pts = video_timestamp;
+ 
+               /* write the compressed frame in the media file */
+-              int error_code = av_interleaved_write_frame(oc, &pkt);
++              int error_code = av_interleaved_write_frame(oc, pkt);
+               if (error_code < 0) {
+                       
ZmqLogger::Instance()->AppendDebugMethod("FFmpegWriter::write_video_packet 
ERROR [" + av_err2string(error_code) + "]", "error_code", error_code);
+                       return false;
+               }
+ 
+               // Deallocate packet
+-              AV_FREE_PACKET(&pkt);
++              AV_FREE_PACKET(pkt);
+ 
+       } else
+       {
diff -Nru libopenshot-0.2.7+dfsg1/debian/patches/series 
libopenshot-0.2.7+dfsg1/debian/patches/series
--- libopenshot-0.2.7+dfsg1/debian/patches/series       2022-03-04 
14:40:31.000000000 -0800
+++ libopenshot-0.2.7+dfsg1/debian/patches/series       2022-07-22 
16:15:39.000000000 -0700
@@ -1 +1,5 @@
 0001-Include-SOVERSION-in-VERSION.patch
+0001-constify-some-AVCodecIDs-necessary-for-new-ffmpeg.patch
+0001-FFmpegWriter-Macro-member-cleanup.patch
+0002-FFmpegWriter-Don-t-force-deprecated-stream-member.patch
+0003-FFmpegWriter-Don-t-use-AVPicture-gone-in-5.0.patch

Reply via email to