On Mon, Mar 28, 2011 at 3:36 AM, Anton Khirnov <[email protected]> wrote:
> ---
>  libavcodec/Makefile  |    1 +
>  libavformat/mp3enc.c |   74 ++++++++++++++++++++++++++++++++++++++++++++++---
>  2 files changed, 70 insertions(+), 5 deletions(-)
>
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index 85d9a34..f9b1bf8 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -530,6 +530,7 @@ OBJS-$(CONFIG_MATROSKA_DEMUXER)        += mpeg4audio.o 
> mpegaudiodata.o
>  OBJS-$(CONFIG_MATROSKA_MUXER)          += xiph.o mpeg4audio.o \
>                                           flacdec.o flacdata.o flac.o \
>                                           mpegaudiodata.o
> +OBJS-$(CONFIG_MP3_MUXER)               += mpegaudiodata.o 
> mpegaudiodecheader.o
>  OBJS-$(CONFIG_MOV_DEMUXER)             += mpeg4audio.o mpegaudiodata.o
>  OBJS-$(CONFIG_MOV_MUXER)               += mpeg4audio.o mpegaudiodata.o
>  OBJS-$(CONFIG_MPEGTS_MUXER)            += mpegvideo.o mpeg4audio.o
> diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c
> index 8514ad1..af37ad7 100644
> --- a/libavformat/mp3enc.c
> +++ b/libavformat/mp3enc.c
> @@ -21,9 +21,12 @@
>
>  #include <strings.h>
>  #include "avformat.h"
> +#include "avio_internal.h"
>  #include "id3v1.h"
>  #include "id3v2.h"
>  #include "rawenc.h"
> +#include "libavcodec/mpegaudiodata.h"
> +#include "libavcodec/mpegaudiodecheader.h"
>  #include "libavutil/intreadwrite.h"
>  #include "libavutil/opt.h"
>
> @@ -126,15 +129,31 @@ static int id3v2_put_ttag(AVFormatContext *s, const 
> char *str1, const char *str2
>     return len + ID3v2_HEADER_SIZE;
>  }
>
> +typedef struct MP3Context {
> +    const AVClass *class;
> +    int id3v2_version;
> +    int64_t nb_frames_offset;
> +} MP3Context;
> +
>  static int mp3_write_trailer(struct AVFormatContext *s)
>  {
>     uint8_t buf[ID3v1_TAG_SIZE];
> +    MP3Context *mp3 = s->priv_data ? s->priv_data : NULL;

MP3Context *mp3 = s->priv_data;

>
>     /* write the id3v1 tag */
>     if (id3v1_create_tag(s, buf) > 0) {
>         avio_write(s->pb, buf, ID3v1_TAG_SIZE);
> -        avio_flush(s->pb);
>     }
> +
> +    /* write number of frames */
> +    if (mp3 && mp3->nb_frames_offset) {
> +        avio_seek(s->pb, mp3->nb_frames_offset, SEEK_SET);
> +        avio_wb32(s->pb, s->streams[0]->nb_frames);
> +        avio_seek(s->pb, 0, SEEK_END);
> +    }
> +
> +    avio_flush(s->pb);
> +
>     return 0;
>  }
>

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

Reply via email to