[FFmpeg-devel] [PATCH 1/2] first submit source code

Steven Xiao steven.xiao at amd.com
Thu Sep 1 20:17:10 EEST 2022


---
 ffmpeg/libavcodec/avcodec.h      |  8 ++++++++
 ffmpeg/libavcodec/codec_par.c    |  8 ++++++++
 ffmpeg/libavcodec/decode.c       |  9 +++++++++
 ffmpeg/libavformat/matroskadec.c | 17 +++++++++++++----
 4 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/ffmpeg/libavcodec/avcodec.h b/ffmpeg/libavcodec/avcodec.h
index 65c8535..593cd35 100644
--- a/ffmpeg/libavcodec/avcodec.h
+++ b/ffmpeg/libavcodec/avcodec.h
@@ -585,6 +585,14 @@ typedef struct AVCodecContext {
      */
     int coded_width, coded_height;
 
+    /**
+     * The dimensions of the crop, usually from container.
+     */
+    int crop_top;
+    int crop_left;
+    int crop_bottom;
+    int crop_right;
+
     /**
      * the number of pictures in a group of pictures, or 0 for intra_only
      * - encoding: Set by user.
diff --git a/ffmpeg/libavcodec/codec_par.c b/ffmpeg/libavcodec/codec_par.c
index abda649..f74964a 100644
--- a/ffmpeg/libavcodec/codec_par.c
+++ b/ffmpeg/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/ffmpeg/libavcodec/decode.c b/ffmpeg/libavcodec/decode.c
index 7537398..f31805c 100644
--- a/ffmpeg/libavcodec/decode.c
+++ b/ffmpeg/libavcodec/decode.c
@@ -324,6 +324,15 @@ static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame,
     emms_c();
     actual_got_frame = got_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;
diff --git a/ffmpeg/libavformat/matroskadec.c b/ffmpeg/libavformat/matroskadec.c
index ad7ee39..e41f037 100644
--- a/ffmpeg/libavformat/matroskadec.c
+++ b/ffmpeg/libavformat/matroskadec.c
@@ -208,6 +208,10 @@ typedef struct MatroskaTrackVideo {
     uint64_t pixel_width;
     uint64_t pixel_height;
     EbmlBin  color_space;
+    uint64_t pixel_cropb;
+    uint64_t pixel_cropt;
+    uint64_t pixel_cropl;
+    uint64_t pixel_cropr;
     uint64_t display_unit;
     uint64_t interlaced;
     uint64_t field_order;
@@ -515,10 +519,10 @@ static EbmlSyntax matroska_track_video[] = {
     { MATROSKA_ID_VIDEOALPHAMODE,      EBML_UINT,  0, 0, offsetof(MatroskaTrackVideo, alpha_mode), { .u = 0 } },
     { MATROSKA_ID_VIDEOCOLOR,          EBML_NEST,  0, sizeof(MatroskaTrackVideoColor), offsetof(MatroskaTrackVideo, color), { .n = matroska_track_video_color } },
     { MATROSKA_ID_VIDEOPROJECTION,     EBML_NEST,  0, 0, offsetof(MatroskaTrackVideo, projection), { .n = matroska_track_video_projection } },
-    { MATROSKA_ID_VIDEOPIXELCROPB,     EBML_NONE },
-    { MATROSKA_ID_VIDEOPIXELCROPT,     EBML_NONE },
-    { MATROSKA_ID_VIDEOPIXELCROPL,     EBML_NONE },
-    { MATROSKA_ID_VIDEOPIXELCROPR,     EBML_NONE },
+    { MATROSKA_ID_VIDEOPIXELCROPB,     EBML_UINT,  0, 0, offsetof(MatroskaTrackVideo, pixel_cropb), {.u = 0 } },
+    { MATROSKA_ID_VIDEOPIXELCROPT,     EBML_UINT,  0, 0, offsetof(MatroskaTrackVideo, pixel_cropt), {.u = 0 } },
+    { MATROSKA_ID_VIDEOPIXELCROPL,     EBML_UINT,  0, 0, offsetof(MatroskaTrackVideo, pixel_cropl), {.u = 0 } },
+    { MATROSKA_ID_VIDEOPIXELCROPR,     EBML_UINT,  0, 0, offsetof(MatroskaTrackVideo, pixel_cropr), {.u = 0 } },
     { MATROSKA_ID_VIDEODISPLAYUNIT,    EBML_UINT,  0, 0, offsetof(MatroskaTrackVideo, display_unit), { .u= MATROSKA_VIDEO_DISPLAYUNIT_PIXELS } },
     { MATROSKA_ID_VIDEOFLAGINTERLACED, EBML_UINT,  0, 0, offsetof(MatroskaTrackVideo, interlaced),  { .u = MATROSKA_VIDEO_INTERLACE_FLAG_UNDETERMINED } },
     { MATROSKA_ID_VIDEOFIELDORDER,     EBML_UINT,  0, 0, offsetof(MatroskaTrackVideo, field_order), { .u = MATROSKA_VIDEO_FIELDORDER_UNDETERMINED } },
@@ -2877,6 +2881,11 @@ static int matroska_parse_tracks(AVFormatContext *s)
             st->codecpar->width      = track->video.pixel_width;
             st->codecpar->height     = track->video.pixel_height;
 
+            st->codecpar->crop_top   = track->video.pixel_cropt;
+            st->codecpar->crop_left  = track->video.pixel_cropl;
+            st->codecpar->crop_bottom= track->video.pixel_cropb;
+            st->codecpar->crop_right = track->video.pixel_cropr;
+
             if (track->video.interlaced == MATROSKA_VIDEO_INTERLACE_FLAG_INTERLACED)
                 st->codecpar->field_order = mkv_field_order(matroska, track->video.field_order);
             else if (track->video.interlaced == MATROSKA_VIDEO_INTERLACE_FLAG_PROGRESSIVE)
-- 
2.35.1.windows.2



More information about the ffmpeg-devel mailing list