/*
* MOV, 3GP, MP4 muxer
- * Copyright (c) 2003 Thomas Raivio.
- * Copyright (c) 2004 Gildas Bazin <gbazin at videolan dot org>.
+ * Copyright (c) 2003 Thomas Raivio
+ * Copyright (c) 2004 Gildas Bazin <gbazin at videolan dot org>
*
* This file is part of FFmpeg.
*
#include "avio.h"
#include "isom.h"
#include "avc.h"
+#include "libavcodec/bitstream.h"
#undef NDEBUG
#include <assert.h>
uint8_t *vosData;
MOVIentry *cluster;
int audio_vbr;
+ int height; ///< active picture (w/o VBI) height for D-10/IMX
} MOVTrack;
typedef struct MOVContext {
int mode;
int64_t time;
int nb_streams;
- offset_t mdat_pos;
+ int64_t mdat_pos;
uint64_t mdat_size;
long timescale;
MOVTrack tracks[MAX_STREAMS];
} MOVContext;
//FIXME support 64 bit variant with wide placeholders
-static offset_t updateSize(ByteIOContext *pb, offset_t pos)
+static int64_t updateSize(ByteIOContext *pb, int64_t pos)
{
- offset_t curpos = url_ftell(pb);
+ int64_t curpos = url_ftell(pb);
url_fseek(pb, pos, SEEK_SET);
put_be32(pb, curpos - pos); /* rewrite size */
url_fseek(pb, curpos, SEEK_SET);
{
int i;
int mode64 = 0; // use 32 bit size variant if possible
- offset_t pos = url_ftell(pb);
+ int64_t pos = url_ftell(pb);
put_be32(pb, 0); /* size */
if (pos > UINT32_MAX) {
mode64 = 1;
int equalChunks = 1;
int i, j, entries = 0, tst = -1, oldtst = -1;
- offset_t pos = url_ftell(pb);
+ int64_t pos = url_ftell(pb);
put_be32(pb, 0); /* size */
put_tag(pb, "stsz");
put_be32(pb, 0); /* version & flags */
static int mov_write_stsc_tag(ByteIOContext *pb, MOVTrack *track)
{
int index = 0, oldval = -1, i;
- offset_t entryPos, curpos;
+ int64_t entryPos, curpos;
- offset_t pos = url_ftell(pb);
+ int64_t pos = url_ftell(pb);
put_be32(pb, 0); /* size */
put_tag(pb, "stsc");
put_be32(pb, 0); // version & flags
/* Sync sample atom */
static int mov_write_stss_tag(ByteIOContext *pb, MOVTrack *track)
{
- offset_t curpos, entryPos;
+ int64_t curpos, entryPos;
int i, index = 0;
- offset_t pos = url_ftell(pb);
+ int64_t pos = url_ftell(pb);
put_be32(pb, 0); // size
put_tag(pb, "stss");
put_be32(pb, 0); // version & flags
return 0x11;
}
+static int mov_write_ac3_tag(ByteIOContext *pb, MOVTrack *track)
+{
+ GetBitContext gbc;
+ PutBitContext pbc;
+ uint8_t buf[3];
+ int fscod, bsid, bsmod, acmod, lfeon, frmsizecod;
+
+ if (track->vosLen < 7)
+ return -1;
+
+ put_be32(pb, 11);
+ put_tag(pb, "dac3");
+
+ init_get_bits(&gbc, track->vosData+4, track->vosLen-4);
+ fscod = get_bits(&gbc, 2);
+ frmsizecod = get_bits(&gbc, 6);
+ bsid = get_bits(&gbc, 5);
+ bsmod = get_bits(&gbc, 3);
+ acmod = get_bits(&gbc, 3);
+ if (acmod == 2) {
+ skip_bits(&gbc, 2); // dsurmod
+ } else {
+ if ((acmod & 1) && acmod != 1)
+ skip_bits(&gbc, 2); // cmixlev
+ if (acmod & 4)
+ skip_bits(&gbc, 2); // surmixlev
+ }
+ lfeon = get_bits1(&gbc);
+
+ init_put_bits(&pbc, buf, sizeof(buf));
+ put_bits(&pbc, 2, fscod);
+ put_bits(&pbc, 5, bsid);
+ put_bits(&pbc, 3, bsmod);
+ put_bits(&pbc, 3, acmod);
+ put_bits(&pbc, 1, lfeon);
+ put_bits(&pbc, 5, frmsizecod>>1); // bit_rate_code
+ put_bits(&pbc, 5, 0); // reserved
+
+ flush_put_bits(&pbc);
+ put_buffer(pb, buf, sizeof(buf));
+
+ return 11;
+}
+
/**
* This function writes extradata "as is".
* Extradata must be formated like a valid atom (with size and tag)
static int mov_write_esds_tag(ByteIOContext *pb, MOVTrack *track) // Basic
{
- offset_t pos = url_ftell(pb);
+ int64_t pos = url_ftell(pb);
int decoderSpecificInfoLen = track->vosLen ? descrLength(track->vosLen):0;
put_be32(pb, 0); // size
putDescr(pb, 0x04, 13 + decoderSpecificInfoLen);
// Object type indication
- put_byte(pb, codec_get_tag(ff_mp4_obj_type, track->enc->codec_id));
+ if ((track->enc->codec_id == CODEC_ID_MP2 ||
+ track->enc->codec_id == CODEC_ID_MP3) &&
+ track->enc->sample_rate > 24000)
+ put_byte(pb, 0x6B); // 11172-3
+ else
+ put_byte(pb, codec_get_tag(ff_mp4_obj_type, track->enc->codec_id));
// the following fields is made of 6 bits to identify the streamtype (4 for video, 5 for audio)
// plus 1 bit to indicate upstream and 1 bit set to 1 (reserved)
static int mov_write_wave_tag(ByteIOContext *pb, MOVTrack *track)
{
- offset_t pos = url_ftell(pb);
+ int64_t pos = url_ftell(pb);
put_be32(pb, 0); /* size */
put_tag(pb, "wave");
mov_write_enda_tag(pb);
} else if (track->enc->codec_id == CODEC_ID_AMR_NB) {
mov_write_amr_tag(pb, track);
+ } else if (track->enc->codec_id == CODEC_ID_AC3) {
+ mov_write_ac3_tag(pb, track);
} else if (track->enc->codec_id == CODEC_ID_ALAC) {
mov_write_extradata_tag(pb, track);
}
static int mov_write_audio_tag(ByteIOContext *pb, MOVTrack *track)
{
- offset_t pos = url_ftell(pb);
+ int64_t pos = url_ftell(pb);
int version = track->mode == MODE_MOV &&
(track->audio_vbr ||
track->enc->codec_id == CODEC_ID_PCM_S32LE ||
if(track->mode == MODE_MOV &&
(track->enc->codec_id == CODEC_ID_AAC ||
+ track->enc->codec_id == CODEC_ID_AC3 ||
track->enc->codec_id == CODEC_ID_AMR_NB ||
track->enc->codec_id == CODEC_ID_PCM_S24LE ||
track->enc->codec_id == CODEC_ID_PCM_S32LE ||
mov_write_esds_tag(pb, track);
else if(track->enc->codec_id == CODEC_ID_AMR_NB)
mov_write_amr_tag(pb, track);
- else if (track->enc->codec_id == CODEC_ID_ALAC)
+ else if(track->enc->codec_id == CODEC_ID_AC3)
+ mov_write_ac3_tag(pb, track);
+ else if(track->enc->codec_id == CODEC_ID_ALAC)
mov_write_extradata_tag(pb, track);
else if(track->vosLen > 0)
mov_write_glbl_tag(pb, track);
static int mov_write_avcc_tag(ByteIOContext *pb, MOVTrack *track)
{
- offset_t pos = url_ftell(pb);
+ int64_t pos = url_ftell(pb);
put_be32(pb, 0);
put_tag(pb, "avcC");
{ CODEC_ID_AAC, MKTAG('m','p','4','a') },
{ CODEC_ID_AMR_NB, MKTAG('s','a','m','r') },
{ CODEC_ID_AMR_WB, MKTAG('s','a','w','b') },
+ { CODEC_ID_MOV_TEXT, MKTAG('t','x','3','g') },
+ { CODEC_ID_NONE, 0 },
};
static const AVCodecTag mov_pix_fmt_tags[] = {
{ CODEC_ID_MPEG4, MKTAG('m','p','4','v') },
{ CODEC_ID_AAC, MKTAG('m','p','4','a') },
{ CODEC_ID_ALAC, MKTAG('a','l','a','c') },
+ { CODEC_ID_AC3, MKTAG('a','c','-','3') },
+ { CODEC_ID_MOV_TEXT, MKTAG('t','x','3','g') },
+ { CODEC_ID_NONE, 0 },
};
static int mov_find_codec_tag(AVFormatContext *s, MOVTrack *track)
if (track->mode == MODE_MP4 || track->mode == MODE_PSP) {
if (!codec_get_tag(ff_mp4_obj_type, track->enc->codec_id))
return 0;
- if (track->enc->codec_id == CODEC_ID_H264) tag = MKTAG('a','v','c','1');
+ if (track->enc->codec_id == CODEC_ID_H264) tag = MKTAG('a','v','c','1');
+ else if (track->enc->codec_id == CODEC_ID_AC3) tag = MKTAG('a','c','-','3');
+ else if (track->enc->codec_id == CODEC_ID_DIRAC) tag = MKTAG('d','r','a','c');
+ else if (track->enc->codec_id == CODEC_ID_MOV_TEXT) tag = MKTAG('t','x','3','g');
else if (track->enc->codec_type == CODEC_TYPE_VIDEO) tag = MKTAG('m','p','4','v');
else if (track->enc->codec_type == CODEC_TYPE_AUDIO) tag = MKTAG('m','p','4','a');
} else if (track->mode == MODE_IPOD) {
"the file may be unplayable!\n");
}
}
+ } else if (track->enc->codec_type == CODEC_TYPE_SUBTITLE) {
+ tag = codec_get_tag(ff_codec_movsubtitle_tags, track->enc->codec_id);
}
}
}
return 28;
}
+static int mov_write_subtitle_tag(ByteIOContext *pb, MOVTrack *track)
+{
+ int64_t pos = url_ftell(pb);
+ put_be32(pb, 0); /* size */
+ put_le32(pb, track->tag); // store it byteswapped
+ put_be32(pb, 0); /* Reserved */
+ put_be16(pb, 0); /* Reserved */
+ put_be16(pb, 1); /* Data-reference index */
+
+ if (track->enc->extradata_size)
+ put_buffer(pb, track->enc->extradata, track->enc->extradata_size);
+
+ return updateSize(pb, pos);
+}
+
static int mov_write_video_tag(ByteIOContext *pb, MOVTrack *track)
{
- offset_t pos = url_ftell(pb);
+ int64_t pos = url_ftell(pb);
char compressor_name[32];
put_be32(pb, 0); /* size */
put_be32(pb, 0); /* Reserved */
}
put_be16(pb, track->enc->width); /* Video width */
- put_be16(pb, track->enc->height); /* Video height */
+ put_be16(pb, track->height); /* Video height */
put_be32(pb, 0x00480000); /* Horizontal resolution 72dpi */
put_be32(pb, 0x00480000); /* Vertical resolution 72dpi */
put_be32(pb, 0); /* Data size (= 0) */
put_byte(pb, strlen(compressor_name));
put_buffer(pb, compressor_name, 31);
- if (track->mode == MODE_MOV && track->enc->bits_per_sample)
- put_be16(pb, track->enc->bits_per_sample);
+ if (track->mode == MODE_MOV && track->enc->bits_per_coded_sample)
+ put_be16(pb, track->enc->bits_per_coded_sample);
else
put_be16(pb, 0x18); /* Reserved */
put_be16(pb, 0xffff); /* Reserved */
static int mov_write_stsd_tag(ByteIOContext *pb, MOVTrack *track)
{
- offset_t pos = url_ftell(pb);
+ int64_t pos = url_ftell(pb);
put_be32(pb, 0); /* size */
put_tag(pb, "stsd");
put_be32(pb, 0); /* version & flags */
mov_write_video_tag(pb, track);
else if (track->enc->codec_type == CODEC_TYPE_AUDIO)
mov_write_audio_tag(pb, track);
+ else if (track->enc->codec_type == CODEC_TYPE_SUBTITLE)
+ mov_write_subtitle_tag(pb, track);
return updateSize(pb, pos);
}
static int mov_write_ctts_tag(ByteIOContext *pb, MOVTrack *track)
{
- MOV_stts_t *ctts_entries;
+ MOVStts *ctts_entries;
uint32_t entries = 0;
uint32_t atom_size;
int i;
/* Time to sample atom */
static int mov_write_stts_tag(ByteIOContext *pb, MOVTrack *track)
{
- MOV_stts_t *stts_entries;
+ MOVStts *stts_entries;
uint32_t entries = -1;
uint32_t atom_size;
int i;
static int mov_write_stbl_tag(ByteIOContext *pb, MOVTrack *track)
{
- offset_t pos = url_ftell(pb);
+ int64_t pos = url_ftell(pb);
put_be32(pb, 0); /* size */
put_tag(pb, "stbl");
mov_write_stsd_tag(pb, track);
static int mov_write_dinf_tag(ByteIOContext *pb)
{
- offset_t pos = url_ftell(pb);
+ int64_t pos = url_ftell(pb);
put_be32(pb, 0); /* size */
put_tag(pb, "dinf");
mov_write_dref_tag(pb);
return updateSize(pb, pos);
}
+static int mov_write_nmhd_tag(ByteIOContext *pb)
+{
+ put_be32(pb, 12);
+ put_tag(pb, "nmhd");
+ put_be32(pb, 0);
+ return 12;
+}
+
+static int mov_write_gmhd_tag(ByteIOContext *pb)
+{
+ put_be32(pb, 0x20); /* size */
+ put_tag(pb, "gmhd");
+ put_be32(pb, 0x18); /* gmin size */
+ put_tag(pb, "gmin"); /* generic media info */
+ put_be32(pb, 0); /* version & flags */
+ put_be16(pb, 0x40); /* graphics mode = */
+ put_be16(pb, 0x8000); /* opColor (r?) */
+ put_be16(pb, 0x8000); /* opColor (g?) */
+ put_be16(pb, 0x8000); /* opColor (b?) */
+ put_be16(pb, 0); /* balance */
+ put_be16(pb, 0); /* reserved */
+ return 0x20;
+}
+
static int mov_write_smhd_tag(ByteIOContext *pb)
{
put_be32(pb, 16); /* size */
static int mov_write_hdlr_tag(ByteIOContext *pb, MOVTrack *track)
{
- const char *descr, *hdlr, *hdlr_type;
- offset_t pos = url_ftell(pb);
+ const char *hdlr, *descr = NULL, *hdlr_type = NULL;
+ int64_t pos = url_ftell(pb);
if (!track) { /* no media --> data handler */
hdlr = "dhlr";
if (track->enc->codec_type == CODEC_TYPE_VIDEO) {
hdlr_type = "vide";
descr = "VideoHandler";
- } else {
+ } else if (track->enc->codec_type == CODEC_TYPE_AUDIO) {
hdlr_type = "soun";
descr = "SoundHandler";
+ } else if (track->enc->codec_type == CODEC_TYPE_SUBTITLE) {
+ if (track->mode == MODE_IPOD) hdlr_type = "sbtl";
+ else hdlr_type = "text";
+ descr = "SubtitleHandler";
}
}
static int mov_write_minf_tag(ByteIOContext *pb, MOVTrack *track)
{
- offset_t pos = url_ftell(pb);
+ int64_t pos = url_ftell(pb);
put_be32(pb, 0); /* size */
put_tag(pb, "minf");
if(track->enc->codec_type == CODEC_TYPE_VIDEO)
mov_write_vmhd_tag(pb);
- else
+ else if (track->enc->codec_type == CODEC_TYPE_AUDIO)
mov_write_smhd_tag(pb);
+ else if (track->enc->codec_type == CODEC_TYPE_SUBTITLE) {
+ if (track->mode == MODE_MOV) mov_write_gmhd_tag(pb);
+ else mov_write_nmhd_tag(pb);
+ }
if (track->mode == MODE_MOV) /* FIXME: Why do it for MODE_MOV only ? */
mov_write_hdlr_tag(pb, NULL);
mov_write_dinf_tag(pb);
static int mov_write_mdia_tag(ByteIOContext *pb, MOVTrack *track)
{
- offset_t pos = url_ftell(pb);
+ int64_t pos = url_ftell(pb);
put_be32(pb, 0); /* size */
put_tag(pb, "mdia");
mov_write_mdhd_tag(pb, track);
put_be32(pb, 0x40000000); /* reserved */
/* Track width and height, for visual only */
- if(track->enc->codec_type == CODEC_TYPE_VIDEO) {
+ if(track->enc->codec_type == CODEC_TYPE_VIDEO ||
+ track->enc->codec_type == CODEC_TYPE_SUBTITLE) {
double sample_aspect_ratio = av_q2d(st->sample_aspect_ratio);
- if(!sample_aspect_ratio) sample_aspect_ratio = 1;
+ if(!sample_aspect_ratio || track->height != track->enc->height)
+ sample_aspect_ratio = 1;
put_be32(pb, sample_aspect_ratio * track->enc->width*0x10000);
- put_be32(pb, track->enc->height*0x10000);
+ put_be32(pb, track->height*0x10000);
}
else {
put_be32(pb, 0);
static int mov_write_trak_tag(ByteIOContext *pb, MOVTrack *track, AVStream *st)
{
- offset_t pos = url_ftell(pb);
+ int64_t pos = url_ftell(pb);
put_be32(pb, 0); /* size */
put_tag(pb, "trak");
mov_write_tkhd_tag(pb, track, st);
static int mov_write_itunes_hdlr_tag(ByteIOContext *pb, MOVContext *mov,
AVFormatContext *s)
{
- offset_t pos = url_ftell(pb);
+ int64_t pos = url_ftell(pb);
put_be32(pb, 0); /* size */
put_tag(pb, "hdlr");
put_be32(pb, 0);
static int mov_write_string_data_tag(ByteIOContext *pb, const char *data, int long_style)
{
if(long_style){
- offset_t pos = url_ftell(pb);
+ int64_t pos = url_ftell(pb);
put_be32(pb, 0); /* size */
put_tag(pb, "data");
put_be32(pb, 1);
static int mov_write_string_tag(ByteIOContext *pb, const char *name, const char *value, int long_style){
int size = 0;
if (value && value[0]) {
- offset_t pos = url_ftell(pb);
+ int64_t pos = url_ftell(pb);
put_be32(pb, 0); /* size */
put_tag(pb, name);
mov_write_string_data_tag(pb, value, long_style);
{
int size = 0;
if (s->track) {
- offset_t pos = url_ftell(pb);
+ int64_t pos = url_ftell(pb);
put_be32(pb, 0); /* size */
put_tag(pb, "trkn");
{
- offset_t pos = url_ftell(pb);
+ int64_t pos = url_ftell(pb);
put_be32(pb, 0); /* size */
put_tag(pb, "data");
put_be32(pb, 0); // 8 bytes empty
static int mov_write_ilst_tag(ByteIOContext *pb, MOVContext *mov,
AVFormatContext *s)
{
- offset_t pos = url_ftell(pb);
+ int64_t pos = url_ftell(pb);
put_be32(pb, 0); /* size */
put_tag(pb, "ilst");
mov_write_string_tag(pb, "\251nam", s->title , 1);
mov_write_string_tag(pb, "\251too", LIBAVFORMAT_IDENT, 1);
mov_write_string_tag(pb, "\251cmt", s->comment , 1);
mov_write_string_tag(pb, "\251gen", s->genre , 1);
+ mov_write_string_tag(pb, "\251cpy", s->copyright , 1);
mov_write_trkn_tag(pb, mov, s);
return updateSize(pb, pos);
}
// only save meta tag if required
if (s->title[0] || s->author[0] || s->album[0] || s->year ||
s->comment[0] || s->genre[0] || s->track) {
- offset_t pos = url_ftell(pb);
+ int64_t pos = url_ftell(pb);
put_be32(pb, 0); /* size */
put_tag(pb, "meta");
put_be32(pb, 0);
static int mov_write_3gp_udta_tag(ByteIOContext *pb, AVFormatContext *s,
const char *tag, const char *str)
{
- offset_t pos = url_ftell(pb);
+ int64_t pos = url_ftell(pb);
if (!utf8len(str))
return 0;
put_be32(pb, 0); /* size */
if (!bitexact && (s->title[0] || s->author[0] || s->album[0] || s->year ||
s->comment[0] || s->genre[0] || s->track)) {
- offset_t pos = url_ftell(pb);
+ int64_t pos = url_ftell(pb);
put_be32(pb, 0); /* size */
put_tag(pb, "udta");
mov_write_3gp_udta_tag(pb, s, "gnre", s->genre);
mov_write_3gp_udta_tag(pb, s, "dscp", s->comment);
mov_write_3gp_udta_tag(pb, s, "albm", s->album);
+ mov_write_3gp_udta_tag(pb, s, "cprt", s->copyright);
mov_write_3gp_udta_tag(pb, s, "yrrc", "nil");
} else if (mov->mode == MODE_MOV) { // the title field breaks gtkpod with mp4 and my suspicion is that stuff is not valid in mp4
mov_write_string_tag(pb, "\251nam", s->title , 0);
mov_write_string_tag(pb, "\251enc", LIBAVFORMAT_IDENT, 0);
mov_write_string_tag(pb, "\251des", s->comment , 0);
mov_write_string_tag(pb, "\251gen", s->genre , 0);
+ mov_write_string_tag(pb, "\251cpy", s->copyright , 0);
} else {
/* iTunes meta data */
mov_write_meta_tag(pb, mov, s);
static int mov_write_uuidusmt_tag(ByteIOContext *pb, AVFormatContext *s)
{
- offset_t pos, pos2;
+ int64_t pos, pos2;
if (s->title[0]) {
pos = url_ftell(pb);
AVFormatContext *s)
{
int i;
- offset_t pos = url_ftell(pb);
+ int64_t pos = url_ftell(pb);
put_be32(pb, 0); /* size placeholder*/
put_tag(pb, "moov");
mov->timescale = globalTimescale;
static int mov_write_ftyp_tag(ByteIOContext *pb, AVFormatContext *s)
{
MOVContext *mov = s->priv_data;
- offset_t pos = url_ftell(pb);
+ int64_t pos = url_ftell(pb);
int has_h264 = 0, has_video = 0;
int minor = 0x200;
int i;
return -1;
}
if(st->codec->codec_type == CODEC_TYPE_VIDEO){
+ if (track->tag == MKTAG('m','x','3','p') || track->tag == MKTAG('m','x','3','n') ||
+ track->tag == MKTAG('m','x','4','p') || track->tag == MKTAG('m','x','4','n') ||
+ track->tag == MKTAG('m','x','5','p') || track->tag == MKTAG('m','x','5','n')) {
+ if (st->codec->width != 720 || (st->codec->height != 608 && st->codec->height != 512)) {
+ av_log(s, AV_LOG_ERROR, "D-10/IMX must use 720x608 or 720x512 video resolution\n");
+ return -1;
+ }
+ track->height = track->tag>>24 == 'n' ? 486 : 576;
+ } else
+ track->height = st->codec->height;
track->timescale = st->codec->time_base.den;
av_set_pts_info(st, 64, 1, st->codec->time_base.den);
if (track->mode == MODE_MOV && track->timescale > 100000)
}else if(st->codec->codec_type == CODEC_TYPE_AUDIO){
track->timescale = st->codec->sample_rate;
av_set_pts_info(st, 64, 1, st->codec->sample_rate);
- if(!st->codec->frame_size){
+ if(!st->codec->frame_size && !av_get_bits_per_sample(st->codec->codec_id)) {
av_log(s, AV_LOG_ERROR, "track %d: codec frame size is not set\n", i);
return -1;
}else if(st->codec->frame_size > 1){ /* assume compressed audio */
track->audio_vbr = 1;
}else{
+ st->codec->frame_size = 1;
track->sampleSize = (av_get_bits_per_sample(st->codec->codec_id) >> 3) * st->codec->channels;
}
+ if(track->mode != MODE_MOV &&
+ track->enc->codec_id == CODEC_ID_MP3 && track->enc->sample_rate < 16000){
+ av_log(s, AV_LOG_ERROR, "track %d: muxing mp3 at %dhz is not supported\n",
+ i, track->enc->sample_rate);
+ return -1;
+ }
+ }else if(st->codec->codec_type == CODEC_TYPE_SUBTITLE){
+ track->timescale = st->codec->time_base.den;
+ av_set_pts_info(st, 64, 1, st->codec->time_base.den);
}
}
if (enc->codec_id == CODEC_ID_H264 && trk->vosLen > 0 && *(uint8_t *)trk->vosData != 1) {
/* from x264 or from bytestream h264 */
/* nal reformating needed */
- int ret = ff_avc_parse_nal_units(pkt->data, &pkt->data, &pkt->size);
- if (ret < 0)
- return ret;
- assert(pkt->size);
- size = pkt->size;
- } else if (enc->codec_id == CODEC_ID_DNXHD && !trk->vosLen) {
+ size = ff_avc_parse_nal_units(pb, pkt->data, pkt->size);
+ } else {
+ put_buffer(pb, pkt->data, size);
+ }
+
+ if ((enc->codec_id == CODEC_ID_DNXHD ||
+ enc->codec_id == CODEC_ID_AC3) && !trk->vosLen) {
/* copy frame to create needed atoms */
trk->vosLen = size;
trk->vosData = av_malloc(size);
+ if (!trk->vosData)
+ return AVERROR(ENOMEM);
memcpy(trk->vosData, pkt->data, size);
}
return -1;
}
- trk->cluster[trk->entry].pos = url_ftell(pb);
+ trk->cluster[trk->entry].pos = url_ftell(pb) - size;
trk->cluster[trk->entry].samplesInChunk = samplesInChunk;
trk->cluster[trk->entry].size = size;
trk->cluster[trk->entry].entries = samplesInChunk;
trk->sampleCount += samplesInChunk;
mov->mdat_size += size;
- put_buffer(pb, pkt->data, size);
-
put_flush_packet(pb);
return 0;
}
int res = 0;
int i;
- offset_t moov_pos = url_ftell(pb);
+ int64_t moov_pos = url_ftell(pb);
/* Write size of mdat tag */
if (mov->mdat_size+8 <= UINT32_MAX) {
return res;
}
-#ifdef CONFIG_MOV_MUXER
+#if CONFIG_MOV_MUXER
AVOutputFormat mov_muxer = {
"mov",
NULL_IF_CONFIG_SMALL("MOV format"),
.codec_tag = (const AVCodecTag* const []){codec_movvideo_tags, codec_movaudio_tags, 0},
};
#endif
-#ifdef CONFIG_TGP_MUXER
+#if CONFIG_TGP_MUXER
AVOutputFormat tgp_muxer = {
"3gp",
NULL_IF_CONFIG_SMALL("3GP format"),
.codec_tag = (const AVCodecTag* const []){codec_3gp_tags, 0},
};
#endif
-#ifdef CONFIG_MP4_MUXER
+#if CONFIG_MP4_MUXER
AVOutputFormat mp4_muxer = {
"mp4",
NULL_IF_CONFIG_SMALL("MP4 format"),
.codec_tag = (const AVCodecTag* const []){ff_mp4_obj_type, 0},
};
#endif
-#ifdef CONFIG_PSP_MUXER
+#if CONFIG_PSP_MUXER
AVOutputFormat psp_muxer = {
"psp",
NULL_IF_CONFIG_SMALL("PSP MP4 format"),
.codec_tag = (const AVCodecTag* const []){ff_mp4_obj_type, 0},
};
#endif
-#ifdef CONFIG_TG2_MUXER
+#if CONFIG_TG2_MUXER
AVOutputFormat tg2_muxer = {
"3g2",
NULL_IF_CONFIG_SMALL("3GP2 format"),
.codec_tag = (const AVCodecTag* const []){codec_3gp_tags, 0},
};
#endif
-#ifdef CONFIG_IPOD_MUXER
+#if CONFIG_IPOD_MUXER
AVOutputFormat ipod_muxer = {
"ipod",
NULL_IF_CONFIG_SMALL("iPod H.264 MP4 format"),