]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/mp3.c
ff_msmpeg4_decode_init() calls ff_h263_decode_init() which calls
[ffmpeg] / libavformat / mp3.c
index 2b493e2459bc4a98470f5b1c31ced456d773b20b..45797733699fab41417bd9a2d4c75c075d19b1d1 100644 (file)
@@ -143,11 +143,15 @@ static int mp3_read_header(AVFormatContext *s,
     st->need_parsing = AVSTREAM_PARSE_FULL;
     st->start_time = 0;
 
+    // lcm of all mp3 sample rates
+    av_set_pts_info(st, 64, 1, 14112000);
+
     ff_id3v2_read(s);
+    off = url_ftell(s->pb);
+
     if (!av_metadata_get(s->metadata, "", NULL, AV_METADATA_IGNORE_SUFFIX))
         ff_id3v1_read(s);
 
-    off = url_ftell(s->pb);
     if (mp3_parse_vbr_tags(s, st, off) < 0)
         url_fseek(s->pb, off, SEEK_SET);
 
@@ -211,7 +215,7 @@ static int id3v1_create_tag(AVFormatContext *s, uint8_t *buf)
     count += id3v1_set_string(s, "title",   buf +  3, 30);
     count += id3v1_set_string(s, "author",  buf + 33, 30);
     count += id3v1_set_string(s, "album",   buf + 63, 30);
-    count += id3v1_set_string(s, "year",    buf + 93,  4);
+    count += id3v1_set_string(s, "date",    buf + 93,  4);
     count += id3v1_set_string(s, "comment", buf + 97, 30);
     if ((tag = av_metadata_get(s->metadata, "track", NULL, 0))) {
         buf[125] = 0;
@@ -252,6 +256,42 @@ static void id3v2_put_ttag(AVFormatContext *s, const char *buf, int len,
 }
 
 
+static int mp3_write_packet(struct AVFormatContext *s, AVPacket *pkt)
+{
+    put_buffer(s->pb, pkt->data, pkt->size);
+    put_flush_packet(s->pb);
+    return 0;
+}
+
+static int mp3_write_trailer(struct AVFormatContext *s)
+{
+    uint8_t buf[ID3v1_TAG_SIZE];
+
+    /* write the id3v1 tag */
+    if (id3v1_create_tag(s, buf) > 0) {
+        put_buffer(s->pb, buf, ID3v1_TAG_SIZE);
+        put_flush_packet(s->pb);
+    }
+    return 0;
+}
+#endif /* CONFIG_MP2_MUXER || CONFIG_MP3_MUXER */
+
+#if CONFIG_MP2_MUXER
+AVOutputFormat mp2_muxer = {
+    "mp2",
+    NULL_IF_CONFIG_SMALL("MPEG audio layer 2"),
+    "audio/x-mpeg",
+    "mp2,m2a",
+    0,
+    CODEC_ID_MP2,
+    CODEC_ID_NONE,
+    NULL,
+    mp3_write_packet,
+    mp3_write_trailer,
+};
+#endif
+
+#if CONFIG_MP3_MUXER
 /**
  * Write an ID3v2.4 header at beginning of stream
  */
@@ -273,7 +313,7 @@ static int mp3_write_header(struct AVFormatContext *s)
     while ((t = av_metadata_get(s->metadata, "", t, AV_METADATA_IGNORE_SUFFIX))) {
         uint32_t tag = 0;
 
-        if (t->key[0] == 'T' && strcmp(t->key, "TSSE")) {
+        if (t->key[0] == 'T' && strlen(t->key) == 4) {
             int i;
             for (i = 0; *ff_id3v2_tags[i]; i++)
                 if (AV_RB32(t->key) == AV_RB32(ff_id3v2_tags[i])) {
@@ -298,11 +338,6 @@ static int mp3_write_header(struct AVFormatContext *s)
             av_free(buf);
         }
     }
-    if(!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) {
-        totlen += strlen(LIBAVFORMAT_IDENT) + ID3v2_HEADER_SIZE + 2;
-        id3v2_put_ttag(s, LIBAVFORMAT_IDENT, strlen(LIBAVFORMAT_IDENT) + 1,
-                       MKBETAG('T', 'S', 'S', 'E'));
-    }
 
     cur_pos = url_ftell(s->pb);
     url_fseek(s->pb, size_pos, SEEK_SET);
@@ -312,41 +347,6 @@ static int mp3_write_header(struct AVFormatContext *s)
     return 0;
 }
 
-static int mp3_write_packet(struct AVFormatContext *s, AVPacket *pkt)
-{
-    put_buffer(s->pb, pkt->data, pkt->size);
-    put_flush_packet(s->pb);
-    return 0;
-}
-
-static int mp3_write_trailer(struct AVFormatContext *s)
-{
-    uint8_t buf[ID3v1_TAG_SIZE];
-
-    /* write the id3v1 tag */
-    if (id3v1_create_tag(s, buf) > 0) {
-        put_buffer(s->pb, buf, ID3v1_TAG_SIZE);
-        put_flush_packet(s->pb);
-    }
-    return 0;
-}
-#endif /* CONFIG_MP2_MUXER || CONFIG_MP3_MUXER */
-
-#if CONFIG_MP2_MUXER
-AVOutputFormat mp2_muxer = {
-    "mp2",
-    NULL_IF_CONFIG_SMALL("MPEG audio layer 2"),
-    "audio/x-mpeg",
-    "mp2,m2a",
-    0,
-    CODEC_ID_MP2,
-    CODEC_ID_NONE,
-    NULL,
-    mp3_write_packet,
-    mp3_write_trailer,
-};
-#endif
-#if CONFIG_MP3_MUXER
 AVOutputFormat mp3_muxer = {
     "mp3",
     NULL_IF_CONFIG_SMALL("MPEG audio layer 3"),