You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-15 14:13:16 +02:00
avformat/segafilmenc: Combine several checks
by moving them around. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
committed by
Michael Niedermayer
parent
ba2581adb2
commit
ab44f0aee8
@@ -155,7 +155,6 @@ static int get_audio_codec_id(enum AVCodecID codec_id)
|
|||||||
|
|
||||||
static int film_init(AVFormatContext *format_context)
|
static int film_init(AVFormatContext *format_context)
|
||||||
{
|
{
|
||||||
AVStream *audio = NULL;
|
|
||||||
FILMOutputContext *film = format_context->priv_data;
|
FILMOutputContext *film = format_context->priv_data;
|
||||||
film->audio_index = -1;
|
film->audio_index = -1;
|
||||||
film->video_index = -1;
|
film->video_index = -1;
|
||||||
@@ -171,8 +170,12 @@ static int film_init(AVFormatContext *format_context)
|
|||||||
av_log(format_context, AV_LOG_ERROR, "Sega FILM allows a maximum of one audio stream.\n");
|
av_log(format_context, AV_LOG_ERROR, "Sega FILM allows a maximum of one audio stream.\n");
|
||||||
return AVERROR(EINVAL);
|
return AVERROR(EINVAL);
|
||||||
}
|
}
|
||||||
|
if (get_audio_codec_id(st->codecpar->codec_id) < 0) {
|
||||||
|
av_log(format_context, AV_LOG_ERROR,
|
||||||
|
"Incompatible audio stream format.\n");
|
||||||
|
return AVERROR(EINVAL);
|
||||||
|
}
|
||||||
film->audio_index = i;
|
film->audio_index = i;
|
||||||
audio = st;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
|
if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
|
||||||
@@ -200,11 +203,6 @@ static int film_init(AVFormatContext *format_context)
|
|||||||
return AVERROR(EINVAL);
|
return AVERROR(EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (audio != NULL && get_audio_codec_id(audio->codecpar->codec_id) < 0) {
|
|
||||||
av_log(format_context, AV_LOG_ERROR, "Incompatible audio stream format.\n");
|
|
||||||
return AVERROR(EINVAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,11 +267,9 @@ static int film_write_header(AVFormatContext *format_context)
|
|||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int64_t sample_table_size, stabsize, headersize;
|
int64_t sample_table_size, stabsize, headersize;
|
||||||
int8_t audio_codec;
|
|
||||||
AVIOContext *pb = format_context->pb;
|
AVIOContext *pb = format_context->pb;
|
||||||
FILMOutputContext *film = format_context->priv_data;
|
FILMOutputContext *film = format_context->priv_data;
|
||||||
FILMPacket *prev, *packet;
|
FILMPacket *prev, *packet;
|
||||||
AVStream *audio = NULL;
|
|
||||||
AVStream *video = NULL;
|
AVStream *video = NULL;
|
||||||
|
|
||||||
/* Calculate how much we need to reserve for the header;
|
/* Calculate how much we need to reserve for the header;
|
||||||
@@ -290,13 +286,6 @@ static int film_write_header(AVFormatContext *format_context)
|
|||||||
/* Seek back to the beginning to start writing the header now */
|
/* Seek back to the beginning to start writing the header now */
|
||||||
avio_seek(pb, 0, SEEK_SET);
|
avio_seek(pb, 0, SEEK_SET);
|
||||||
|
|
||||||
if (film->audio_index > -1)
|
|
||||||
audio = format_context->streams[film->audio_index];
|
|
||||||
|
|
||||||
if (audio != NULL) {
|
|
||||||
audio_codec = get_audio_codec_id(audio->codecpar->codec_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* First, write the FILM header; this is very simple */
|
/* First, write the FILM header; this is very simple */
|
||||||
|
|
||||||
ffio_wfourcc(pb, "FILM");
|
ffio_wfourcc(pb, "FILM");
|
||||||
@@ -327,7 +316,10 @@ static int film_write_header(AVFormatContext *format_context)
|
|||||||
avio_wb32(pb, video->codecpar->width);
|
avio_wb32(pb, video->codecpar->width);
|
||||||
avio_w8(pb, 24); /* Bits per pixel - observed to always be 24 */
|
avio_w8(pb, 24); /* Bits per pixel - observed to always be 24 */
|
||||||
|
|
||||||
if (audio != NULL) {
|
if (film->audio_index > -1) {
|
||||||
|
AVStream *audio = format_context->streams[film->audio_index];
|
||||||
|
int audio_codec = get_audio_codec_id(audio->codecpar->codec_id);
|
||||||
|
|
||||||
avio_w8(pb, audio->codecpar->channels); /* Audio channels */
|
avio_w8(pb, audio->codecpar->channels); /* Audio channels */
|
||||||
avio_w8(pb, audio->codecpar->bits_per_coded_sample); /* Audio bit depth */
|
avio_w8(pb, audio->codecpar->bits_per_coded_sample); /* Audio bit depth */
|
||||||
avio_w8(pb, audio_codec); /* Compression - 0 is PCM, 2 is ADX */
|
avio_w8(pb, audio_codec); /* Compression - 0 is PCM, 2 is ADX */
|
||||||
|
Reference in New Issue
Block a user