[vlc-commits] [Git][videolan/vlc][master] 2 commits: avcodec/chroma: provide the UV flipped status in FindFfmpegChroma()

Steve Lhomme (@robUx4) gitlab at videolan.org
Thu Oct 19 14:38:26 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
5c153bf0 by Steve Lhomme at 2023-10-19T14:12:24+00:00
avcodec/chroma: provide the UV flipped status in FindFfmpegChroma()

Only VLC_CODEC_YV12 has the U/V planes swapped compared to the libavutil
chroma. We need to let the caller know when mapping VLC chromas to
FFmpeg ones.

- - - - -
0da47ff9 by Steve Lhomme at 2023-10-19T14:12:24+00:00
swscale: don't get UV plane swap from FixParameters()

We already have this information from the VLC->libavutil chroma mapping.

- - - - -


6 changed files:

- modules/codec/avcodec/chroma.c
- modules/codec/avcodec/chroma.h
- modules/codec/avcodec/encoder.c
- modules/codec/avcodec/video.c
- modules/demux/avformat/mux.c
- modules/video_chroma/swscale.c


Changes:

=====================================
modules/codec/avcodec/chroma.c
=====================================
@@ -219,10 +219,13 @@ int GetVlcChroma( video_format_t *fmt, enum AVPixelFormat i_ffmpeg_chroma )
     return VLC_EGENERIC;
 }
 
-enum AVPixelFormat FindFfmpegChroma( vlc_fourcc_t fourcc )
+enum AVPixelFormat FindFfmpegChroma( vlc_fourcc_t fourcc, bool *uv_flipped )
 {
     for( size_t i = 0; i < ARRAY_SIZE(chroma_table) != 0; i++ )
         if( chroma_table[i].i_chroma == fourcc )
+        {
+            *uv_flipped = fourcc == VLC_CODEC_YV12;
             return chroma_table[i].i_chroma_id;
+        }
     return AV_PIX_FMT_NONE;
 }


=====================================
modules/codec/avcodec/chroma.h
=====================================
@@ -27,7 +27,7 @@
 
 #include <libavutil/pixfmt.h>
 
-enum AVPixelFormat FindFfmpegChroma( vlc_fourcc_t );
+enum AVPixelFormat FindFfmpegChroma( vlc_fourcc_t, bool *uv_flipped );
 
 int GetVlcChroma( video_format_t *fmt, enum AVPixelFormat i_ffmpeg_chroma );
 


=====================================
modules/codec/avcodec/encoder.c
=====================================
@@ -339,7 +339,8 @@ int InitVideoEnc( vlc_object_t *p_this )
             if( GetFfmpegCodec( VIDEO_ES, p_enc->fmt_out.i_codec, &i_codec_id,
                                 &psz_namecodec ) )
                 break;
-            if( FindFfmpegChroma( p_enc->fmt_out.i_codec ) != AV_PIX_FMT_NONE )
+            bool uv_flipped;
+            if( FindFfmpegChroma( p_enc->fmt_out.i_codec, &uv_flipped ) != AV_PIX_FMT_NONE )
             {
                 i_codec_id = AV_CODEC_ID_RAWVIDEO;
                 psz_namecodec = "Raw video";
@@ -569,7 +570,9 @@ int InitVideoEnc( vlc_object_t *p_this )
             p_enc->fmt_in.video.i_chroma = VLC_CODEC_RGB24;
         }
 
-        p_context->pix_fmt = FindFfmpegChroma( p_enc->fmt_in.video.i_chroma );
+        bool uv_flipped;
+        p_context->pix_fmt = FindFfmpegChroma( p_enc->fmt_in.video.i_chroma, &uv_flipped );
+        assert(!uv_flipped); // I420/RGB24 should not be flipped
 
         if( p_codec->pix_fmts )
         {
@@ -868,7 +871,12 @@ int InitVideoEnc( vlc_object_t *p_this )
     {
         /* XXX: hack: Force same codec (will be handled by transcode) */
         p_enc->fmt_in.video.i_chroma = p_enc->fmt_in.i_codec = p_enc->fmt_out.i_codec;
-        p_context->pix_fmt = FindFfmpegChroma( p_enc->fmt_in.video.i_chroma );
+
+        bool uv_flipped;
+        p_context->pix_fmt = FindFfmpegChroma( p_enc->fmt_in.video.i_chroma, &uv_flipped );
+        if (unlikely(uv_flipped))
+            msg_Warn(p_enc, "VLC chroma needs UV planes swapping %4.4s",
+                p_enc->fmt_in.video.i_chroma);
     }
 
     /* Make sure we get extradata filled by the encoder */


=====================================
modules/codec/avcodec/video.c
=====================================
@@ -709,13 +709,14 @@ static int ExtractAV1Profile(AVCodecContext *p_context, const es_format_t *fmt_i
         AV1_release_sequence_header(sequence_hdr);
         return VLC_ENOTSUP;
     }
-    p_context->sw_pix_fmt = FindFfmpegChroma(chroma);
-
+    bool uv_flipped;
+    p_context->sw_pix_fmt = FindFfmpegChroma(chroma, &uv_flipped);
     if (p_context->sw_pix_fmt == AV_PIX_FMT_NONE)
     {
         AV1_release_sequence_header(sequence_hdr);
         return VLC_ENOTSUP;
     }
+    assert(uv_flipped == false);
 
     AV1_get_frame_max_dimensions(sequence_hdr, &w, &h);
 


=====================================
modules/demux/avformat/mux.c
=====================================
@@ -318,12 +318,16 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
         stream->time_base.num = i_frame_rate_base;
         if(i_codec_id == AV_CODEC_ID_RAWVIDEO)
         {
+            bool uv_flipped;
             video_format_t vfmt;
             video_format_Copy(&vfmt, &fmt->video);
-            enum AVPixelFormat avformat = FindFfmpegChroma(vfmt.i_chroma);
+            enum AVPixelFormat avformat = FindFfmpegChroma(vfmt.i_chroma, &uv_flipped);
             if(avformat == AV_PIX_FMT_NONE)
                 msg_Warn(p_mux, "can't match format RAW video %4.4s",
                          (const char *)&vfmt.i_chroma);
+            else if (unlikely(uv_flipped))
+                msg_Warn(p_mux, "UV planes need swapping for %4.4s",
+                         (const char *)&vfmt.i_chroma);
             video_format_Clean(&vfmt);
             codecpar->format = avformat;
         }


=====================================
modules/video_chroma/swscale.c
=====================================
@@ -265,7 +265,7 @@ static void CloseScaler( filter_t *p_filter )
 /*****************************************************************************
  * Helpers
  *****************************************************************************/
-static void FixParameters( enum AVPixelFormat *pi_fmt, bool *pb_has_a, bool *pb_swap_uv, vlc_fourcc_t fmt )
+static void FixParameters( enum AVPixelFormat *pi_fmt, bool *pb_has_a, vlc_fourcc_t fmt )
 {
     switch( fmt )
     {
@@ -297,10 +297,6 @@ static void FixParameters( enum AVPixelFormat *pi_fmt, bool *pb_has_a, bool *pb_
         *pi_fmt = AV_PIX_FMT_RGB32_1;
         *pb_has_a = true;
         break;
-    case VLC_CODEC_YV12:
-        *pi_fmt = AV_PIX_FMT_YUV420P;
-        *pb_swap_uv = true;
-        break;
     default:
         break;
     }
@@ -320,8 +316,8 @@ static int GetParameters( ScalerConfiguration *p_cfg,
     bool b_swap_uvi = false;
     bool b_swap_uvo = false;
 
-    i_fmti = FindFfmpegChroma( p_fmti->i_chroma );
-    i_fmto = FindFfmpegChroma( p_fmto->i_chroma );
+    i_fmti = FindFfmpegChroma( p_fmti->i_chroma, &b_swap_uvi );
+    i_fmto = FindFfmpegChroma( p_fmto->i_chroma, &b_swap_uvo );
 
     if( p_fmti->i_chroma == p_fmto->i_chroma )
     {
@@ -332,8 +328,8 @@ static int GetParameters( ScalerConfiguration *p_cfg,
         }
     }
 
-    FixParameters( &i_fmti, &b_has_ai, &b_swap_uvi, p_fmti->i_chroma );
-    FixParameters( &i_fmto, &b_has_ao, &b_swap_uvo, p_fmto->i_chroma );
+    FixParameters( &i_fmti, &b_has_ai, p_fmti->i_chroma );
+    FixParameters( &i_fmto, &b_has_ao, p_fmto->i_chroma );
 
 #if !defined (__ANDROID__) && !defined(TARGET_OS_IPHONE)
     /* FIXME TODO removed when ffmpeg is fixed



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/2a359b21289c7eb6016d7d94b85ea7d2ca98d3ab...0da47ff9896e0bbff8bf047fe767d7c2df4aa9cf

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/2a359b21289c7eb6016d7d94b85ea7d2ca98d3ab...0da47ff9896e0bbff8bf047fe767d7c2df4aa9cf
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list