[FFmpeg-devel] [PATCH 1/1] Add Sega FILM muxer

Michael Niedermayer michael at niedermayer.cc
Fri Mar 23 21:23:38 EET 2018


On Wed, Mar 21, 2018 at 10:46:31PM -0700, misty at brew.sh wrote:
> From: Misty De Meo <mistydemeo at gmail.com>
[...]

> +static int film_write_header(AVFormatContext *format_context)
> +{
> +    int ret = 0;
> +    int64_t stabstart_pos, sample_table_size, stabsize, headersize;
> +    int8_t audio_codec;
> +    AVIOContext *pb = format_context->pb;
> +    FILMOutputContext *film = format_context->priv_data;
> +    FILMPacket *prev, *packet;
> +    AVStream *audio = NULL;
> +    AVStream *video = NULL;
> +
> +    /* Calculate how much we need to reserve for the header;
> +     * this is the amount the rest of the data will be shifted up by. */
> +    sample_table_size = film->packet_count * 16;
> +    stabsize = 16 + sample_table_size;
> +    headersize = 16 + // FILM header base
> +                 32 + // FDSC chunk
> +                 stabsize;
> +
> +    ret = shift_data(format_context, headersize);
> +    if (ret < 0)
> +        return ret;
> +    // Seek back to the beginning to start writing the header now
> +    avio_seek(pb, 0, SEEK_SET);
> +
> +    if (film->audio_index > -1)
> +        audio = format_context->streams[film->audio_index];
> +    if (film->video_index > -1)
> +        video = format_context->streams[film->video_index];
> +
> +    if (audio != NULL) {
> +        audio_codec = get_audio_codec_id(audio->codecpar->codec_id);
> +        if (audio_codec < 0) {
> +            av_log(format_context, AV_LOG_ERROR, "Incompatible audio stream format.\n");
> +            return AVERROR(EINVAL);
> +        }
> +    }
> +
> +    // First, write the FILM header; this is very simple
> +
> +    ffio_wfourcc(pb, "FILM");
> +    avio_wb32(pb, 48 + stabsize);
> +    /* This seems to be okay to hardcode, since this muxer targets 1.09 features;
> +     * videos produced by this muxer are readable by 1.08 and lower players. */
> +    ffio_wfourcc(pb, "1.09");
> +    // I have no idea what this field does, might be reserved
> +    avio_wb32(pb, 0);
> +
> +    // Next write the FDSC (file description) chunk
> +    ffio_wfourcc(pb, "FDSC");
> +    avio_wb32(pb, 0x20); // Size of FDSC chunk
> +    // TODO stop hardcoding this if support for another codec is added
> +    ffio_wfourcc(pb, "cvid");
> +    avio_wb32(pb, video->codecpar->height);
> +    avio_wb32(pb, video->codecpar->width);
> +    avio_w8(pb, 24); // Bits per pixel - observed to always be 24
> +
> +    if (audio != NULL) {
> +        avio_w8(pb, audio->codecpar->channels); // Audio channels
> +        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_wb16(pb, audio->codecpar->sample_rate); // Audio sampling rate
> +    } else {
> +        // Set all these fields to 0 if there's no audio
> +        avio_w8(pb, 0);
> +        avio_w8(pb, 0);
> +        avio_w8(pb, 0);
> +        avio_wb16(pb, 0);
> +    }
> +
> +    // I have no idea what this pair of fields does either, might be reserved
> +    avio_wb32(pb, 0);
> +    avio_wb16(pb, 0);
> +

> +    // Finally, write the STAB (sample table) chunk
> +    stabstart_pos = avio_tell(pb);

this is set but never used


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Take away the freedom of one citizen and you will be jailed, take away
the freedom of all citizens and you will be congratulated by your peers
in Parliament.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20180323/1a1542f3/attachment.sig>


More information about the ffmpeg-devel mailing list