On Fri, Jan 13, 2012 at 03:34:04AM +0000, Paul B Mahol wrote:
> ---
>  doc/general.texi         |    2 +-
>  libavformat/Makefile     |    1 +
>  libavformat/allformats.c |    2 +-
>  libavformat/smjpeg.c     |  101 ++++++++++++++++++++++++++++++++++++++++++++-
>  4 files changed, 101 insertions(+), 5 deletions(-)

Now we need some game engine from Loki to reuse newly-created videos :)
 
> diff --git a/doc/general.texi b/doc/general.texi
> index 65d65bb..79af887 100644
> --- a/doc/general.texi
> +++ b/doc/general.texi
> @@ -296,7 +296,7 @@ library:
>      @tab Used in Sierra CD-ROM games.
>  @item Smacker                   @tab   @tab X
>      @tab Multimedia format used by many games.
> -@item SMJPEG                    @tab   @tab X
> +@item SMJPEG                    @tab X @tab X
>      @tab Used in certain Loki game ports.
>  @item Sony OpenMG (OMA)         @tab X @tab X
>      @tab Audio format used in Sony Sonic Stage and Sony Vegas.

Changelog and version bumps are needed too.

> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index 3902e89..bd97a7f 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -274,6 +274,7 @@ OBJS-$(CONFIG_SEGMENT_MUXER)             += segment.o
>  OBJS-$(CONFIG_SHORTEN_DEMUXER)           += rawdec.o
>  OBJS-$(CONFIG_SIFF_DEMUXER)              += siff.o
>  OBJS-$(CONFIG_SMACKER_DEMUXER)           += smacker.o
> +OBJS-$(CONFIG_SMJPEG_MUXER)              += smjpeg.o
>  OBJS-$(CONFIG_SMJPEG_DEMUXER)            += smjpeg.o
>  OBJS-$(CONFIG_SOL_DEMUXER)               += sol.o pcm.o
>  OBJS-$(CONFIG_SOX_DEMUXER)               += soxdec.o pcm.o
> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> index 523b113..481d2c1 100644
> --- a/libavformat/allformats.c
> +++ b/libavformat/allformats.c
> @@ -201,7 +201,7 @@ void av_register_all(void)
>      REGISTER_DEMUXER  (SHORTEN, shorten);
>      REGISTER_DEMUXER  (SIFF, siff);
>      REGISTER_DEMUXER  (SMACKER, smacker);
> -    REGISTER_DEMUXER  (SMJPEG, smjpeg);
> +    REGISTER_MUXDEMUX (SMJPEG, smjpeg);
>      REGISTER_DEMUXER  (SOL, sol);
>      REGISTER_MUXDEMUX (SOX, sox);
>      REGISTER_MUXDEMUX (SPDIF, spdif);
> diff --git a/libavformat/smjpeg.c b/libavformat/smjpeg.c
> index dc94361..6b5d0cb 100644
> --- a/libavformat/smjpeg.c
> +++ b/libavformat/smjpeg.c
> @@ -1,6 +1,6 @@
>  /*
> - * SMJPEG demuxer
> - * Copyright (c) 2011 Paul B Mahol
> + * SMJPEG format
> + * Copyright (c) 2011-2012 Paul B Mahol
>   *
>   * This file is part of Libav.
>   *
> @@ -21,7 +21,7 @@
>  
>  /**
>   * @file
> - * This is a demuxer for Loki SDL Motion JPEG files
> + * This is a format for Loki SDL Motion JPEG files
>   */
>  
>  #include "avformat.h"
> @@ -39,6 +39,100 @@ static const AVCodecTag codec_smjpeg_audio_tags[] = {
>      { CODEC_ID_NONE, 0 },
>  };
>  
> +#if CONFIG_SMJPEG_MUXER
> +static int smjpeg_write_header(AVFormatContext *s)
> +{
> +    AVDictionaryEntry *t = NULL;
> +    AVIOContext *pb = s->pb;
> +    int n;
> +
> +    if (s->nb_streams > 2) {
> +        av_log(s, AV_LOG_ERROR, "SMJPEG does not support >2 streams\n");
> +        return AVERROR_INVALIDDATA;
> +    }
> +    avio_write(pb, "\x0\xaSMJPEG", 8);
> +    avio_wb32(pb, 0);
> +    avio_wb32(pb, 0);
> +
> +    while ((t = av_dict_get(s->metadata, "", t, AV_DICT_IGNORE_SUFFIX))) {
> +        avio_wl32(pb, MKTAG('_', 'T', 'X', 'T'));
> +        avio_wb32(pb, strlen(t->key) + strlen(t->value) + 3);
> +        avio_write(pb, t->key, strlen(t->key));
> +        avio_write(pb, " = ", 3);
> +        avio_write(pb, t->value, strlen(t->value));
> +    }
> +
> +    for (n = 0; n < s->nb_streams; n++) {
> +        AVStream *st = s->streams[n];
> +        AVCodecContext *codec = st->codec;
> +        if (codec->codec_type == AVMEDIA_TYPE_AUDIO) {
> +            avio_wl32(pb, MKTAG('_', 'S', 'N', 'D'));
> +            avio_wb32(pb, 8);
> +            avio_wb16(pb, codec->sample_rate);
> +            avio_w8(pb, codec->bits_per_coded_sample);
> +            avio_w8(pb, codec->channels);
> +            avio_wl32(pb, ff_codec_get_tag(codec_smjpeg_audio_tags, 
> codec->codec_id));
> +            avpriv_set_pts_info(st, 32, 1, 1000);
> +        } else if (codec->codec_type == AVMEDIA_TYPE_VIDEO) {
> +            avio_wl32(pb, MKTAG('_', 'V', 'I', 'D'));
> +            avio_wb32(pb, 12);
> +            avio_wb32(pb, codec->width);
> +            avio_wb32(pb, codec->height);
> +            avio_wl32(pb, ff_codec_get_tag(codec_smjpeg_video_tags, 
> codec->codec_id));
> +            avpriv_set_pts_info(st, 32, 1, 1000);
> +        }
> +    }
> +
> +    avio_wl32(pb, MKTAG('H', 'E', 'N', 'D'));
> +    avio_flush(pb);
> +
> +    return 0;
> +}
> +
> +static int smjpeg_write_packet(AVFormatContext *s, AVPacket *pkt)
> +{
> +    AVIOContext *pb = s->pb;
> +    AVStream *st = s->streams[pkt->stream_index];
> +    AVCodecContext *codec = st->codec;
> +
> +    if (codec->codec_type == AVMEDIA_TYPE_AUDIO)
> +       avio_wl32(pb, MKTAG('s', 'n', 'd', 'D'));
> +    else if (codec->codec_type == AVMEDIA_TYPE_VIDEO)
> +       avio_wl32(pb, MKTAG('v', 'i', 'd', 'D'));

weird indentation

> +    else
> +        return 0;
> +
> +    avio_wb32(pb, pkt->pts);
> +    avio_wb32(pb, pkt->size);
> +    avio_write(pb, pkt->data, pkt->size);
> +    avio_flush(pb);
> +
> +    return 0;
> +}
> +
> +static int smjpeg_write_trailer(AVFormatContext *s)
> +{
> +    AVIOContext *pb = s->pb;
> +
> +    avio_wl32(pb, MKTAG('D', 'O', 'N', 'E'));
> +    avio_flush(pb);
> +    return 0;
> +}
> +
> +AVOutputFormat ff_smjpeg_muxer = {
> +    .name           = "smjpeg",
> +    .long_name      = NULL_IF_CONFIG_SMALL("Loki SDL MJPEG"),
> +    .audio_codec    = CODEC_ID_PCM_S16LE,
> +    .video_codec    = CODEC_ID_MJPEG,
> +    .write_header   = smjpeg_write_header,
> +    .write_packet   = smjpeg_write_packet,
> +    .write_trailer  = smjpeg_write_trailer,
> +    .flags = AVFMT_GLOBALHEADER,
> +    .codec_tag = (const AVCodecTag *const []){ codec_smjpeg_video_tags, 
> codec_smjpeg_audio_tags, 0 },
> +};
> +#endif
> +
> +#if CONFIG_SMJPEG_DEMUXER
>  typedef struct SMJPEGContext {
>      int audio_stream_index;
>      int video_stream_index;
> @@ -185,3 +279,4 @@ AVInputFormat ff_smjpeg_demuxer = {
>      .read_packet    = smjpeg_read_packet,
>      .extensions     = "mjpg",
>  };
> +#endif
> -- 

Do they have common code? If not maybe it's better to put muxer into separate
file. Tags are easy to duplicate.

In general looks nice.
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to