Fix JXS_video_descriptor schar field parsing in the MPEG-TS demuxer:
 - Add 4:2:0 subsampling support (Ssub=2)
 - Detect GBR/RGB pixel formats from colour_specification bits [11:8]
 - Add comment clarifying bit depth comes from codestream, not descriptor

The schar field per ISO/IEC 21122-3 encodes colour_specification in
bits [11:8] (Cs: 0=YCbCr, 1=RGB/GBR) and subsampling in bits [3:0]
(Ssub: 0=4:2:2, 1=4:4:4, 2=4:2:0). The previous code only handled
Ssub 0 and 1, and did not check Cs bits for GBR detection.
---
 libavformat/mpegts.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 4b326d309b..6b94ebd785 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -1901,11 +1901,25 @@ static int 
parse_mpeg2_extension_descriptor(AVFormatContext *fc, AVStream *st, i
                 st->codecpar->framerate.den = framerate_den;
             }
 
+            /* schar bits [11:8] = Cs (colour_specification), bits [3:0] = 
Ssub (subsampling).
+             * Bit depth is not carried in schar; it comes from the codestream.
+             * Set a reasonable default format per subsampling; the parser will
+             * refine it once the first frame is parsed. */
             switch (schar & 0xf) {
-            case 0: st->codecpar->format = AV_PIX_FMT_YUV422P10LE; break;
-            case 1: st->codecpar->format = AV_PIX_FMT_YUV444P10LE; break;
+            case 0: /* 4:2:2 */
+                st->codecpar->format = AV_PIX_FMT_YUV422P10LE;
+                break;
+            case 1: /* 4:4:4 */
+                if (((schar >> 8) & 0xf) == 1)
+                    st->codecpar->format = AV_PIX_FMT_GBRP10LE;
+                else
+                    st->codecpar->format = AV_PIX_FMT_YUV444P10LE;
+                break;
+            case 2: /* 4:2:0 */
+                st->codecpar->format = AV_PIX_FMT_YUV420P10LE;
+                break;
             default:
-                av_log(fc, AV_LOG_WARNING, "Unknown JPEG XS sampling format");
+                av_log(fc, AV_LOG_WARNING, "Unknown JPEG XS sampling format 
%d\n", schar & 0xf);
                 break;
             }
 
-- 
2.53.0

---------------------------------------------------------------------
Intel Technology Poland sp. z o.o.
ul. Slowackiego 173 | 80-298 Gdansk | Sad Rejonowy Gdansk Polnoc | VII Wydzial 
Gospodarczy Krajowego Rejestru Sadowego - KRS 101882 | NIP 957-07-52-316 | 
Kapital zakladowy 200.000 PLN.
Spolka oswiadcza, ze posiada status duzego przedsiebiorcy w rozumieniu ustawy z 
dnia 8 marca 2013 r. o przeciwdzialaniu nadmiernym opoznieniom w transakcjach 
handlowych.

Ta wiadomosc wraz z zalacznikami jest przeznaczona dla okreslonego adresata i 
moze zawierac informacje poufne. W razie przypadkowego otrzymania tej 
wiadomosci, prosimy o powiadomienie nadawcy oraz trwale jej usuniecie; 
jakiekolwiek przegladanie lub rozpowszechnianie jest zabronione.
This e-mail and any attachments may contain confidential material for the sole 
use of the intended recipient(s). If you are not the intended recipient, please 
contact the sender and delete all copies; any review or distribution by others 
is strictly prohibited.

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to