* Copyright (c) 2004 Gildas Bazin <gbazin at videolan dot org>
* Copyright (c) 2009 Baptiste Coudurier <baptiste dot coudurier at gmail dot com>
*
- * This file is part of FFmpeg.
+ * This file is part of Libav.
*
- * FFmpeg is free software; you can redistribute it and/or
+ * Libav is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
- * FFmpeg is distributed in the hope that it will be useful,
+ * Libav is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
+ * License along with Libav; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavcodec/put_bits.h"
#include "internal.h"
#include "libavutil/avstring.h"
+#include "libavutil/intfloat.h"
+#include "libavutil/mathematics.h"
+#include "libavutil/opt.h"
+#include "libavutil/dict.h"
+#include "rtpenc.h"
+#include "mov_chan.h"
#undef NDEBUG
#include <assert.h>
+static const AVOption options[] = {
+ { "movflags", "MOV muxer flags", offsetof(MOVMuxContext, flags), AV_OPT_TYPE_FLAGS, {.dbl = 0}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
+ { "rtphint", "Add RTP hint tracks", 0, AV_OPT_TYPE_CONST, {.dbl = FF_MOV_FLAG_RTP_HINT}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
+ FF_RTP_FLAG_OPTS(MOVMuxContext, rtp_flags),
+ { NULL },
+};
+
+#define MOV_CLASS(flavor)\
+static const AVClass flavor ## _muxer_class = {\
+ .class_name = #flavor " muxer",\
+ .item_name = av_default_item_name,\
+ .option = options,\
+ .version = LIBAVUTIL_VERSION_INT,\
+};
+
//FIXME support 64 bit variant with wide placeholders
static int64_t updateSize(AVIOContext *pb, int64_t pos)
{
- int64_t curpos = url_ftell(pb);
- url_fseek(pb, pos, SEEK_SET);
+ int64_t curpos = avio_tell(pb);
+ avio_seek(pb, pos, SEEK_SET);
avio_wb32(pb, curpos - pos); /* rewrite size */
- url_fseek(pb, curpos, SEEK_SET);
+ avio_seek(pb, curpos, SEEK_SET);
return curpos - pos;
}
{
int i;
int mode64 = 0; // use 32 bit size variant if possible
- int64_t pos = url_ftell(pb);
+ int64_t pos = avio_tell(pb);
avio_wb32(pb, 0); /* size */
if (pos > UINT32_MAX) {
mode64 = 1;
int equalChunks = 1;
int i, j, entries = 0, tst = -1, oldtst = -1;
- int64_t pos = url_ftell(pb);
+ int64_t pos = avio_tell(pb);
avio_wb32(pb, 0); /* size */
ffio_wfourcc(pb, "stsz");
avio_wb32(pb, 0); /* version & flags */
}
if (equalChunks) {
int sSize = track->cluster[0].size/track->cluster[0].entries;
+ sSize = FFMAX(1, sSize); // adpcm mono case could make sSize == 0
avio_wb32(pb, sSize); // sample size
avio_wb32(pb, entries); // sample count
}
int index = 0, oldval = -1, i;
int64_t entryPos, curpos;
- int64_t pos = url_ftell(pb);
+ int64_t pos = avio_tell(pb);
avio_wb32(pb, 0); /* size */
ffio_wfourcc(pb, "stsc");
avio_wb32(pb, 0); // version & flags
- entryPos = url_ftell(pb);
+ entryPos = avio_tell(pb);
avio_wb32(pb, track->entry); // entry count
for (i=0; i<track->entry; i++) {
if(oldval != track->cluster[i].samplesInChunk)
index++;
}
}
- curpos = url_ftell(pb);
- url_fseek(pb, entryPos, SEEK_SET);
+ curpos = avio_tell(pb);
+ avio_seek(pb, entryPos, SEEK_SET);
avio_wb32(pb, index); // rewrite size
- url_fseek(pb, curpos, SEEK_SET);
+ avio_seek(pb, curpos, SEEK_SET);
return updateSize(pb, pos);
}
{
int64_t curpos, entryPos;
int i, index = 0;
- int64_t pos = url_ftell(pb);
+ int64_t pos = avio_tell(pb);
avio_wb32(pb, 0); // size
ffio_wfourcc(pb, flag == MOV_SYNC_SAMPLE ? "stss" : "stps");
avio_wb32(pb, 0); // version & flags
- entryPos = url_ftell(pb);
+ entryPos = avio_tell(pb);
avio_wb32(pb, track->entry); // entry count
for (i=0; i<track->entry; i++) {
if (track->cluster[i].flags & flag) {
index++;
}
}
- curpos = url_ftell(pb);
- url_fseek(pb, entryPos, SEEK_SET);
+ curpos = avio_tell(pb);
+ avio_seek(pb, entryPos, SEEK_SET);
avio_wb32(pb, index); // rewrite size
- url_fseek(pb, curpos, SEEK_SET);
+ avio_seek(pb, curpos, SEEK_SET);
return updateSize(pb, pos);
}
avio_wb32(pb, 11);
ffio_wfourcc(pb, "dac3");
- init_get_bits(&gbc, track->vosData+4, track->vosLen-4);
+ init_get_bits(&gbc, track->vosData+4, (track->vosLen-4) * 8);
fscod = get_bits(&gbc, 2);
frmsizecod = get_bits(&gbc, 6);
bsid = get_bits(&gbc, 5);
/**
* This function writes extradata "as is".
- * Extradata must be formated like a valid atom (with size and tag)
+ * Extradata must be formatted like a valid atom (with size and tag).
*/
static int mov_write_extradata_tag(AVIOContext *pb, MOVTrack *track)
{
return 10;
}
-static unsigned int descrLength(unsigned int len)
-{
- int i;
- for(i=1; len>>(7*i); i++);
- return len + 1 + i;
-}
-
static void putDescr(AVIOContext *pb, int tag, unsigned int size)
{
- int i= descrLength(size) - size - 2;
+ int i = 3;
avio_w8(pb, tag);
for(; i>0; i--)
avio_w8(pb, (size>>(7*i)) | 0x80);
static int mov_write_esds_tag(AVIOContext *pb, MOVTrack *track) // Basic
{
- int64_t pos = url_ftell(pb);
- int decoderSpecificInfoLen = track->vosLen ? descrLength(track->vosLen):0;
+ int64_t pos = avio_tell(pb);
+ int decoderSpecificInfoLen = track->vosLen ? 5+track->vosLen : 0;
avio_wb32(pb, 0); // size
ffio_wfourcc(pb, "esds");
avio_wb32(pb, 0); // Version
// ES descriptor
- putDescr(pb, 0x03, 3 + descrLength(13 + decoderSpecificInfoLen) +
- descrLength(1));
+ putDescr(pb, 0x03, 3 + 5+13 + decoderSpecificInfoLen + 5+1);
avio_wb16(pb, track->trackID);
avio_w8(pb, 0x00); // flags (= no flags)
static int mov_write_ms_tag(AVIOContext *pb, MOVTrack *track)
{
- int64_t pos = url_ftell(pb);
+ int64_t pos = avio_tell(pb);
avio_wb32(pb, 0);
avio_wl32(pb, track->tag); // store it byteswapped
track->enc->codec_tag = av_bswap16(track->tag >> 16);
return updateSize(pb, pos);
}
+static int mov_write_chan_tag(AVIOContext *pb, MOVTrack *track)
+{
+ uint32_t layout_tag, bitmap;
+ int64_t pos = avio_tell(pb);
+
+ layout_tag = ff_mov_get_channel_layout_tag(track->enc->codec_id,
+ track->enc->channel_layout,
+ &bitmap);
+ if (!layout_tag) {
+ av_log(track->enc, AV_LOG_WARNING, "not writing 'chan' tag due to "
+ "lack of channel information\n");
+ return 0;
+ }
+
+ avio_wb32(pb, 0); // Size
+ ffio_wfourcc(pb, "chan"); // Type
+ avio_w8(pb, 0); // Version
+ avio_wb24(pb, 0); // Flags
+ avio_wb32(pb, layout_tag); // mChannelLayoutTag
+ avio_wb32(pb, bitmap); // mChannelBitmap
+ avio_wb32(pb, 0); // mNumberChannelDescriptions
+
+ return updateSize(pb, pos);
+}
+
static int mov_write_wave_tag(AVIOContext *pb, MOVTrack *track)
{
- int64_t pos = url_ftell(pb);
+ int64_t pos = avio_tell(pb);
avio_wb32(pb, 0); /* size */
ffio_wfourcc(pb, "wave");
} 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_chan_tag(pb, track);
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(AVIOContext *pb, MOVTrack *track)
{
- int64_t pos = url_ftell(pb);
+ int64_t pos = avio_tell(pb);
int version = 0;
uint32_t tag = track->tag;
if (track->mode == MODE_MOV) {
- if (track->timescale > UINT16_MAX) {
- if (mov_get_lpcm_flags(track->enc->codec_id))
- tag = AV_RL32("lpcm");
- version = 2;
- } else if (track->audio_vbr || mov_pcm_le_gt16(track->enc->codec_id) ||
- track->enc->codec_id == CODEC_ID_ADPCM_MS ||
- track->enc->codec_id == CODEC_ID_ADPCM_IMA_WAV) {
- version = 1;
- }
+ if (mov_get_lpcm_flags(track->enc->codec_id))
+ tag = AV_RL32("lpcm");
+ version = 2;
}
avio_wb32(pb, 0); /* size */
avio_wb16(pb, 0);
avio_wb32(pb, 0x00010000);
avio_wb32(pb, 72);
- avio_wb64(pb, av_dbl2int(track->timescale));
+ avio_wb64(pb, av_double2int(track->timescale));
avio_wb32(pb, track->enc->channels);
avio_wb32(pb, 0x7F000000);
avio_wb32(pb, av_get_bits_per_sample(track->enc->codec_id));
avio_wb32(pb, mov_get_lpcm_flags(track->enc->codec_id));
avio_wb32(pb, track->sampleSize);
- avio_wb32(pb, track->enc->frame_size);
+ avio_wb32(pb, track->audio_vbr ? track->enc->frame_size : 1);
} else {
- if (track->mode == MODE_MOV) {
- avio_wb16(pb, track->enc->channels);
- if (track->enc->codec_id == CODEC_ID_PCM_U8 ||
- track->enc->codec_id == CODEC_ID_PCM_S8)
- avio_wb16(pb, 8); /* bits per sample */
- else
- avio_wb16(pb, 16);
- avio_wb16(pb, track->audio_vbr ? -2 : 0); /* compression ID */
- } else { /* reserved for mp4/3gp */
- avio_wb16(pb, 2);
- avio_wb16(pb, 16);
- avio_wb16(pb, 0);
- }
+ /* reserved for mp4/3gp */
+ avio_wb16(pb, 2);
+ avio_wb16(pb, 16);
+ avio_wb16(pb, 0);
avio_wb16(pb, 0); /* packet size (= 0) */
avio_wb16(pb, track->timescale); /* Time scale */
avio_wb16(pb, 0); /* Reserved */
}
- if(version == 1) { /* SoundDescription V1 extended info */
- avio_wb32(pb, track->enc->frame_size); /* Samples per packet */
- avio_wb32(pb, track->sampleSize / track->enc->channels); /* Bytes per packet */
- avio_wb32(pb, track->sampleSize); /* Bytes per frame */
- avio_wb32(pb, 2); /* Bytes per sample */
- }
-
if(track->mode == MODE_MOV &&
(track->enc->codec_id == CODEC_ID_AAC ||
track->enc->codec_id == CODEC_ID_AC3 ||
static int mov_write_avcc_tag(AVIOContext *pb, MOVTrack *track)
{
- int64_t pos = url_ftell(pb);
+ int64_t pos = avio_tell(pb);
avio_wb32(pb, 0);
ffio_wfourcc(pb, "avcC");
ffio_wfourcc(pb, "ACLR");
ffio_wfourcc(pb, "ACLR");
ffio_wfourcc(pb, "0001");
- avio_wb32(pb, 1); /* yuv 1 / rgb 2 ? */
+ avio_wb32(pb, 2); /* yuv range: full 1 / normal 2 */
avio_wb32(pb, 0); /* unknown */
avio_wb32(pb, 24); /* size */
{
int tag;
- if (track->enc->height == 480) /* NTSC */
- if (track->enc->pix_fmt == PIX_FMT_YUV422P) tag = MKTAG('d','v','5','n');
- else tag = MKTAG('d','v','c',' ');
- else if (track->enc->pix_fmt == PIX_FMT_YUV422P) tag = MKTAG('d','v','5','p');
- else if (track->enc->pix_fmt == PIX_FMT_YUV420P) tag = MKTAG('d','v','c','p');
- else tag = MKTAG('d','v','p','p');
+ if (track->enc->width == 720) /* SD */
+ if (track->enc->height == 480) /* NTSC */
+ if (track->enc->pix_fmt == PIX_FMT_YUV422P) tag = MKTAG('d','v','5','n');
+ else tag = MKTAG('d','v','c',' ');
+ else if (track->enc->pix_fmt == PIX_FMT_YUV422P) tag = MKTAG('d','v','5','p');
+ else if (track->enc->pix_fmt == PIX_FMT_YUV420P) tag = MKTAG('d','v','c','p');
+ else tag = MKTAG('d','v','p','p');
+ else if (track->enc->height == 720) /* HD 720 line */
+ if (track->enc->time_base.den == 50) tag = MKTAG('d','v','h','q');
+ else tag = MKTAG('d','v','h','p');
+ else if (track->enc->height == 1080) /* HD 1080 line */
+ if (track->enc->time_base.den == 25) tag = MKTAG('d','v','h','5');
+ else tag = MKTAG('d','v','h','6');
+ else {
+ av_log(s, AV_LOG_ERROR, "unsupported height for dv codec\n");
+ return 0;
+ }
return tag;
}
if (!tag) { // if no mac fcc found, try with Microsoft tags
tag = ff_codec_get_tag(ff_codec_bmp_tags, track->enc->codec_id);
if (tag)
- av_log(s, AV_LOG_INFO, "Warning, using MS style video codec tag, "
+ av_log(s, AV_LOG_WARNING, "Using MS style video codec tag, "
"the file may be unplayable!\n");
}
} else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) {
int ms_tag = ff_codec_get_tag(ff_codec_wav_tags, track->enc->codec_id);
if (ms_tag) {
tag = MKTAG('m', 's', ((ms_tag >> 8) & 0xff), (ms_tag & 0xff));
- av_log(s, AV_LOG_INFO, "Warning, using MS style audio codec tag, "
+ av_log(s, AV_LOG_WARNING, "Using MS style audio codec tag, "
"the file may be unplayable!\n");
}
}
static int mov_write_subtitle_tag(AVIOContext *pb, MOVTrack *track)
{
- int64_t pos = url_ftell(pb);
+ int64_t pos = avio_tell(pb);
avio_wb32(pb, 0); /* size */
avio_wl32(pb, track->tag); // store it byteswapped
avio_wb32(pb, 0); /* Reserved */
static int mov_write_video_tag(AVIOContext *pb, MOVTrack *track)
{
- int64_t pos = url_ftell(pb);
+ int64_t pos = avio_tell(pb);
char compressor_name[32];
avio_wb32(pb, 0); /* size */
memset(compressor_name,0,32);
/* FIXME not sure, ISO 14496-1 draft where it shall be set to 0 */
if (track->mode == MODE_MOV && track->enc->codec && track->enc->codec->name)
- strncpy(compressor_name,track->enc->codec->name,31);
+ av_strlcpy(compressor_name,track->enc->codec->name,32);
avio_w8(pb, strlen(compressor_name));
avio_write(pb, compressor_name, 31);
static int mov_write_rtp_tag(AVIOContext *pb, MOVTrack *track)
{
- int64_t pos = url_ftell(pb);
+ int64_t pos = avio_tell(pb);
avio_wb32(pb, 0); /* size */
ffio_wfourcc(pb, "rtp ");
avio_wb32(pb, 0); /* Reserved */
static int mov_write_stsd_tag(AVIOContext *pb, MOVTrack *track)
{
- int64_t pos = url_ftell(pb);
+ int64_t pos = avio_tell(pb);
avio_wb32(pb, 0); /* size */
ffio_wfourcc(pb, "stsd");
avio_wb32(pb, 0); /* version & flags */
static int mov_write_stbl_tag(AVIOContext *pb, MOVTrack *track)
{
- int64_t pos = url_ftell(pb);
+ int64_t pos = avio_tell(pb);
avio_wb32(pb, 0); /* size */
ffio_wfourcc(pb, "stbl");
mov_write_stsd_tag(pb, track);
static int mov_write_dinf_tag(AVIOContext *pb)
{
- int64_t pos = url_ftell(pb);
+ int64_t pos = avio_tell(pb);
avio_wb32(pb, 0); /* size */
ffio_wfourcc(pb, "dinf");
mov_write_dref_tag(pb);
static int mov_write_hdlr_tag(AVIOContext *pb, MOVTrack *track)
{
const char *hdlr, *descr = NULL, *hdlr_type = NULL;
- int64_t pos = url_ftell(pb);
+ int64_t pos = avio_tell(pb);
if (!track) { /* no media --> data handler */
hdlr = "dhlr";
static int mov_write_minf_tag(AVIOContext *pb, MOVTrack *track)
{
- int64_t pos = url_ftell(pb);
+ int64_t pos = avio_tell(pb);
avio_wb32(pb, 0); /* size */
ffio_wfourcc(pb, "minf");
if(track->enc->codec_type == AVMEDIA_TYPE_VIDEO)
static int mov_write_mdia_tag(AVIOContext *pb, MOVTrack *track)
{
- int64_t pos = url_ftell(pb);
+ int64_t pos = avio_tell(pb);
avio_wb32(pb, 0); /* size */
ffio_wfourcc(pb, "mdia");
mov_write_mdhd_tag(pb, track);
avio_wb32(pb, 0); /* reserved */
avio_wb32(pb, 0); /* reserved */
- avio_wb32(pb, 0x0); /* reserved (Layer & Alternate group) */
+ avio_wb16(pb, 0); /* layer */
+ avio_wb16(pb, st ? st->codec->codec_type : 0); /* alternate group) */
/* Volume, only for audio */
if(track->enc->codec_type == AVMEDIA_TYPE_AUDIO)
avio_wb16(pb, 0x0100);
track->enc->codec_type == AVMEDIA_TYPE_SUBTITLE)) {
if(track->mode == MODE_MOV) {
avio_wb32(pb, track->enc->width << 16);
- avio_wb32(pb, track->enc->height << 16);
+ avio_wb32(pb, track->height << 16);
} else {
double sample_aspect_ratio = av_q2d(st->sample_aspect_ratio);
if(!sample_aspect_ratio || track->height != track->enc->height)
int32_t width = av_rescale(track->enc->sample_aspect_ratio.num, track->enc->width,
track->enc->sample_aspect_ratio.den);
- int64_t pos = url_ftell(pb);
+ int64_t pos = avio_tell(pb);
avio_wb32(pb, 0); /* size */
ffio_wfourcc(pb, "tapt");
avio_wb32(pb, track->enc->height << 16);
return updateSize(pb, pos);
-};
+}
// This box seems important for the psp playback ... without it the movie seems to hang
static int mov_write_edts_tag(AVIOContext *pb, MOVTrack *track)
{
- avio_wb32(pb, 0x24); /* size */
+ int64_t duration = av_rescale_rnd(track->trackDuration, MOV_TIMESCALE,
+ track->timescale, AV_ROUND_UP);
+ int version = duration < INT32_MAX ? 0 : 1;
+ int entry_size, entry_count, size;
+ int64_t delay, start_ct = track->cluster[0].cts;
+ delay = av_rescale_rnd(track->cluster[0].dts + start_ct, MOV_TIMESCALE,
+ track->timescale, AV_ROUND_DOWN);
+ version |= delay < INT32_MAX ? 0 : 1;
+
+ entry_size = (version == 1) ? 20 : 12;
+ entry_count = 1 + (delay > 0);
+ size = 24 + entry_count * entry_size;
+
+ /* write the atom data */
+ avio_wb32(pb, size);
ffio_wfourcc(pb, "edts");
- avio_wb32(pb, 0x1c); /* size */
+ avio_wb32(pb, size - 8);
ffio_wfourcc(pb, "elst");
- avio_wb32(pb, 0x0);
- avio_wb32(pb, 0x1);
+ avio_w8(pb, version);
+ avio_wb24(pb, 0); /* flags */
- /* duration ... doesn't seem to effect psp */
- avio_wb32(pb, av_rescale_rnd(track->trackDuration, MOV_TIMESCALE,
- track->timescale, AV_ROUND_UP));
+ avio_wb32(pb, entry_count);
+ if (delay > 0) { /* add an empty edit to delay presentation */
+ if (version == 1) {
+ avio_wb64(pb, delay);
+ avio_wb64(pb, -1);
+ } else {
+ avio_wb32(pb, delay);
+ avio_wb32(pb, -1);
+ }
+ avio_wb32(pb, 0x00010000);
+ }
- avio_wb32(pb, track->cluster[0].cts); /* first pts is cts since dts is 0 */
+ /* duration */
+ if (version == 1) {
+ avio_wb64(pb, duration);
+ avio_wb64(pb, start_ct);
+ } else {
+ avio_wb32(pb, duration);
+ avio_wb32(pb, start_ct);
+ }
avio_wb32(pb, 0x00010000);
- return 0x24;
+ return size;
}
static int mov_write_tref_tag(AVIOContext *pb, MOVTrack *track)
return 0x34;
}
-static int mov_write_udta_sdp(AVIOContext *pb, AVCodecContext *ctx, int index)
+static int mov_write_udta_sdp(AVIOContext *pb, AVFormatContext *ctx, int index)
{
char buf[1000] = "";
int len;
- ff_sdp_write_media(buf, sizeof(buf), ctx, NULL, NULL, 0, 0);
+ ff_sdp_write_media(buf, sizeof(buf), ctx->streams[0]->codec, NULL, NULL, 0, 0, ctx);
av_strlcatf(buf, sizeof(buf), "a=control:streamid=%d\r\n", index);
len = strlen(buf);
static int mov_write_trak_tag(AVIOContext *pb, MOVTrack *track, AVStream *st)
{
- int64_t pos = url_ftell(pb);
+ int64_t pos = avio_tell(pb);
avio_wb32(pb, 0); /* size */
ffio_wfourcc(pb, "trak");
mov_write_tkhd_tag(pb, track, st);
- if (track->mode == MODE_PSP || track->flags & MOV_TRACK_CTTS)
+ if (track->mode == MODE_PSP || track->flags & MOV_TRACK_CTTS || track->cluster[0].dts)
mov_write_edts_tag(pb, track); // PSP Movies require edts box
if (track->tref_tag)
mov_write_tref_tag(pb, track);
if (track->mode == MODE_PSP)
mov_write_uuid_tag_psp(pb,track); // PSP Movies require this uuid box
if (track->tag == MKTAG('r','t','p',' '))
- mov_write_udta_sdp(pb, track->rtp_ctx->streams[0]->codec, track->trackID);
+ mov_write_udta_sdp(pb, track->rtp_ctx, track->trackID);
if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO && track->mode == MODE_MOV) {
double sample_aspect_ratio = av_q2d(st->sample_aspect_ratio);
if (0.0 != sample_aspect_ratio && 1.0 != sample_aspect_ratio)
static int mov_write_string_tag(AVIOContext *pb, const char *name, const char *value, int lang, int long_style){
int size = 0;
if (value && value[0]) {
- int64_t pos = url_ftell(pb);
+ int64_t pos = avio_tell(pb);
avio_wb32(pb, 0); /* size */
ffio_wfourcc(pb, name);
mov_write_string_data_tag(pb, value, lang, long_style);
int long_style)
{
int l, lang = 0, len, len2;
- AVMetadataTag *t, *t2 = NULL;
+ AVDictionaryEntry *t, *t2 = NULL;
char tag2[16];
- if (!(t = av_metadata_get(s->metadata, tag, NULL, 0)))
+ if (!(t = av_dict_get(s->metadata, tag, NULL, 0)))
return 0;
len = strlen(t->key);
snprintf(tag2, sizeof(tag2), "%s-", tag);
- while ((t2 = av_metadata_get(s->metadata, tag2, t2, AV_METADATA_IGNORE_SUFFIX))) {
+ while ((t2 = av_dict_get(s->metadata, tag2, t2, AV_DICT_IGNORE_SUFFIX))) {
len2 = strlen(t2->key);
if (len2 == len+4 && !strcmp(t->value, t2->value)
&& (l=ff_mov_iso639_to_lang(&t2->key[len2-3], 1)) >= 0) {
static int mov_write_trkn_tag(AVIOContext *pb, MOVMuxContext *mov,
AVFormatContext *s)
{
- AVMetadataTag *t = av_metadata_get(s->metadata, "track", NULL, 0);
+ AVDictionaryEntry *t = av_dict_get(s->metadata, "track", NULL, 0);
int size = 0, track = t ? atoi(t->value) : 0;
if (track) {
avio_wb32(pb, 32); /* size */
static int mov_write_ilst_tag(AVIOContext *pb, MOVMuxContext *mov,
AVFormatContext *s)
{
- int64_t pos = url_ftell(pb);
+ int64_t pos = avio_tell(pb);
avio_wb32(pb, 0); /* size */
ffio_wfourcc(pb, "ilst");
mov_write_string_metadata(s, pb, "\251nam", "title" , 1);
AVFormatContext *s)
{
int size = 0;
- int64_t pos = url_ftell(pb);
+ int64_t pos = avio_tell(pb);
avio_wb32(pb, 0); /* size */
ffio_wfourcc(pb, "meta");
avio_wb32(pb, 0);
static int mov_write_3gp_udta_tag(AVIOContext *pb, AVFormatContext *s,
const char *tag, const char *str)
{
- int64_t pos = url_ftell(pb);
- AVMetadataTag *t = av_metadata_get(s->metadata, str, NULL, 0);
+ int64_t pos = avio_tell(pb);
+ AVDictionaryEntry *t = av_dict_get(s->metadata, str, NULL, 0);
if (!t || !utf8len(t->value))
return 0;
avio_wb32(pb, 0); /* size */
avio_wb16(pb, language_code("eng")); /* language */
avio_write(pb, t->value, strlen(t->value)+1); /* UTF8 string value */
if (!strcmp(tag, "albm") &&
- (t = av_metadata_get(s->metadata, "track", NULL, 0)))
+ (t = av_dict_get(s->metadata, "track", NULL, 0)))
avio_w8(pb, atoi(t->value));
}
return updateSize(pb, pos);
static int mov_write_chpl_tag(AVIOContext *pb, AVFormatContext *s)
{
- int64_t pos = url_ftell(pb);
+ int64_t pos = avio_tell(pb);
int i, nb_chapters = FFMIN(s->nb_chapters, 255);
avio_wb32(pb, 0); // size
for (i = 0; i < nb_chapters; i++) {
AVChapter *c = s->chapters[i];
- AVMetadataTag *t;
+ AVDictionaryEntry *t;
avio_wb64(pb, av_rescale_q(c->start, c->time_base, (AVRational){1,10000000}));
- if ((t = av_metadata_get(c->metadata, "title", NULL, 0))) {
+ if ((t = av_dict_get(c->metadata, "title", NULL, 0))) {
int len = FFMIN(strlen(t->value), 255);
avio_w8(pb, len);
avio_write(pb, t->value, len);
return 0;
}
- ret = url_open_dyn_buf(&pb_buf);
+ ret = avio_open_dyn_buf(&pb_buf);
if(ret < 0)
return ret;
if (s->nb_chapters)
mov_write_chpl_tag(pb_buf, s);
- if ((size = url_close_dyn_buf(pb_buf, &buf)) > 0) {
+ if ((size = avio_close_dyn_buf(pb_buf, &buf)) > 0) {
avio_wb32(pb, size+8);
ffio_wfourcc(pb, "udta");
avio_write(pb, buf, size);
static int mov_write_uuidusmt_tag(AVIOContext *pb, AVFormatContext *s)
{
- AVMetadataTag *title = av_metadata_get(s->metadata, "title", NULL, 0);
+ AVDictionaryEntry *title = av_dict_get(s->metadata, "title", NULL, 0);
int64_t pos, pos2;
if (title) {
- pos = url_ftell(pb);
+ pos = avio_tell(pb);
avio_wb32(pb, 0); /* size placeholder*/
ffio_wfourcc(pb, "uuid");
ffio_wfourcc(pb, "USMT");
avio_wb32(pb, 0xbb88695c);
avio_wb32(pb, 0xfac9c740);
- pos2 = url_ftell(pb);
+ pos2 = avio_tell(pb);
avio_wb32(pb, 0); /* size placeholder*/
ffio_wfourcc(pb, "MTDT");
avio_wb16(pb, 4);
AVFormatContext *s)
{
int i;
- int64_t pos = url_ftell(pb);
+ int64_t pos = avio_tell(pb);
avio_wb32(pb, 0); /* size placeholder*/
ffio_wfourcc(pb, "moov");
avio_wb32(pb, 8); // placeholder for extended size field (64 bit)
ffio_wfourcc(pb, mov->mode == MODE_MOV ? "wide" : "free");
- mov->mdat_pos = url_ftell(pb);
+ mov->mdat_pos = avio_tell(pb);
avio_wb32(pb, 0); /* size placeholder*/
ffio_wfourcc(pb, "mdat");
return 0;
static int mov_write_ftyp_tag(AVIOContext *pb, AVFormatContext *s)
{
MOVMuxContext *mov = s->priv_data;
- int64_t pos = url_ftell(pb);
+ int64_t pos = avio_tell(pb);
int has_h264 = 0, has_video = 0;
int minor = 0x200;
int i;
AVCodecContext *enc = trk->enc;
unsigned int samplesInChunk = 0;
int size= pkt->size;
+ uint8_t *reformatted_data = NULL;
- if (url_is_streamed(s->pb)) return 0; /* Can't handle that */
+ if (!s->pb->seekable) return 0; /* Can't handle that */
if (!size) return 0; /* Discard 0 sized packets */
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};
+ {13, 14, 16, 18, 20, 21, 27, 32, 6, 0, 0, 0, 0, 0, 0, 1};
int len = 0;
while (len < size && samplesInChunk < 100) {
av_log(s, AV_LOG_ERROR, "fatal error, input is not a single packet, implement a AVParser for it\n");
return -1;
}
- } else if (enc->codec_id == CODEC_ID_ADPCM_MS ||
- enc->codec_id == CODEC_ID_ADPCM_IMA_WAV) {
- samplesInChunk = enc->frame_size;
} else if (trk->sampleSize)
samplesInChunk = size/trk->sampleSize;
else
if (enc->codec_id == CODEC_ID_H264 && trk->vosLen > 0 && *(uint8_t *)trk->vosData != 1) {
/* from x264 or from bytestream h264 */
/* nal reformating needed */
- size = ff_avc_parse_nal_units(pb, pkt->data, pkt->size);
+ if (trk->hint_track >= 0 && trk->hint_track < mov->nb_streams) {
+ ff_avc_parse_nal_units_buf(pkt->data, &reformatted_data,
+ &size);
+ avio_write(pb, reformatted_data, size);
+ } else {
+ size = ff_avc_parse_nal_units(pb, pkt->data, pkt->size);
+ }
} else {
avio_write(pb, pkt->data, size);
}
return -1;
}
- trk->cluster[trk->entry].pos = url_ftell(pb) - size;
+ trk->cluster[trk->entry].pos = avio_tell(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_flush_packet(pb);
+ avio_flush(pb);
if (trk->hint_track >= 0 && trk->hint_track < mov->nb_streams)
- ff_mov_add_hinted_packet(s, pkt, trk->hint_track, trk->entry);
+ ff_mov_add_hinted_packet(s, pkt, trk->hint_track, trk->entry,
+ reformatted_data, size);
+ av_free(reformatted_data);
return 0;
}
track->mode = mov->mode;
track->tag = MKTAG('t','e','x','t');
track->timescale = MOV_TIMESCALE;
- track->enc = avcodec_alloc_context();
+ track->enc = avcodec_alloc_context3(NULL);
track->enc->codec_type = AVMEDIA_TYPE_SUBTITLE;
for (i = 0; i < s->nb_chapters; i++) {
AVChapter *c = s->chapters[i];
- AVMetadataTag *t;
+ AVDictionaryEntry *t;
int64_t end = av_rescale_q(c->end, c->time_base, (AVRational){1,MOV_TIMESCALE});
pkt.pts = pkt.dts = av_rescale_q(c->start, c->time_base, (AVRational){1,MOV_TIMESCALE});
pkt.duration = end - pkt.dts;
- if ((t = av_metadata_get(c->metadata, "title", NULL, 0))) {
+ if ((t = av_dict_get(c->metadata, "title", NULL, 0))) {
len = strlen(t->value);
pkt.size = len+2;
pkt.data = av_malloc(pkt.size);
{
AVIOContext *pb = s->pb;
MOVMuxContext *mov = s->priv_data;
+ AVDictionaryEntry *t;
int i, hint_track = 0;
- if (url_is_streamed(s->pb)) {
+ if (!s->pb->seekable) {
av_log(s, AV_LOG_ERROR, "muxer does not support non seekable output\n");
return -1;
}
if (mov->mode & (MODE_MOV|MODE_IPOD) && s->nb_chapters)
mov->chapter_track = mov->nb_streams++;
+#if FF_API_FLAG_RTP_HINT
if (s->flags & AVFMT_FLAG_RTP_HINT) {
+ av_log(s, AV_LOG_WARNING, "The RTP_HINT flag is deprecated, enable it "
+ "via the -movflags rtphint muxer option "
+ "instead.\n");
+ mov->flags |= FF_MOV_FLAG_RTP_HINT;
+ }
+#endif
+ if (mov->flags & FF_MOV_FLAG_RTP_HINT) {
/* Add hint tracks for each audio and video stream */
hint_track = mov->nb_streams;
for (i = 0; i < s->nb_streams; i++) {
for(i=0; i<s->nb_streams; i++){
AVStream *st= s->streams[i];
MOVTrack *track= &mov->tracks[i];
- AVMetadataTag *lang = av_metadata_get(st->metadata, "language", NULL,0);
+ AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL,0);
track->enc = st->codec;
track->language = ff_mov_iso639_to_lang(lang?lang->value:"und", mov->mode!=MODE_MOV);
"or choose different container.\n");
}else if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO){
track->timescale = st->codec->sample_rate;
- 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);
- goto error;
- }else if(st->codec->codec_id == CODEC_ID_ADPCM_MS ||
- st->codec->codec_id == CODEC_ID_ADPCM_IMA_WAV){
+ /* set sampleSize for PCM and ADPCM */
+ if (av_get_bits_per_sample(st->codec->codec_id)) {
if (!st->codec->block_align) {
- av_log(s, AV_LOG_ERROR, "track %d: codec block align is not set for adpcm\n", i);
+ av_log(s, AV_LOG_ERROR, "track %d: codec block align is not set\n", i);
goto error;
}
track->sampleSize = st->codec->block_align;
- }else if(st->codec->frame_size > 1){ /* assume compressed audio */
+ }
+ /* set audio_vbr for compressed audio */
+ if (av_get_bits_per_sample(st->codec->codec_id) < 8) {
+ if (!st->codec->frame_size) {
+ av_log(s, AV_LOG_ERROR, "track %d: codec frame size is not set\n", i);
+ goto error;
+ }
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) {
if (track->timescale > UINT16_MAX) {
if (!track->height)
track->height = st->codec->height;
- av_set_pts_info(st, 64, 1, track->timescale);
+ avpriv_set_pts_info(st, 64, 1, track->timescale);
}
mov_write_mdat_tag(pb, mov);
- mov->time = s->timestamp + 0x7C25B080; //1970 based -> 1904 based
+
+#if FF_API_TIMESTAMP
+ if (s->timestamp)
+ mov->time = s->timestamp;
+ else
+#endif
+ if (t = av_dict_get(s->metadata, "creation_time", NULL, 0))
+ mov->time = ff_iso8601_to_unix_time(t->value);
+ mov->time += 0x7C25B080; //1970 based -> 1904 based
if (mov->chapter_track)
mov_create_chapter_track(s, mov->chapter_track);
- if (s->flags & AVFMT_FLAG_RTP_HINT) {
+ if (mov->flags & FF_MOV_FLAG_RTP_HINT) {
/* Initialize the hint tracks for each audio and video stream */
for (i = 0; i < s->nb_streams; i++) {
AVStream *st = s->streams[i];
}
}
- put_flush_packet(pb);
+ avio_flush(pb);
return 0;
error:
int res = 0;
int i;
- int64_t moov_pos = url_ftell(pb);
+ int64_t moov_pos = avio_tell(pb);
/* Write size of mdat tag */
if (mov->mdat_size+8 <= UINT32_MAX) {
- url_fseek(pb, mov->mdat_pos, SEEK_SET);
+ avio_seek(pb, mov->mdat_pos, SEEK_SET);
avio_wb32(pb, mov->mdat_size+8);
} else {
/* overwrite 'wide' placeholder atom */
- url_fseek(pb, mov->mdat_pos - 8, SEEK_SET);
+ avio_seek(pb, mov->mdat_pos - 8, SEEK_SET);
avio_wb32(pb, 1); /* special value: real atom size will be 64 bit value after tag field */
ffio_wfourcc(pb, "mdat");
avio_wb64(pb, mov->mdat_size+16);
}
- url_fseek(pb, moov_pos, SEEK_SET);
+ avio_seek(pb, moov_pos, SEEK_SET);
mov_write_moov_tag(pb, mov, s);
}
- put_flush_packet(pb);
+ avio_flush(pb);
av_freep(&mov->tracks);
}
#if CONFIG_MOV_MUXER
+MOV_CLASS(mov)
AVOutputFormat ff_mov_muxer = {
- "mov",
- NULL_IF_CONFIG_SMALL("MOV format"),
- NULL,
- "mov",
- sizeof(MOVMuxContext),
- CODEC_ID_AAC,
- CODEC_ID_MPEG4,
- mov_write_header,
- ff_mov_write_packet,
- mov_write_trailer,
+ .name = "mov",
+ .long_name = NULL_IF_CONFIG_SMALL("MOV format"),
+ .extensions = "mov",
+ .priv_data_size = sizeof(MOVMuxContext),
+ .audio_codec = CODEC_ID_AAC,
+#if CONFIG_LIBX264_ENCODER
+ .video_codec = CODEC_ID_H264,
+#else
+ .video_codec = CODEC_ID_MPEG4,
+#endif
+ .write_header = mov_write_header,
+ .write_packet = ff_mov_write_packet,
+ .write_trailer = mov_write_trailer,
.flags = AVFMT_GLOBALHEADER,
.codec_tag = (const AVCodecTag* const []){codec_movvideo_tags, codec_movaudio_tags, 0},
+ .priv_class = &mov_muxer_class,
};
#endif
#if CONFIG_TGP_MUXER
+MOV_CLASS(tgp)
AVOutputFormat ff_tgp_muxer = {
- "3gp",
- NULL_IF_CONFIG_SMALL("3GP format"),
- NULL,
- "3gp",
- sizeof(MOVMuxContext),
- CODEC_ID_AMR_NB,
- CODEC_ID_H263,
- mov_write_header,
- ff_mov_write_packet,
- mov_write_trailer,
+ .name = "3gp",
+ .long_name = NULL_IF_CONFIG_SMALL("3GP format"),
+ .extensions = "3gp",
+ .priv_data_size = sizeof(MOVMuxContext),
+ .audio_codec = CODEC_ID_AMR_NB,
+ .video_codec = CODEC_ID_H263,
+ .write_header = mov_write_header,
+ .write_packet = ff_mov_write_packet,
+ .write_trailer = mov_write_trailer,
.flags = AVFMT_GLOBALHEADER,
.codec_tag = (const AVCodecTag* const []){codec_3gp_tags, 0},
+ .priv_class = &tgp_muxer_class,
};
#endif
#if CONFIG_MP4_MUXER
+MOV_CLASS(mp4)
AVOutputFormat ff_mp4_muxer = {
- "mp4",
- NULL_IF_CONFIG_SMALL("MP4 format"),
- "application/mp4",
- "mp4",
- sizeof(MOVMuxContext),
- CODEC_ID_AAC,
- CODEC_ID_MPEG4,
- mov_write_header,
- ff_mov_write_packet,
- mov_write_trailer,
+ .name = "mp4",
+ .long_name = NULL_IF_CONFIG_SMALL("MP4 format"),
+ .mime_type = "application/mp4",
+ .extensions = "mp4",
+ .priv_data_size = sizeof(MOVMuxContext),
+ .audio_codec = CODEC_ID_AAC,
+#if CONFIG_LIBX264_ENCODER
+ .video_codec = CODEC_ID_H264,
+#else
+ .video_codec = CODEC_ID_MPEG4,
+#endif
+ .write_header = mov_write_header,
+ .write_packet = ff_mov_write_packet,
+ .write_trailer = mov_write_trailer,
.flags = AVFMT_GLOBALHEADER,
.codec_tag = (const AVCodecTag* const []){ff_mp4_obj_type, 0},
+ .priv_class = &mp4_muxer_class,
};
#endif
#if CONFIG_PSP_MUXER
+MOV_CLASS(psp)
AVOutputFormat ff_psp_muxer = {
- "psp",
- NULL_IF_CONFIG_SMALL("PSP MP4 format"),
- NULL,
- "mp4,psp",
- sizeof(MOVMuxContext),
- CODEC_ID_AAC,
- CODEC_ID_MPEG4,
- mov_write_header,
- ff_mov_write_packet,
- mov_write_trailer,
+ .name = "psp",
+ .long_name = NULL_IF_CONFIG_SMALL("PSP MP4 format"),
+ .extensions = "mp4,psp",
+ .priv_data_size = sizeof(MOVMuxContext),
+ .audio_codec = CODEC_ID_AAC,
+#if CONFIG_LIBX264_ENCODER
+ .video_codec = CODEC_ID_H264,
+#else
+ .video_codec = CODEC_ID_MPEG4,
+#endif
+ .write_header = mov_write_header,
+ .write_packet = ff_mov_write_packet,
+ .write_trailer = mov_write_trailer,
.flags = AVFMT_GLOBALHEADER,
.codec_tag = (const AVCodecTag* const []){ff_mp4_obj_type, 0},
+ .priv_class = &psp_muxer_class,
};
#endif
#if CONFIG_TG2_MUXER
+MOV_CLASS(tg2)
AVOutputFormat ff_tg2_muxer = {
- "3g2",
- NULL_IF_CONFIG_SMALL("3GP2 format"),
- NULL,
- "3g2",
- sizeof(MOVMuxContext),
- CODEC_ID_AMR_NB,
- CODEC_ID_H263,
- mov_write_header,
- ff_mov_write_packet,
- mov_write_trailer,
+ .name = "3g2",
+ .long_name = NULL_IF_CONFIG_SMALL("3GP2 format"),
+ .extensions = "3g2",
+ .priv_data_size = sizeof(MOVMuxContext),
+ .audio_codec = CODEC_ID_AMR_NB,
+ .video_codec = CODEC_ID_H263,
+ .write_header = mov_write_header,
+ .write_packet = ff_mov_write_packet,
+ .write_trailer = mov_write_trailer,
.flags = AVFMT_GLOBALHEADER,
.codec_tag = (const AVCodecTag* const []){codec_3gp_tags, 0},
+ .priv_class = &tg2_muxer_class,
};
#endif
#if CONFIG_IPOD_MUXER
+MOV_CLASS(ipod)
AVOutputFormat ff_ipod_muxer = {
- "ipod",
- NULL_IF_CONFIG_SMALL("iPod H.264 MP4 format"),
- "application/mp4",
- "m4v,m4a",
- sizeof(MOVMuxContext),
- CODEC_ID_AAC,
- CODEC_ID_H264,
- mov_write_header,
- ff_mov_write_packet,
- mov_write_trailer,
+ .name = "ipod",
+ .long_name = NULL_IF_CONFIG_SMALL("iPod H.264 MP4 format"),
+ .mime_type = "application/mp4",
+ .extensions = "m4v,m4a",
+ .priv_data_size = sizeof(MOVMuxContext),
+ .audio_codec = CODEC_ID_AAC,
+ .video_codec = CODEC_ID_H264,
+ .write_header = mov_write_header,
+ .write_packet = ff_mov_write_packet,
+ .write_trailer = mov_write_trailer,
.flags = AVFMT_GLOBALHEADER,
.codec_tag = (const AVCodecTag* const []){codec_ipod_tags, 0},
+ .priv_class = &ipod_muxer_class,
};
#endif