Skip to content

Commit

Permalink
Use "C420" as default Y4M color space parameter
Browse files Browse the repository at this point in the history
If the Y4M header does not have a 'C' (color space) parameter, default
to "C420". This matches the defaults of libaom's aomenc and ffmpeg.

1. aom/common/y4minput.c:

static int parse_tags(y4m_input *y4m_ctx, FILE *file) {
  ...
  snprintf(y4m_ctx->chroma_type, sizeof(y4m_ctx->chroma_type), "420");

2. ffmpeg/libavformat/yuv4mpegdec.c:

static int yuv4_read_header(AVFormatContext *s)
{
    ...
    enum AVPixelFormat pix_fmt = AV_PIX_FMT_NONE, alt_pix_fmt = AV_PIX_FMT_NONE;
    ...
    if (pix_fmt == AV_PIX_FMT_NONE) {
        if (alt_pix_fmt == AV_PIX_FMT_NONE)
            pix_fmt = AV_PIX_FMT_YUV420P;
        else
            pix_fmt = alt_pix_fmt;
    }
  • Loading branch information
wantehchang committed Oct 15, 2021
1 parent 67e9f70 commit 5dfa7da
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions apps/shared/y4m.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,10 @@ avifBool y4mRead(const char * inputFilename, avifImage * avif, avifAppSourceTimi
struct y4mFrameIterator frame;
frame.width = -1;
frame.height = -1;
frame.depth = -1;
// Default to the color space "C420" to match the defaults of aomenc and ffmpeg.
frame.depth = 8;
frame.hasAlpha = AVIF_FALSE;
frame.format = AVIF_PIXEL_FORMAT_NONE;
frame.format = AVIF_PIXEL_FORMAT_YUV420;
frame.range = AVIF_RANGE_LIMITED;
frame.chromaSamplePosition = AVIF_CHROMA_SAMPLE_POSITION_UNKNOWN;
memset(&frame.sourceTiming, 0, sizeof(avifAppSourceTiming));
Expand Down Expand Up @@ -338,8 +339,7 @@ avifBool y4mRead(const char * inputFilename, avifImage * avif, avifAppSourceTimi
goto cleanup;
}

if ((frame.width < 1) || (frame.height < 1) || ((frame.depth != 8) && (frame.depth != 10) && (frame.depth != 12)) ||
(frame.format == AVIF_PIXEL_FORMAT_NONE)) {
if ((frame.width < 1) || (frame.height < 1) || ((frame.depth != 8) && (frame.depth != 10) && (frame.depth != 12))) {
fprintf(stderr, "Failed to parse y4m header (not enough information): %s\n", frame.displayFilename);
goto cleanup;
}
Expand Down

0 comments on commit 5dfa7da

Please sign in to comment.