]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/movenc.c
Etsi identifies DTS audio with stream_private+descriptor 0x7b (in the PMT).
[ffmpeg] / libavformat / movenc.c
index dc18ccdb3742533e3232e6d2dddd5a9fb3b9427a..30e3b001d8568d2d16a33121c5bd87998ba06f29 100644 (file)
@@ -200,29 +200,17 @@ static int mov_write_stss_tag(ByteIOContext *pb, MOVTrack* track)
     return updateSize (pb, pos);
 }
 
-static int mov_write_damr_tag(ByteIOContext *pb)
+static int mov_write_amr_tag(ByteIOContext *pb, MOVTrack *track)
 {
     put_be32(pb, 0x11); /* size */
-    put_tag(pb, "damr");
+    if (track->mode == MODE_MOV) put_tag(pb, "samr");
+    else                         put_tag(pb, "damr");
     put_tag(pb, "FFMP");
-    put_byte(pb, 0);
-
-    //put_be16(pb, 0x80); /* Mode set (all modes for AMR_NB) */
-    //put_be16(pb, 0xa); /* Mode change period (no restriction) */
-    put_be16(pb, 0x81ff); /* Mode set (all modes for AMR_NB) */
-    put_be16(pb, 1); /* Mode change period (no restriction) */
-    return 0x11;
-}
-
-static int mov_write_samr_tag(ByteIOContext *pb)
-{
-    put_be32(pb, 0x11); /* size */
-    put_tag(pb, "samr");
-    put_tag(pb, "FFMP");
-    put_byte(pb, 1);
+    put_byte(pb, 0); /* decoder version */
 
-    put_be16(pb, 0x80); /* Mode set (all modes for AMR_NB) */
-    put_be16(pb, 0x5); /* Mode change period (no restriction) */
+    put_be16(pb, 0x81FF); /* Mode set (all modes for AMR_NB) */
+    put_byte(pb, 0x00); /* Mode change period (no restriction) */
+    put_byte(pb, 0x01); /* Frames per sample */
     return 0x11;
 }
 
@@ -322,7 +310,7 @@ static int mov_write_wave_tag(ByteIOContext *pb, MOVTrack* track)
                track->enc->codec_id == CODEC_ID_PCM_S32LE) {
         mov_write_enda_tag(pb);
     } else if (track->enc->codec_id == CODEC_ID_AMR_NB) {
-        mov_write_samr_tag(pb);
+        mov_write_amr_tag(pb, track);
     }
 
     put_be32(pb, 8);     /* size */
@@ -353,9 +341,11 @@ static const CodecTag codec_movaudio_tags[] = {
 static int mov_write_audio_tag(ByteIOContext *pb, MOVTrack* track)
 {
     offset_t pos = url_ftell(pb);
+    int vbr=  track->enc->codec_id == CODEC_ID_AAC ||
+              track->enc->codec_id == CODEC_ID_MP3 ||
+              track->enc->codec_id == CODEC_ID_AMR_NB;
     int version = track->mode == MODE_MOV &&
-        (track->enc->codec_id == CODEC_ID_AAC ||
-         track->enc->codec_id == CODEC_ID_MP3 ||
+        (vbr ||
          track->enc->codec_id == CODEC_ID_PCM_S32LE ||
          track->enc->codec_id == CODEC_ID_PCM_S24LE);
 
@@ -375,9 +365,7 @@ static int mov_write_audio_tag(ByteIOContext *pb, MOVTrack* track)
                  to be a good way to get number of bits of audio */
     put_be16(pb, 0x10); /* Reserved */
 
-    if(track->enc->codec_id == CODEC_ID_AAC ||
-       track->enc->codec_id == CODEC_ID_MP3 ||
-       track->enc->codec_id == CODEC_ID_AMR_NB) {
+    if(vbr) {
         put_be16(pb, 0xfffe); /* compression ID (vbr)*/
     } else {
         put_be16(pb, 0); /* compression ID (= 0) */
@@ -387,13 +375,10 @@ static int mov_write_audio_tag(ByteIOContext *pb, MOVTrack* track)
     put_be16(pb, 0); /* Reserved */
 
     if(version == 1) { /* SoundDescription V1 extended info */
-        /* Parameters tested on quicktime 6.5, 7 */
-        if (track->enc->codec_id == CODEC_ID_MP3)
-            track->sampleSize = 666;
-        if (track->enc->codec_id == CODEC_ID_AAC)
-            track->sampleSize = 2;
+        if (vbr)
+            track->sampleSize = 0;
         put_be32(pb, track->enc->frame_size); /* Samples per packet */
-        put_be32(pb, track->sampleSize / 2); /* Bytes per packet */
+        put_be32(pb, track->sampleSize / track->enc->channels); /* Bytes per packet */
         put_be32(pb, track->sampleSize); /* Bytes per frame */
         put_be32(pb, 2); /* Bytes per sample */
     }
@@ -407,7 +392,7 @@ static int mov_write_audio_tag(ByteIOContext *pb, MOVTrack* track)
     else if(track->enc->codec_id == CODEC_ID_AAC)
         mov_write_esds_tag(pb, track);
     else if(track->enc->codec_id == CODEC_ID_AMR_NB)
-        mov_write_damr_tag(pb);
+        mov_write_amr_tag(pb, track);
 
     return updateSize (pb, pos);
 }
@@ -1478,27 +1463,7 @@ static int mov_write_header(AVFormatContext *s)
         }else if(st->codec->codec_type == CODEC_TYPE_AUDIO){
             track->tag = mov_find_audio_codec_tag(s, track);
             av_set_pts_info(st, 64, 1, st->codec->sample_rate);
-
-            switch (st->codec->codec_id) {
-            case CODEC_ID_PCM_MULAW:
-            case CODEC_ID_PCM_ALAW:
-                track->sampleSize = 1 * st->codec->channels;
-                break;
-            case CODEC_ID_PCM_S16BE:
-            case CODEC_ID_PCM_S16LE:
-                track->sampleSize = 2 * st->codec->channels;
-                break;
-            case CODEC_ID_PCM_S24BE:
-            case CODEC_ID_PCM_S24LE:
-                track->sampleSize = 3 * st->codec->channels;
-                break;
-            case CODEC_ID_PCM_S32BE:
-            case CODEC_ID_PCM_S32LE:
-                track->sampleSize = 4 * st->codec->channels;
-                break;
-            default:
-                track->sampleSize = 0;
-            }
+            track->sampleSize = (av_get_bits_per_sample(st->codec->codec_id) >> 3) * st->codec->channels;
         }
         track->language = ff_mov_iso639_to_lang(st->language, mov->mode != MODE_MOV);
         track->mode = mov->mode;
@@ -1525,7 +1490,7 @@ static int mov_write_packet(AVFormatContext *s, AVPacket *pkt)
     if (url_is_streamed(&s->pb)) return 0; /* Can't handle that */
     if (!size) return 0; /* Discard 0 sized packets */
 
-    if (enc->codec_type == CODEC_ID_AMR_NB) {
+    if (enc->codec_id == CODEC_ID_AMR_NB) {
         /* We must find out how many AMR blocks there are in one packet */
         static uint16_t packed_size[16] =
             {13, 14, 16, 18, 20, 21, 27, 32, 6, 0, 0, 0, 0, 0, 0, 0};
@@ -1535,6 +1500,10 @@ static int mov_write_packet(AVFormatContext *s, AVPacket *pkt)
             len += packed_size[(pkt->data[len] >> 3) & 0x0F];
             samplesInChunk++;
         }
+        if(samplesInChunk > 1){
+            av_log(s, AV_LOG_ERROR, "fatal error, input is not a single packet, inplement a AVParser for it\n");
+            return -1;
+        }
     } else if (trk->sampleSize)
         samplesInChunk = size/trk->sampleSize;
     else