Skip to content

Commit

Permalink
avformat/segafilmenc: Check early whether video is allowed
Browse files Browse the repository at this point in the history
The current code only checks when writing the trailer whether the video
format and Codec ID are actually compatible with the container. At this
point, a lot of data will already have been written (in vain, of
course), so check during the init function instead.

Signed-off-by: Andreas Rheinhardt <[email protected]>
Signed-off-by: Michael Niedermayer <[email protected]>
  • Loading branch information
mkver authored and michaelni committed Jan 14, 2020
1 parent 30859c2 commit 56a04b7
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions libavformat/segafilmenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,17 @@ static int film_init(AVFormatContext *format_context)
av_log(format_context, AV_LOG_ERROR, "Sega FILM allows a maximum of one video stream.\n");
return AVERROR(EINVAL);
}
if (st->codecpar->codec_id != AV_CODEC_ID_CINEPAK &&
st->codecpar->codec_id != AV_CODEC_ID_RAWVIDEO) {
av_log(format_context, AV_LOG_ERROR,
"Incompatible video stream format.\n");
return AVERROR(EINVAL);
}
if (st->codecpar->format != AV_PIX_FMT_RGB24) {
av_log(format_context, AV_LOG_ERROR,
"Pixel format must be rgb24.\n");
return AVERROR(EINVAL);
}
film->video_index = i;
}
}
Expand Down Expand Up @@ -293,11 +304,6 @@ static int film_write_header(AVFormatContext *format_context)
}
}

if (video->codecpar->format != AV_PIX_FMT_RGB24) {
av_log(format_context, AV_LOG_ERROR, "Pixel format must be rgb24.\n");
return AVERROR(EINVAL);
}

/* First, write the FILM header; this is very simple */

ffio_wfourcc(pb, "FILM");
Expand All @@ -320,9 +326,6 @@ static int film_write_header(AVFormatContext *format_context)
case AV_CODEC_ID_RAWVIDEO:
ffio_wfourcc(pb, "raw ");
break;
default:
av_log(format_context, AV_LOG_ERROR, "Incompatible video stream format.\n");
return AVERROR(EINVAL);
}

avio_wb32(pb, video->codecpar->height);
Expand Down

0 comments on commit 56a04b7

Please sign in to comment.