Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: OvchinnikovDmitrii <ovchinnikov.dmitrii@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Cc: OvchinnikovDmitrii <ovchinnikov.dmitrii@gmail.com>
Subject: [FFmpeg-devel] [crop support for matroska demuxer 2/3] libavcodec: Public code to support container crop
Date: Sat,  1 Oct 2022 08:13:40 +0200
Message-ID: <20221001061341.662-2-ovchinnikov.dmitrii@gmail.com> (raw)
In-Reply-To: <20221001061341.662-1-ovchinnikov.dmitrii@gmail.com>

Support both simple and receive_frame api
The container crop information is applied additional to frame crop information
---
 libavcodec/codec_par.c |  8 ++++++++
 libavcodec/decode.c    | 20 ++++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/libavcodec/codec_par.c b/libavcodec/codec_par.c
index abda649aa8..f74964a817 100644
--- a/libavcodec/codec_par.c
+++ b/libavcodec/codec_par.c
@@ -118,6 +118,10 @@ int avcodec_parameters_from_context(AVCodecParameters *par,
         par->format              = codec->pix_fmt;
         par->width               = codec->width;
         par->height              = codec->height;
+        par->crop_top           = codec->crop_top;
+        par->crop_left          = codec->crop_left;
+        par->crop_bottom        = codec->crop_bottom;
+        par->crop_right         = codec->crop_right;
         par->field_order         = codec->field_order;
         par->color_range         = codec->color_range;
         par->color_primaries     = codec->color_primaries;
@@ -199,6 +203,10 @@ int avcodec_parameters_to_context(AVCodecContext *codec,
         codec->pix_fmt                = par->format;
         codec->width                  = par->width;
         codec->height                 = par->height;
+        codec->crop_top               = par->crop_top;
+        codec->crop_left              = par->crop_left;
+        codec->crop_bottom            = par->crop_bottom;
+        codec->crop_right             = par->crop_right;
         codec->field_order            = par->field_order;
         codec->color_range            = par->color_range;
         codec->color_primaries        = par->color_primaries;
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 6be2d3d6ed..548225c904 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -324,6 +324,16 @@ static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame,
     emms_c();
     actual_got_frame = got_frame;
 
+    /* crop for simple api mode. apply additional container crop info to frame */
+    if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
+        if (avctx->crop_top != 0 || avctx->crop_left != 0 || avctx->crop_right != 0 || avctx->crop_bottom != 0){
+            frame->crop_top    += avctx->crop_top;
+            frame->crop_left   += avctx->crop_left;
+            frame->crop_right  += avctx->crop_right;
+            frame->crop_bottom += avctx->crop_bottom;
+        }
+    }
+
     if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
         if (frame->flags & AV_FRAME_FLAG_DISCARD)
             got_frame = 0;
@@ -707,6 +717,16 @@ int ff_decode_receive_frame(AVCodecContext *avctx, AVFrame *frame)
 
     if (avci->buffer_frame->buf[0]) {
         av_frame_move_ref(frame, avci->buffer_frame);
+
+        /* crop for receive_frame api mode. apply additional container crop info to frame */
+        if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
+            if (avctx->crop_top != 0 || avctx->crop_left != 0 || avctx->crop_right != 0 || avctx->crop_bottom != 0){
+                frame->crop_top    += avctx->crop_top;
+                frame->crop_left   += avctx->crop_left;
+                frame->crop_right  += avctx->crop_right;
+                frame->crop_bottom += avctx->crop_bottom;
+            }
+        }
     } else {
         ret = decode_receive_frame_internal(avctx, frame);
         if (ret < 0)
-- 
2.30.0.windows.2

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  reply	other threads:[~2022-10-01  6:14 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-01  6:13 [FFmpeg-devel] [crop support for matroska demuxer 1/3] libavcodec: Add crop related fields to structure AVCodecContext and AVCodecParameters OvchinnikovDmitrii
2022-10-01  6:13 ` OvchinnikovDmitrii [this message]
2022-10-01  7:16   ` [FFmpeg-devel] [crop support for matroska demuxer 2/3] libavcodec: Public code to support container crop Hendrik Leppkes
2022-10-04 11:35     ` Anton Khirnov
2022-10-01  6:13 ` [FFmpeg-devel] [crop support for matroska demuxer 3/3] libavformat\matroskadec.c: crop support for matroska demuxer OvchinnikovDmitrii
2022-10-01  7:06 ` [FFmpeg-devel] [crop support for matroska demuxer 1/3] libavcodec: Add crop related fields to structure AVCodecContext and AVCodecParameters Hendrik Leppkes
2022-10-04 11:49   ` James Almer
2022-10-07 15:12     ` Dmitrii Ovchinnikov
2022-10-01 11:24 ` Timo Rothenpieler
2022-10-04 11:34   ` Anton Khirnov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221001061341.662-2-ovchinnikov.dmitrii@gmail.com \
    --to=ovchinnikov.dmitrii@gmail.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git