* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avformat.h"
-#include "avi.h"
+#include "riff.h"
#include "avio.h"
-#include "mov.h"
+#include "isom.h"
#undef NDEBUG
#include <assert.h>
int64_t trackDuration;
long sampleCount;
long sampleDuration;
+ long sampleSize;
int hasKeyframes;
int hasBframes;
int language;
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_byte(pb, 0); /* decoder version */
- //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_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;
}
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 */
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);
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) */
put_be16(pb, track->timescale); /* Time scale */
put_be16(pb, 0); /* Reserved */
- if(version == 1) {
- /* SoundDescription V1 extended info */
+ if(version == 1) { /* SoundDescription V1 extended info */
+ if (vbr)
+ track->sampleSize = 0;
put_be32(pb, track->enc->frame_size); /* Samples per packet */
- /* Parameters tested on quicktime 6.5, 7 */
- put_be32(pb, 1); /* Bytes per packet */
- /* FIXME not correct */
- /* 8 is the min value needed for in32 to work with quicktime 6.5 */
- /* Value ignored by other codecs currently supported (others might need it) */
- put_be32(pb, 8); /* Bytes per frame */
+ 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 */
}
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);
}
}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);
+ 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;
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_TYPE_AUDIO) {
- switch (enc->codec_id) {
- case 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};
- int len = 0;
-
- while (len < size && samplesInChunk < 100) {
- len += packed_size[(pkt->data[len] >> 3) & 0x0F];
- samplesInChunk++;
- }
- }
- break;
- case CODEC_ID_PCM_MULAW:
- case CODEC_ID_PCM_ALAW:
- samplesInChunk = size/enc->channels;
- break;
- case CODEC_ID_PCM_S16BE:
- case CODEC_ID_PCM_S16LE:
- samplesInChunk = size/(2*enc->channels);
- break;
- case CODEC_ID_PCM_S24BE:
- case CODEC_ID_PCM_S24LE:
- samplesInChunk = size/(3*enc->channels);
- break;
- case CODEC_ID_PCM_S32BE:
- case CODEC_ID_PCM_S32LE:
- samplesInChunk = size/(4*enc->channels);
- break;
- default:
- samplesInChunk = 1;
+ 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};
+ int len = 0;
+
+ while (len < size && samplesInChunk < 100) {
+ len += packed_size[(pkt->data[len] >> 3) & 0x0F];
+ samplesInChunk++;
}
- } else {
+ 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
samplesInChunk = 1;
- }
/* copy extradata if it exists */
if (trk->vosLen == 0 && enc->extradata_size > 0) {
return res;
}
-static AVOutputFormat mov_oformat = {
+#ifdef CONFIG_MOV_MUXER
+AVOutputFormat mov_muxer = {
"mov",
"mov format",
NULL,
mov_write_trailer,
.flags = AVFMT_GLOBALHEADER,
};
-
-static AVOutputFormat _3gp_oformat = {
+#endif
+#ifdef CONFIG_TGP_MUXER
+AVOutputFormat tgp_muxer = {
"3gp",
"3gp format",
NULL,
mov_write_trailer,
.flags = AVFMT_GLOBALHEADER,
};
-
-static AVOutputFormat mp4_oformat = {
+#endif
+#ifdef CONFIG_MP4_MUXER
+AVOutputFormat mp4_muxer = {
"mp4",
"mp4 format",
"application/mp4",
mov_write_trailer,
.flags = AVFMT_GLOBALHEADER,
};
-
-static AVOutputFormat psp_oformat = {
+#endif
+#ifdef CONFIG_PSP_MUXER
+AVOutputFormat psp_muxer = {
"psp",
"psp mp4 format",
NULL,
mov_write_trailer,
.flags = AVFMT_GLOBALHEADER,
};
-
-static AVOutputFormat _3g2_oformat = {
+#endif
+#ifdef CONFIG_TG2_MUXER
+AVOutputFormat tg2_muxer = {
"3g2",
"3gp2 format",
NULL,
mov_write_trailer,
.flags = AVFMT_GLOBALHEADER,
};
-
-int movenc_init(void)
-{
- av_register_output_format(&mov_oformat);
- av_register_output_format(&_3gp_oformat);
- av_register_output_format(&mp4_oformat);
- av_register_output_format(&psp_oformat);
- av_register_output_format(&_3g2_oformat);
- return 0;
-}
+#endif