From c3af52fa8bbd6f1c5c0c70af89b02ff5b394f21d Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Wed, 25 Jan 2012 17:17:52 +0800 Subject: [PATCH 01/22] dsputil: use vertical component for drawing bottom edge. Current code only writes 8 pixels of vertical edge for YUV422, which causes MC artifacts when subsequent frames use data from that edge. --- libavcodec/x86/dsputil_mmx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/x86/dsputil_mmx.c b/libavcodec/x86/dsputil_mmx.c index e34b95b0da..7964014532 100644 --- a/libavcodec/x86/dsputil_mmx.c +++ b/libavcodec/x86/dsputil_mmx.c @@ -860,7 +860,7 @@ static void draw_edges_mmx(uint8_t *buf, int wrap, int width, int height, int w, } if (sides&EDGE_BOTTOM) { - for(i = 0; i < w; i += 4) { + for(i = 0; i < h; i += 4) { ptr= last_line + (i + 1) * wrap - w; __asm__ volatile( "1: \n\t" From 6ca3856894c8838096595f7e147df8f73169dfe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Sat, 7 Jan 2012 01:32:53 +0200 Subject: [PATCH 02/22] movenc: Add a separate start_pts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes calculation of trackDuration if the MOVIentry array is cleared. This is required by the fragmentation support in the next patch. Signed-off-by: Martin Storsjö --- libavformat/movenc.c | 7 +++++-- libavformat/movenc.h | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 85b5667076..d113bffb55 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -987,7 +987,7 @@ static int mov_write_stts_tag(AVIOContext *pb, MOVTrack *track) stts_entries = av_malloc(track->entry * sizeof(*stts_entries)); /* worst case */ for (i=0; ientry; i++) { int64_t duration = i + 1 == track->entry ? - track->trackDuration - track->cluster[i].dts + track->cluster[0].dts : /* readjusting */ + track->trackDuration - track->cluster[i].dts + track->start_dts : /* readjusting */ track->cluster[i+1].dts - track->cluster[i].dts; if (i && duration == stts_entries[entries].duration) { stts_entries[entries].count++; /* compress */ @@ -2104,7 +2104,9 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) trk->cluster[trk->entry].size = size; trk->cluster[trk->entry].entries = samplesInChunk; trk->cluster[trk->entry].dts = pkt->dts; - trk->trackDuration = pkt->dts - trk->cluster[0].dts + pkt->duration; + if (trk->start_dts == AV_NOPTS_VALUE) + trk->start_dts = pkt->dts; + trk->trackDuration = pkt->dts - trk->start_dts + pkt->duration; if (pkt->pts == AV_NOPTS_VALUE) { av_log(s, AV_LOG_WARNING, "pts has no value\n"); @@ -2253,6 +2255,7 @@ static int mov_write_header(AVFormatContext *s) /* If hinting of this track is enabled by a later hint track, * this is updated. */ track->hint_track = -1; + track->start_dts = AV_NOPTS_VALUE; if(st->codec->codec_type == AVMEDIA_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') || diff --git a/libavformat/movenc.h b/libavformat/movenc.h index 5595ac71a8..5b7689a27b 100644 --- a/libavformat/movenc.h +++ b/libavformat/movenc.h @@ -89,6 +89,7 @@ typedef struct MOVIndex { int height; ///< active picture (w/o VBI) height for D-10/IMX uint32_t tref_tag; int tref_id; ///< trackID of the referenced track + int64_t start_dts; int hint_track; ///< the track that hints this track, -1 if no hint track is set int src_track; ///< the track that this hint track describes From 83988d58ed134f82b6d2a25ef0065edfaf50ccb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Thu, 5 Jan 2012 13:57:05 +0200 Subject: [PATCH 03/22] movenc: Add support for writing fragmented mov files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- Changelog | 1 + libavformat/movenc.c | 409 ++++++++++++++++++++++++++++++++++++++++-- libavformat/movenc.h | 25 +++ libavformat/version.h | 2 +- 4 files changed, 426 insertions(+), 11 deletions(-) diff --git a/Changelog b/Changelog index 3bbbb14346..6a32f3f522 100644 --- a/Changelog +++ b/Changelog @@ -4,6 +4,7 @@ releases are sorted from youngest to oldest. version : - XWD encoder and decoder +- Support for fragmentation in the mov/mp4 muxer version 0.8: diff --git a/libavformat/movenc.c b/libavformat/movenc.c index d113bffb55..bcf755abc7 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -45,10 +45,15 @@ 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" }, + { "empty_moov", "Make the initial moov atom empty (not supported by QuickTime)", 0, AV_OPT_TYPE_CONST, {.dbl = FF_MOV_FLAG_EMPTY_MOOV}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" }, + { "frag_keyframe", "Fragment at video keyframes", 0, AV_OPT_TYPE_CONST, {.dbl = FF_MOV_FLAG_FRAG_KEYFRAME}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" }, + { "separate_moof", "Write separate moof/mdat atoms for each track", 0, AV_OPT_TYPE_CONST, {.dbl = FF_MOV_FLAG_SEPARATE_MOOF}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" }, FF_RTP_FLAG_OPTS(MOVMuxContext, rtp_flags), { "skip_iods", "Skip writing iods atom.", offsetof(MOVMuxContext, iods_skip), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM}, { "iods_audio_profile", "iods audio profile atom.", offsetof(MOVMuxContext, iods_audio_profile), AV_OPT_TYPE_INT, {.dbl = -1}, -1, 255, AV_OPT_FLAG_ENCODING_PARAM}, { "iods_video_profile", "iods video profile atom.", offsetof(MOVMuxContext, iods_video_profile), AV_OPT_TYPE_INT, {.dbl = -1}, -1, 255, AV_OPT_FLAG_ENCODING_PARAM}, + { "frag_duration", "Maximum fragment duration", offsetof(MOVMuxContext, max_fragment_duration), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM}, + { "frag_size", "Maximum fragment size", offsetof(MOVMuxContext, max_fragment_size), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM}, { NULL }, }; @@ -113,8 +118,8 @@ static int mov_write_stsz_tag(AVIOContext *pb, MOVTrack *track) oldtst = tst; entries += track->cluster[i].entries; } - if (equalChunks) { - int sSize = track->cluster[0].size/track->cluster[0].entries; + if (equalChunks && track->entry) { + int sSize = track->entry ? track->cluster[0].size/track->cluster[0].entries : 0; sSize = FFMAX(1, sSize); // adpcm mono case could make sSize == 0 avio_wb32(pb, sSize); // sample size avio_wb32(pb, entries); // sample count @@ -984,7 +989,9 @@ static int mov_write_stts_tag(AVIOContext *pb, MOVTrack *track) stts_entries[0].duration = 1; entries = 1; } else { - stts_entries = av_malloc(track->entry * sizeof(*stts_entries)); /* worst case */ + stts_entries = track->entry ? + av_malloc(track->entry * sizeof(*stts_entries)) : /* worst case */ + NULL; for (i=0; ientry; i++) { int64_t duration = i + 1 == track->entry ? track->trackDuration - track->cluster[i].dts + track->start_dts : /* readjusting */ @@ -1406,14 +1413,18 @@ static int mov_write_udta_sdp(AVIOContext *pb, AVFormatContext *ctx, int index) return len + 24; } -static int mov_write_trak_tag(AVIOContext *pb, MOVTrack *track, AVStream *st) +static int mov_write_trak_tag(AVIOContext *pb, MOVMuxContext *mov, + MOVTrack *track, AVStream *st) { 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 || track->cluster[0].dts) - mov_write_edts_tag(pb, track); // PSP Movies require edts box + if (track->mode == MODE_PSP || track->flags & MOV_TRACK_CTTS || + (track->entry && track->cluster[0].dts)) { + if (!(mov->flags & FF_MOV_FLAG_FRAGMENT)) + mov_write_edts_tag(pb, track); // PSP Movies require edts box + } if (track->tref_tag) mov_write_tref_tag(pb, track); mov_write_mdia_tag(pb, track); @@ -1458,6 +1469,30 @@ static int mov_write_iods_tag(AVIOContext *pb, MOVMuxContext *mov) return updateSize(pb, pos); } +static int mov_write_trex_tag(AVIOContext *pb, MOVTrack *track) +{ + avio_wb32(pb, 0x20); /* size */ + ffio_wfourcc(pb, "trex"); + avio_wb32(pb, 0); /* version & flags */ + avio_wb32(pb, track->trackID); /* track ID */ + avio_wb32(pb, 1); /* default sample description index */ + avio_wb32(pb, 0); /* default sample duration */ + avio_wb32(pb, 0); /* default sample size */ + avio_wb32(pb, 0); /* default sample flags */ + return 0; +} + +static int mov_write_mvex_tag(AVIOContext *pb, MOVMuxContext *mov) +{ + int64_t pos = avio_tell(pb); + int i; + avio_wb32(pb, 0x0); /* size */ + ffio_wfourcc(pb, "mvex"); + for (i = 0; i < mov->nb_streams; i++) + mov_write_trex_tag(pb, &mov->tracks[i]); + return updateSize(pb, pos); +} + static int mov_write_mvhd_tag(AVIOContext *pb, MOVMuxContext *mov) { int maxTrackID = 1, i; @@ -1844,7 +1879,8 @@ static int mov_write_moov_tag(AVIOContext *pb, MOVMuxContext *mov, ffio_wfourcc(pb, "moov"); for (i=0; inb_streams; i++) { - if(mov->tracks[i].entry <= 0) continue; + if (mov->tracks[i].entry <= 0 && !(mov->flags & FF_MOV_FLAG_FRAGMENT)) + continue; mov->tracks[i].time = mov->time; mov->tracks[i].trackID = i+1; @@ -1867,10 +1903,12 @@ static int mov_write_moov_tag(AVIOContext *pb, MOVMuxContext *mov, if (mov->mode != MODE_MOV && !mov->iods_skip) mov_write_iods_tag(pb, mov); for (i=0; inb_streams; i++) { - if(mov->tracks[i].entry > 0) { - mov_write_trak_tag(pb, &(mov->tracks[i]), i < s->nb_streams ? s->streams[i] : NULL); + if (mov->tracks[i].entry > 0 || mov->flags & FF_MOV_FLAG_FRAGMENT) { + mov_write_trak_tag(pb, mov, &(mov->tracks[i]), i < s->nb_streams ? s->streams[i] : NULL); } } + if (mov->flags & FF_MOV_FLAG_FRAGMENT) + mov_write_mvex_tag(pb, mov); /* QuickTime requires trak to precede this */ if (mov->mode == MODE_PSP) mov_write_uuidusmt_tag(pb, s); @@ -1880,6 +1918,202 @@ static int mov_write_moov_tag(AVIOContext *pb, MOVMuxContext *mov, return updateSize(pb, pos); } +static int mov_write_mfhd_tag(AVIOContext *pb, MOVMuxContext *mov) +{ + avio_wb32(pb, 16); + ffio_wfourcc(pb, "mfhd"); + avio_wb32(pb, 0); + avio_wb32(pb, mov->fragments); + return 0; +} + +static int mov_write_tfhd_tag(AVIOContext *pb, MOVTrack *track, + int64_t moof_offset) +{ + int64_t pos = avio_tell(pb); + /* default-sample-size + default-sample-duration + base-data-offset */ + uint32_t flags = 0x19; + if (!track->entry) { + flags |= 0x010000; /* duration-is-empty */ + } else { + flags |= 0x20; /* default-sample-flags-present */ + } + + avio_wb32(pb, 0); /* size placeholder */ + ffio_wfourcc(pb, "tfhd"); + avio_w8(pb, 0); /* version */ + avio_wb24(pb, flags); + + avio_wb32(pb, track->trackID); /* track-id */ + if (flags & 0x01) + avio_wb64(pb, moof_offset); + if (flags & 0x08) { + track->default_duration = track->audio_vbr ? track->enc->frame_size : 1; + avio_wb32(pb, track->default_duration); + } + if (flags & 0x10) { + track->default_size = track->entry ? track->cluster[0].size : 1; + avio_wb32(pb, track->default_size); + } else + track->default_size = -1; + + if (flags & 0x20) { + track->default_sample_flags = + track->enc->codec_type == AVMEDIA_TYPE_VIDEO ? + 0x01010000 : 0x02000000; + avio_wb32(pb, track->default_sample_flags); + } + + return updateSize(pb, pos); +} + +static uint32_t get_sample_flags(MOVTrack *track, MOVIentry *entry) +{ + return entry->flags & MOV_SYNC_SAMPLE ? 0x02000000 : 0x01010000; +} + +static int mov_write_trun_tag(AVIOContext *pb, MOVTrack *track) +{ + int64_t pos = avio_tell(pb); + uint32_t flags = 1; /* data-offset-present */ + int i; + + for (i = 0; i < track->entry; i++) { + int64_t duration = i + 1 == track->entry ? + track->trackDuration - track->cluster[i].dts + track->start_dts : + track->cluster[i + 1].dts - track->cluster[i].dts; + if (duration != track->default_duration) + flags |= 0x100; /* sample-duration-present */ + if (track->cluster[i].size != track->default_size) + flags |= 0x200; /* sample-size-present */ + if (i > 0 && get_sample_flags(track, &track->cluster[i]) != track->default_sample_flags) + flags |= 0x400; /* sample-flags-present */ + } + if (!(flags & 0x400)) + flags |= 0x4; /* first-sample-flags-present */ + if (track->flags & MOV_TRACK_CTTS) + flags |= 0x800; /* sample-composition-time-offsets-present */ + + avio_wb32(pb, 0); /* size placeholder */ + ffio_wfourcc(pb, "trun"); + avio_w8(pb, 0); /* version */ + avio_wb24(pb, flags); + + avio_wb32(pb, track->entry); /* sample count */ + track->moof_size_offset = avio_tell(pb); + avio_wb32(pb, 0); /* data offset */ + if (flags & 0x4) /* first sample flags */ + avio_wb32(pb, get_sample_flags(track, &track->cluster[0])); + + for (i = 0; i < track->entry; i++) { + int64_t duration = i + 1 == track->entry ? + track->trackDuration - track->cluster[i].dts + track->start_dts : + track->cluster[i + 1].dts - track->cluster[i].dts; + if (flags & 0x100) + avio_wb32(pb, duration); + if (flags & 0x200) + avio_wb32(pb, track->cluster[i].size); + if (flags & 0x400) + avio_wb32(pb, get_sample_flags(track, &track->cluster[i])); + if (flags & 0x800) + avio_wb32(pb, track->cluster[i].cts); + } + + return updateSize(pb, pos); +} + +static int mov_write_traf_tag(AVIOContext *pb, MOVTrack *track, int64_t moof_offset) +{ + int64_t pos = avio_tell(pb); + avio_wb32(pb, 0); /* size placeholder */ + ffio_wfourcc(pb, "traf"); + + mov_write_tfhd_tag(pb, track, moof_offset); + mov_write_trun_tag(pb, track); + + return updateSize(pb, pos); +} + +static int mov_write_moof_tag(AVIOContext *pb, MOVMuxContext *mov, int tracks) +{ + int64_t pos = avio_tell(pb), end; + int i, moof_size; + + avio_wb32(pb, 0); /* size placeholder */ + ffio_wfourcc(pb, "moof"); + + mov_write_mfhd_tag(pb, mov); + for (i = 0; i < mov->nb_streams; i++) { + MOVTrack *track = &mov->tracks[i]; + if (tracks >= 0 && i != tracks) + continue; + if (!track->entry) + continue; + mov_write_traf_tag(pb, track, pos); + } + + end = avio_tell(pb); + moof_size = end - pos; + for (i = 0; i < mov->nb_streams; i++) { + MOVTrack *track = &mov->tracks[i]; + if (tracks >= 0 && i != tracks) + continue; + if (!track->entry) + continue; + avio_seek(pb, mov->tracks[i].moof_size_offset, SEEK_SET); + avio_wb32(pb, moof_size + 8 + mov->tracks[i].data_offset); + } + avio_seek(pb, end, SEEK_SET); + + return updateSize(pb, pos); +} + +static int mov_write_tfra_tag(AVIOContext *pb, MOVTrack *track) +{ + int64_t pos = avio_tell(pb); + int i; + + avio_wb32(pb, 0); /* size placeholder */ + ffio_wfourcc(pb, "tfra"); + avio_w8(pb, 1); /* version */ + avio_wb24(pb, 0); + + avio_wb32(pb, track->trackID); + avio_wb32(pb, 0); /* length of traf/trun/sample num */ + avio_wb32(pb, track->nb_frag_info); + for (i = 0; i < track->nb_frag_info; i++) { + avio_wb64(pb, track->frag_info[i].time); + avio_wb64(pb, track->frag_info[i].offset); + avio_w8(pb, 1); /* traf number */ + avio_w8(pb, 1); /* trun number */ + avio_w8(pb, 1); /* sample number */ + } + + return updateSize(pb, pos); +} + +static int mov_write_mfra_tag(AVIOContext *pb, MOVMuxContext *mov) +{ + int64_t pos = avio_tell(pb); + int i; + + avio_wb32(pb, 0); /* size placeholder */ + ffio_wfourcc(pb, "mfra"); + + for (i = 0; i < mov->nb_streams; i++) { + MOVTrack *track = &mov->tracks[i]; + if (track->nb_frag_info) + mov_write_tfra_tag(pb, track); + } + + avio_wb32(pb, 16); + ffio_wfourcc(pb, "mfro"); + avio_wb32(pb, 0); /* version + flags */ + avio_wb32(pb, avio_tell(pb) + 4 - pos); + + return updateSize(pb, pos); +} + static int mov_write_mdat_tag(AVIOContext *pb, MOVMuxContext *mov) { avio_wb32(pb, 8); // placeholder for extended size field (64 bit) @@ -2030,6 +2264,108 @@ static int mov_parse_mpeg2_frame(AVPacket *pkt, uint32_t *flags) return 0; } +static int mov_flush_fragment(AVFormatContext *s) +{ + MOVMuxContext *mov = s->priv_data; + int i, first_track = -1; + int64_t mdat_size = 0; + + if (!(mov->flags & FF_MOV_FLAG_FRAGMENT)) + return 0; + + if (!(mov->flags & FF_MOV_FLAG_EMPTY_MOOV) && mov->fragments == 0) { + int64_t pos = avio_tell(s->pb); + + for (i = 0; i < mov->nb_streams; i++) + if (!mov->tracks[i].entry) + break; + /* Don't write the initial moov unless all tracks have data */ + if (i < mov->nb_streams) + return 0; + avio_seek(s->pb, mov->mdat_pos, SEEK_SET); + avio_wb32(s->pb, mov->mdat_size + 8); + avio_seek(s->pb, pos, SEEK_SET); + mov_write_moov_tag(s->pb, mov, s); + mov->fragments++; + mov->mdat_size = 0; + for (i = 0; i < mov->nb_streams; i++) { + if (mov->tracks[i].entry) + mov->tracks[i].frag_start += mov->tracks[i].start_dts + + mov->tracks[i].trackDuration - + mov->tracks[i].cluster[0].dts; + mov->tracks[i].entry = 0; + } + return 0; + } + + for (i = 0; i < mov->nb_streams; i++) { + MOVTrack *track = &mov->tracks[i]; + if (mov->flags & FF_MOV_FLAG_SEPARATE_MOOF) + track->data_offset = 0; + else + track->data_offset = mdat_size; + if (!track->mdat_buf) + continue; + mdat_size += avio_tell(track->mdat_buf); + if (first_track < 0) + first_track = i; + } + + if (!mdat_size) + return 0; + + for (i = 0; i < mov->nb_streams; i++) { + MOVTrack *track = &mov->tracks[i]; + int buf_size, write_moof = 1, moof_tracks = -1; + uint8_t *buf; + int64_t duration = 0; + + if (track->entry) + duration = track->start_dts + track->trackDuration - + track->cluster[0].dts; + if (mov->flags & FF_MOV_FLAG_SEPARATE_MOOF) { + if (!track->mdat_buf) + continue; + mdat_size = avio_tell(track->mdat_buf); + moof_tracks = i; + } else { + write_moof = i == first_track; + } + + if (write_moof) { + MOVFragmentInfo *info; + track->nb_frag_info++; + track->frag_info = av_realloc(track->frag_info, + sizeof(*track->frag_info) * + track->nb_frag_info); + info = &track->frag_info[track->nb_frag_info - 1]; + info->offset = avio_tell(s->pb); + info->time = mov->tracks[i].frag_start; + + mov_write_moof_tag(s->pb, mov, moof_tracks); + mov->fragments++; + + avio_wb32(s->pb, mdat_size + 8); + ffio_wfourcc(s->pb, "mdat"); + } + + if (track->entry) + track->frag_start += duration; + track->entry = 0; + if (!track->mdat_buf) + continue; + buf_size = avio_close_dyn_buf(track->mdat_buf, &buf); + track->mdat_buf = NULL; + + avio_write(s->pb, buf, buf_size); + av_free(buf); + } + + mov->mdat_size = 0; + + return 0; +} + int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) { MOVMuxContext *mov = s->priv_data; @@ -2043,6 +2379,26 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) if (!s->pb->seekable) return 0; /* Can't handle that */ if (!size) return 0; /* Discard 0 sized packets */ + if ((mov->max_fragment_duration && trk->entry && + av_rescale_q(pkt->dts - trk->cluster[0].dts, + s->streams[pkt->stream_index]->time_base, + AV_TIME_BASE_Q) >= mov->max_fragment_duration) || + (mov->max_fragment_size && mov->mdat_size + size >= mov->max_fragment_size) || + (mov->flags & FF_MOV_FLAG_FRAG_KEYFRAME && + enc->codec_type == AVMEDIA_TYPE_VIDEO && + trk->entry && pkt->flags & AV_PKT_FLAG_KEY)) { + mov_flush_fragment(s); + } + + if (mov->flags & FF_MOV_FLAG_FRAGMENT && mov->fragments > 0) { + if (!trk->mdat_buf) { + int ret; + if ((ret = avio_open_dyn_buf(&trk->mdat_buf)) < 0) + return ret; + } + pb = trk->mdat_buf; + } + 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] = @@ -2104,6 +2460,13 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) trk->cluster[trk->entry].size = size; trk->cluster[trk->entry].entries = samplesInChunk; trk->cluster[trk->entry].dts = pkt->dts; + if (!trk->entry && trk->start_dts != AV_NOPTS_VALUE) { + /* First packet of a new fragment. We already wrote the duration + * of the last packet of the previous fragment based on trackDuration, + * which might not exactly match our dts. Therefore adjust the dts + * of this packet to be what the previous packets duration implies. */ + trk->cluster[trk->entry].dts = trk->start_dts + trk->trackDuration; + } if (trk->start_dts == AV_NOPTS_VALUE) trk->start_dts = pkt->dts; trk->trackDuration = pkt->dts - trk->start_dts + pkt->duration; @@ -2309,9 +2672,24 @@ static int mov_write_header(AVFormatContext *s) track->height = st->codec->height; avpriv_set_pts_info(st, 64, 1, track->timescale); + + /* copy extradata if it exists */ + if (st->codec->extradata_size) { + track->vosLen = st->codec->extradata_size; + track->vosData = av_malloc(track->vosLen); + memcpy(track->vosData, st->codec->extradata, track->vosLen); + } } - mov_write_mdat_tag(pb, mov); + /* Set the FRAGMENT flag if any of the fragmentation methods are + * enabled. */ + if (mov->max_fragment_duration || mov->max_fragment_size || + mov->flags & (FF_MOV_FLAG_EMPTY_MOOV | + FF_MOV_FLAG_FRAG_KEYFRAME)) + mov->flags |= FF_MOV_FLAG_FRAGMENT; + + if (!(mov->flags & FF_MOV_FLAG_EMPTY_MOOV)) + mov_write_mdat_tag(pb, mov); #if FF_API_TIMESTAMP if (s->timestamp) @@ -2340,6 +2718,11 @@ static int mov_write_header(AVFormatContext *s) avio_flush(pb); + if (mov->flags & FF_MOV_FLAG_EMPTY_MOOV) { + mov_write_moov_tag(pb, mov, s); + mov->fragments++; + } + return 0; error: av_freep(&mov->tracks); @@ -2355,6 +2738,7 @@ static int mov_write_trailer(AVFormatContext *s) int64_t moov_pos = avio_tell(pb); + if (!(mov->flags & FF_MOV_FLAG_FRAGMENT)) { /* Write size of mdat tag */ if (mov->mdat_size+8 <= UINT32_MAX) { avio_seek(pb, mov->mdat_pos, SEEK_SET); @@ -2369,6 +2753,10 @@ static int mov_write_trailer(AVFormatContext *s) avio_seek(pb, moov_pos, SEEK_SET); mov_write_moov_tag(pb, mov, s); + } else { + mov_flush_fragment(s); + mov_write_mfra_tag(pb, mov); + } if (mov->chapter_track) av_freep(&mov->tracks[mov->chapter_track].enc); @@ -2377,6 +2765,7 @@ static int mov_write_trailer(AVFormatContext *s) if (mov->tracks[i].tag == MKTAG('r','t','p',' ')) ff_mov_close_hinting(&mov->tracks[i]); av_freep(&mov->tracks[i].cluster); + av_freep(&mov->tracks[i].frag_info); if(mov->tracks[i].vosLen) av_free(mov->tracks[i].vosData); diff --git a/libavformat/movenc.h b/libavformat/movenc.h index 5b7689a27b..4cc61b3a7d 100644 --- a/libavformat/movenc.h +++ b/libavformat/movenc.h @@ -65,6 +65,11 @@ typedef struct { HintSample *samples; } HintSampleQueue; +typedef struct { + int64_t offset; + int64_t time; +} MOVFragmentInfo; + typedef struct MOVIndex { int mode; int entry; @@ -98,7 +103,19 @@ typedef struct MOVIndex { int64_t cur_rtp_ts_unwrapped; uint32_t max_packet_size; + int64_t default_duration; + uint32_t default_sample_flags; + uint32_t default_size; + HintSampleQueue sample_queue; + + AVIOContext *mdat_buf; + int64_t moof_size_offset; + int64_t data_offset; + int64_t frag_start; + + int nb_frag_info; + MOVFragmentInfo *frag_info; } MOVTrack; typedef struct MOVMuxContext { @@ -116,9 +133,17 @@ typedef struct MOVMuxContext { int iods_skip; int iods_video_profile; int iods_audio_profile; + + int fragments; + int max_fragment_duration; + int max_fragment_size; } MOVMuxContext; #define FF_MOV_FLAG_RTP_HINT 1 +#define FF_MOV_FLAG_FRAGMENT 2 +#define FF_MOV_FLAG_EMPTY_MOOV 4 +#define FF_MOV_FLAG_FRAG_KEYFRAME 8 +#define FF_MOV_FLAG_SEPARATE_MOOF 16 int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt); diff --git a/libavformat/version.h b/libavformat/version.h index d50b2a54dc..b283592447 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -30,7 +30,7 @@ #include "libavutil/avutil.h" #define LIBAVFORMAT_VERSION_MAJOR 53 -#define LIBAVFORMAT_VERSION_MINOR 20 +#define LIBAVFORMAT_VERSION_MINOR 21 #define LIBAVFORMAT_VERSION_MICRO 0 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ From f1caf01d5e2913a96c5689e6570fd10e25d1c76b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Fri, 20 Jan 2012 19:27:33 +0200 Subject: [PATCH 04/22] libavformat: Add a flag for muxers that support write_packet(NULL) for flushing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavformat/avformat.h | 18 +++++++++++++++--- libavformat/utils.c | 10 +++++++++- libavformat/version.h | 2 +- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 71aed80305..18a80ac291 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -380,6 +380,7 @@ typedef struct AVFormatParameters { #define AVFMT_NOBINSEARCH 0x2000 /**< Format does not allow to fallback to binary search via read_timestamp */ #define AVFMT_NOGENSEARCH 0x4000 /**< Format does not allow to fallback to generic search */ #define AVFMT_NO_BYTE_SEEK 0x8000 /**< Format does not allow seeking by bytes */ +#define AVFMT_ALLOW_FLUSH 0x10000 /**< Format allows flushing. If not set, the muxer will not receive a NULL packet in the write_packet function. */ /** * @addtogroup lavf_encoding @@ -403,12 +404,19 @@ typedef struct AVOutputFormat { enum CodecID audio_codec; /**< default audio codec */ enum CodecID video_codec; /**< default video codec */ int (*write_header)(struct AVFormatContext *); + /** + * Write a packet. If AVFMT_ALLOW_FLUSH is set in flags, + * pkt can be NULL in order to flush data buffered in the muxer. + * When flushing, return 0 if there still is more data to flush, + * or 1 if everything was flushed and there is no more buffered + * data. + */ int (*write_packet)(struct AVFormatContext *, AVPacket *pkt); int (*write_trailer)(struct AVFormatContext *); /** * can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_RAWPICTURE, * AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS, AVFMT_VARIABLE_FPS, - * AVFMT_NODIMENSIONS, AVFMT_NOSTREAMS + * AVFMT_NODIMENSIONS, AVFMT_NOSTREAMS, AVFMT_ALLOW_FLUSH */ int flags; /** @@ -1685,8 +1693,12 @@ attribute_deprecated int av_write_header(AVFormatContext *s); * * @param s media file handle * @param pkt The packet, which contains the stream_index, buf/buf_size, - dts/pts, ... - * @return < 0 on error, = 0 if OK, 1 if end of stream wanted + * dts/pts, ... + * This can be NULL (at any time, not just at the end), in + * order to immediately flush data buffered within the muxer, + * for muxers that buffer up data internally before writing it + * to the output. + * @return < 0 on error, = 0 if OK, 1 if flushed and there is no more data to flush */ int av_write_frame(AVFormatContext *s, AVPacket *pkt); diff --git a/libavformat/utils.c b/libavformat/utils.c index 22ee13b51f..093389b386 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -3135,7 +3135,15 @@ static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt){ int av_write_frame(AVFormatContext *s, AVPacket *pkt) { - int ret = compute_pkt_fields2(s, s->streams[pkt->stream_index], pkt); + int ret; + + if (!pkt) { + if (s->oformat->flags & AVFMT_ALLOW_FLUSH) + return s->oformat->write_packet(s, pkt); + return 1; + } + + ret = compute_pkt_fields2(s, s->streams[pkt->stream_index], pkt); if(ret<0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS)) return ret; diff --git a/libavformat/version.h b/libavformat/version.h index b283592447..5cdf1c881a 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -30,7 +30,7 @@ #include "libavutil/avutil.h" #define LIBAVFORMAT_VERSION_MAJOR 53 -#define LIBAVFORMAT_VERSION_MINOR 21 +#define LIBAVFORMAT_VERSION_MINOR 22 #define LIBAVFORMAT_VERSION_MICRO 0 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ From b613ff5e930cb216ce97c79a561336e9de683b20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Fri, 20 Jan 2012 19:29:33 +0200 Subject: [PATCH 05/22] movenc: Allow the caller to decide on fragmentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavformat/movenc.c | 28 ++++++++++++++++++++-------- libavformat/movenc.h | 1 + 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index bcf755abc7..29ba129372 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -48,6 +48,7 @@ static const AVOption options[] = { { "empty_moov", "Make the initial moov atom empty (not supported by QuickTime)", 0, AV_OPT_TYPE_CONST, {.dbl = FF_MOV_FLAG_EMPTY_MOOV}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" }, { "frag_keyframe", "Fragment at video keyframes", 0, AV_OPT_TYPE_CONST, {.dbl = FF_MOV_FLAG_FRAG_KEYFRAME}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" }, { "separate_moof", "Write separate moof/mdat atoms for each track", 0, AV_OPT_TYPE_CONST, {.dbl = FF_MOV_FLAG_SEPARATE_MOOF}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" }, + { "frag_custom", "Flush fragments on caller requests", 0, AV_OPT_TYPE_CONST, {.dbl = FF_MOV_FLAG_FRAG_CUSTOM}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" }, FF_RTP_FLAG_OPTS(MOVMuxContext, rtp_flags), { "skip_iods", "Skip writing iods atom.", offsetof(MOVMuxContext, iods_skip), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM}, { "iods_audio_profile", "iods audio profile atom.", offsetof(MOVMuxContext, iods_audio_profile), AV_OPT_TYPE_INT, {.dbl = -1}, -1, 255, AV_OPT_FLAG_ENCODING_PARAM}, @@ -2366,7 +2367,7 @@ static int mov_flush_fragment(AVFormatContext *s) return 0; } -int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) +static int mov_write_packet_internal(AVFormatContext *s, AVPacket *pkt) { MOVMuxContext *mov = s->priv_data; AVIOContext *pb = s->pb; @@ -2504,6 +2505,16 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) return 0; } +int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) +{ + if (!pkt) { + mov_flush_fragment(s); + return 1; + } else { + return mov_write_packet_internal(s, pkt); + } +} + // QuickTime chapters involve an additional text track with the chapter names // as samples, and a tref pointing from the other tracks to the chapter one. static void mov_create_chapter_track(AVFormatContext *s, int tracknum) @@ -2685,7 +2696,8 @@ static int mov_write_header(AVFormatContext *s) * enabled. */ if (mov->max_fragment_duration || mov->max_fragment_size || mov->flags & (FF_MOV_FLAG_EMPTY_MOOV | - FF_MOV_FLAG_FRAG_KEYFRAME)) + FF_MOV_FLAG_FRAG_KEYFRAME | + FF_MOV_FLAG_FRAG_CUSTOM)) mov->flags |= FF_MOV_FLAG_FRAGMENT; if (!(mov->flags & FF_MOV_FLAG_EMPTY_MOOV)) @@ -2794,7 +2806,7 @@ AVOutputFormat ff_mov_muxer = { .write_header = mov_write_header, .write_packet = ff_mov_write_packet, .write_trailer = mov_write_trailer, - .flags = AVFMT_GLOBALHEADER, + .flags = AVFMT_GLOBALHEADER | AVFMT_ALLOW_FLUSH, .codec_tag = (const AVCodecTag* const []){codec_movvideo_tags, codec_movaudio_tags, 0}, .priv_class = &mov_muxer_class, }; @@ -2811,7 +2823,7 @@ AVOutputFormat ff_tgp_muxer = { .write_header = mov_write_header, .write_packet = ff_mov_write_packet, .write_trailer = mov_write_trailer, - .flags = AVFMT_GLOBALHEADER, + .flags = AVFMT_GLOBALHEADER | AVFMT_ALLOW_FLUSH, .codec_tag = (const AVCodecTag* const []){codec_3gp_tags, 0}, .priv_class = &tgp_muxer_class, }; @@ -2833,7 +2845,7 @@ AVOutputFormat ff_mp4_muxer = { .write_header = mov_write_header, .write_packet = ff_mov_write_packet, .write_trailer = mov_write_trailer, - .flags = AVFMT_GLOBALHEADER, + .flags = AVFMT_GLOBALHEADER | AVFMT_ALLOW_FLUSH, .codec_tag = (const AVCodecTag* const []){ff_mp4_obj_type, 0}, .priv_class = &mp4_muxer_class, }; @@ -2854,7 +2866,7 @@ AVOutputFormat ff_psp_muxer = { .write_header = mov_write_header, .write_packet = ff_mov_write_packet, .write_trailer = mov_write_trailer, - .flags = AVFMT_GLOBALHEADER, + .flags = AVFMT_GLOBALHEADER | AVFMT_ALLOW_FLUSH, .codec_tag = (const AVCodecTag* const []){ff_mp4_obj_type, 0}, .priv_class = &psp_muxer_class, }; @@ -2871,7 +2883,7 @@ AVOutputFormat ff_tg2_muxer = { .write_header = mov_write_header, .write_packet = ff_mov_write_packet, .write_trailer = mov_write_trailer, - .flags = AVFMT_GLOBALHEADER, + .flags = AVFMT_GLOBALHEADER | AVFMT_ALLOW_FLUSH, .codec_tag = (const AVCodecTag* const []){codec_3gp_tags, 0}, .priv_class = &tg2_muxer_class, }; @@ -2889,7 +2901,7 @@ AVOutputFormat ff_ipod_muxer = { .write_header = mov_write_header, .write_packet = ff_mov_write_packet, .write_trailer = mov_write_trailer, - .flags = AVFMT_GLOBALHEADER, + .flags = AVFMT_GLOBALHEADER | AVFMT_ALLOW_FLUSH, .codec_tag = (const AVCodecTag* const []){codec_ipod_tags, 0}, .priv_class = &ipod_muxer_class, }; diff --git a/libavformat/movenc.h b/libavformat/movenc.h index 4cc61b3a7d..892324948e 100644 --- a/libavformat/movenc.h +++ b/libavformat/movenc.h @@ -144,6 +144,7 @@ typedef struct MOVMuxContext { #define FF_MOV_FLAG_EMPTY_MOOV 4 #define FF_MOV_FLAG_FRAG_KEYFRAME 8 #define FF_MOV_FLAG_SEPARATE_MOOF 16 +#define FF_MOV_FLAG_FRAG_CUSTOM 32 int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt); From 4ddd54dab40fd84391d1edaec319353f986119b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Mon, 9 Jan 2012 17:58:26 +0200 Subject: [PATCH 06/22] movenc: Add a separate ismv/isma (smooth streaming) muxer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- Changelog | 1 + libavformat/allformats.c | 1 + libavformat/movenc.c | 138 +++++++++++++++++++++++++++++++++++++-- libavformat/movenc.h | 5 ++ libavformat/version.h | 2 +- 5 files changed, 142 insertions(+), 5 deletions(-) diff --git a/Changelog b/Changelog index 6a32f3f522..cc7420cb45 100644 --- a/Changelog +++ b/Changelog @@ -5,6 +5,7 @@ version : - XWD encoder and decoder - Support for fragmentation in the mov/mp4 muxer +- ISMV (Smooth Streaming) muxer version 0.8: diff --git a/libavformat/allformats.c b/libavformat/allformats.c index 481d2c1e31..66a8cfec48 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -111,6 +111,7 @@ void av_register_all(void) REGISTER_DEMUXER (INGENIENT, ingenient); REGISTER_DEMUXER (IPMOVIE, ipmovie); REGISTER_MUXER (IPOD, ipod); + REGISTER_MUXER (ISMV, ismv); REGISTER_DEMUXER (ISS, iss); REGISTER_DEMUXER (IV8, iv8); REGISTER_MUXDEMUX (IVF, ivf); diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 29ba129372..da110ddda0 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -55,6 +55,7 @@ static const AVOption options[] = { { "iods_video_profile", "iods video profile atom.", offsetof(MOVMuxContext, iods_video_profile), AV_OPT_TYPE_INT, {.dbl = -1}, -1, 255, AV_OPT_FLAG_ENCODING_PARAM}, { "frag_duration", "Maximum fragment duration", offsetof(MOVMuxContext, max_fragment_duration), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM}, { "frag_size", "Maximum fragment size", offsetof(MOVMuxContext, max_fragment_size), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM}, + { "ism_lookahead", "Number of lookahead entries for ISM files", offsetof(MOVMuxContext, ism_lookahead), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM}, { NULL }, }; @@ -761,7 +762,7 @@ static int mov_find_codec_tag(AVFormatContext *s, MOVTrack *track) { int tag = track->enc->codec_tag; - if (track->mode == MODE_MP4 || track->mode == MODE_PSP) + if (track->mode == MODE_MP4 || track->mode == MODE_PSP || track->mode == MODE_ISM) tag = mp4_get_codec_tag(s, track); else if (track->mode == MODE_IPOD) tag = ipod_get_codec_tag(s, track); @@ -1940,6 +1941,11 @@ static int mov_write_tfhd_tag(AVIOContext *pb, MOVTrack *track, flags |= 0x20; /* default-sample-flags-present */ } + /* Don't set a default sample size when creating data for silverlight, + * the player refuses to play files with that set. */ + if (track->mode == MODE_ISM) + flags &= ~0x10; + avio_wb32(pb, 0); /* size placeholder */ ffio_wfourcc(pb, "tfhd"); avio_w8(pb, 0); /* version */ @@ -2023,7 +2029,78 @@ static int mov_write_trun_tag(AVIOContext *pb, MOVTrack *track) return updateSize(pb, pos); } -static int mov_write_traf_tag(AVIOContext *pb, MOVTrack *track, int64_t moof_offset) +static int mov_write_tfxd_tag(AVIOContext *pb, MOVTrack *track) +{ + int64_t pos = avio_tell(pb); + const uint8_t uuid[] = { + 0x6d, 0x1d, 0x9b, 0x05, 0x42, 0xd5, 0x44, 0xe6, + 0x80, 0xe2, 0x14, 0x1d, 0xaf, 0xf7, 0x57, 0xb2 + }; + + avio_wb32(pb, 0); /* size placeholder */ + ffio_wfourcc(pb, "uuid"); + avio_write(pb, uuid, sizeof(uuid)); + avio_w8(pb, 1); + avio_wb24(pb, 0); + avio_wb64(pb, track->frag_start); + avio_wb64(pb, track->start_dts + track->trackDuration - + track->cluster[0].dts); + + return updateSize(pb, pos); +} + +static int mov_write_tfrf_tag(AVIOContext *pb, MOVMuxContext *mov, + MOVTrack *track, int entry) +{ + int n = track->nb_frag_info - 1 - entry, i; + int size = 8 + 16 + 4 + 1 + 16*n; + const uint8_t uuid[] = { + 0xd4, 0x80, 0x7e, 0xf2, 0xca, 0x39, 0x46, 0x95, + 0x8e, 0x54, 0x26, 0xcb, 0x9e, 0x46, 0xa7, 0x9f + }; + + if (entry < 0) + return 0; + + avio_seek(pb, track->frag_info[entry].tfrf_offset, SEEK_SET); + avio_wb32(pb, size); + ffio_wfourcc(pb, "uuid"); + avio_write(pb, uuid, sizeof(uuid)); + avio_w8(pb, 1); + avio_wb24(pb, 0); + avio_w8(pb, n); + for (i = 0; i < n; i++) { + int index = entry + 1 + i; + avio_wb64(pb, track->frag_info[index].time); + avio_wb64(pb, track->frag_info[index].duration); + } + if (n < mov->ism_lookahead) { + int free_size = 16*(mov->ism_lookahead - n); + avio_wb32(pb, free_size); + ffio_wfourcc(pb, "free"); + for (i = 0; i < free_size - 8; i++) + avio_w8(pb, 0); + } + + return 0; +} + +static int mov_write_tfrf_tags(AVIOContext *pb, MOVMuxContext *mov, + MOVTrack *track) +{ + int64_t pos = avio_tell(pb); + int i; + for (i = 0; i < mov->ism_lookahead; i++) { + /* Update the tfrf tag for the last ism_lookahead fragments, + * nb_frag_info - 1 is the next fragment to be written. */ + mov_write_tfrf_tag(pb, mov, track, track->nb_frag_info - 2 - i); + } + avio_seek(pb, pos, SEEK_SET); + return 0; +} + +static int mov_write_traf_tag(AVIOContext *pb, MOVMuxContext *mov, + MOVTrack *track, int64_t moof_offset) { int64_t pos = avio_tell(pb); avio_wb32(pb, 0); /* size placeholder */ @@ -2031,6 +2108,19 @@ static int mov_write_traf_tag(AVIOContext *pb, MOVTrack *track, int64_t moof_off mov_write_tfhd_tag(pb, track, moof_offset); mov_write_trun_tag(pb, track); + if (mov->mode == MODE_ISM) { + mov_write_tfxd_tag(pb, track); + + if (mov->ism_lookahead) { + int i, size = 16 + 4 + 1 + 16*mov->ism_lookahead; + + track->tfrf_offset = avio_tell(pb); + avio_wb32(pb, 8 + size); + ffio_wfourcc(pb, "free"); + for (i = 0; i < size; i++) + avio_w8(pb, 0); + } + } return updateSize(pb, pos); } @@ -2050,7 +2140,7 @@ static int mov_write_moof_tag(AVIOContext *pb, MOVMuxContext *mov, int tracks) continue; if (!track->entry) continue; - mov_write_traf_tag(pb, track, pos); + mov_write_traf_tag(pb, mov, track, pos); } end = avio_tell(pb); @@ -2158,6 +2248,8 @@ static int mov_write_ftyp_tag(AVIOContext *pb, AVFormatContext *s) ffio_wfourcc(pb, "isom"); else if (mov->mode == MODE_IPOD) ffio_wfourcc(pb, has_video ? "M4V ":"M4A "); + else if (mov->mode == MODE_ISM) + ffio_wfourcc(pb, "isml"); else ffio_wfourcc(pb, "qt "); @@ -2165,7 +2257,10 @@ static int mov_write_ftyp_tag(AVIOContext *pb, AVFormatContext *s) if(mov->mode == MODE_MOV) ffio_wfourcc(pb, "qt "); - else{ + else if (mov->mode == MODE_ISM) { + ffio_wfourcc(pb, "piff"); + ffio_wfourcc(pb, "iso2"); + } else { ffio_wfourcc(pb, "isom"); ffio_wfourcc(pb, "iso2"); if(has_h264) @@ -2342,8 +2437,11 @@ static int mov_flush_fragment(AVFormatContext *s) info = &track->frag_info[track->nb_frag_info - 1]; info->offset = avio_tell(s->pb); info->time = mov->tracks[i].frag_start; + info->duration = duration; + mov_write_tfrf_tags(s->pb, mov, track); mov_write_moof_tag(s->pb, mov, moof_tracks); + info->tfrf_offset = track->tfrf_offset; mov->fragments++; avio_wb32(s->pb, mdat_size + 8); @@ -2571,6 +2669,7 @@ static int mov_write_header(AVFormatContext *s) else if (!strcmp("mov", s->oformat->name)) mov->mode = MODE_MOV; else if (!strcmp("psp", s->oformat->name)) mov->mode = MODE_PSP; else if (!strcmp("ipod",s->oformat->name)) mov->mode = MODE_IPOD; + else if (!strcmp("ismv",s->oformat->name)) mov->mode = MODE_ISM; mov_write_ftyp_tag(pb,s); if (mov->mode == MODE_PSP) { @@ -2681,6 +2780,10 @@ static int mov_write_header(AVFormatContext *s) } if (!track->height) track->height = st->codec->height; + /* The ism specific timescale isn't mandatory, but is assumed by + * some tools, such as mp4split. */ + if (mov->mode == MODE_ISM) + track->timescale = 10000000; avpriv_set_pts_info(st, 64, 1, track->timescale); @@ -2692,6 +2795,15 @@ static int mov_write_header(AVFormatContext *s) } } + if (mov->mode == MODE_ISM) { + /* If no fragmentation options have been set, set a default. */ + if (!(mov->flags & (FF_MOV_FLAG_FRAG_KEYFRAME | + FF_MOV_FLAG_FRAG_CUSTOM)) && + !mov->max_fragment_duration && !mov->max_fragment_size) + mov->max_fragment_duration = 5000000; + mov->flags |= FF_MOV_FLAG_EMPTY_MOOV | FF_MOV_FLAG_SEPARATE_MOOF; + } + /* Set the FRAGMENT flag if any of the fragmentation methods are * enabled. */ if (mov->max_fragment_duration || mov->max_fragment_size || @@ -2906,3 +3018,21 @@ AVOutputFormat ff_ipod_muxer = { .priv_class = &ipod_muxer_class, }; #endif +#if CONFIG_ISMV_MUXER +MOV_CLASS(ismv) +AVOutputFormat ff_ismv_muxer = { + .name = "ismv", + .long_name = NULL_IF_CONFIG_SMALL("ISMV/ISMA (Smooth Streaming) format"), + .mime_type = "application/mp4", + .extensions = "ismv,isma", + .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 | AVFMT_ALLOW_FLUSH, + .codec_tag = (const AVCodecTag* const []){ff_mp4_obj_type, 0}, + .priv_class = &ismv_muxer_class, +}; +#endif diff --git a/libavformat/movenc.h b/libavformat/movenc.h index 892324948e..a1e504dca5 100644 --- a/libavformat/movenc.h +++ b/libavformat/movenc.h @@ -38,6 +38,7 @@ // avconv -i testinput.avi -f psp -r 14.985 -s 320x240 -b 768 -ar 24000 -ab 32 M4V00001.MP4 #define MODE_3G2 0x10 #define MODE_IPOD 0x20 +#define MODE_ISM 0x40 typedef struct MOVIentry { uint64_t pos; @@ -68,6 +69,8 @@ typedef struct { typedef struct { int64_t offset; int64_t time; + int64_t duration; + int64_t tfrf_offset; } MOVFragmentInfo; typedef struct MOVIndex { @@ -113,6 +116,7 @@ typedef struct MOVIndex { int64_t moof_size_offset; int64_t data_offset; int64_t frag_start; + int64_t tfrf_offset; int nb_frag_info; MOVFragmentInfo *frag_info; @@ -137,6 +141,7 @@ typedef struct MOVMuxContext { int fragments; int max_fragment_duration; int max_fragment_size; + int ism_lookahead; } MOVMuxContext; #define FF_MOV_FLAG_RTP_HINT 1 diff --git a/libavformat/version.h b/libavformat/version.h index 5cdf1c881a..cdea318eba 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -30,7 +30,7 @@ #include "libavutil/avutil.h" #define LIBAVFORMAT_VERSION_MAJOR 53 -#define LIBAVFORMAT_VERSION_MINOR 22 +#define LIBAVFORMAT_VERSION_MINOR 23 #define LIBAVFORMAT_VERSION_MICRO 0 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ From 3b5d4428acf6eab60410358a5dbf931a17300ecf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Mon, 9 Jan 2012 11:05:33 +0200 Subject: [PATCH 07/22] movenc: Write the sample rate instead of time scale in the stsd atom MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For ismv/isma, the time scale might not be the same as the sample rate. Signed-off-by: Martin Storsjö --- libavformat/movenc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index da110ddda0..95d92aa71c 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -478,7 +478,7 @@ static int mov_write_audio_tag(AVIOContext *pb, MOVTrack *track) avio_wb16(pb, 0); avio_wb32(pb, 0x00010000); avio_wb32(pb, 72); - avio_wb64(pb, av_double2int(track->timescale)); + avio_wb64(pb, av_double2int(track->enc->sample_rate)); avio_wb32(pb, track->enc->channels); avio_wb32(pb, 0x7F000000); avio_wb32(pb, av_get_bits_per_sample(track->enc->codec_id)); @@ -492,7 +492,7 @@ static int mov_write_audio_tag(AVIOContext *pb, MOVTrack *track) avio_wb16(pb, 0); avio_wb16(pb, 0); /* packet size (= 0) */ - avio_wb16(pb, track->timescale); /* Time scale */ + avio_wb16(pb, track->enc->sample_rate); avio_wb16(pb, 0); /* Reserved */ } From bc7d05177fc93c62de4e03dddccba55c42124e5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Fri, 13 Jan 2012 14:40:24 +0200 Subject: [PATCH 08/22] movdec: Calculate an average bit rate for fragmented streams, too MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavformat/isom.h | 1 + libavformat/mov.c | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/libavformat/isom.h b/libavformat/isom.h index e6d04dc526..16d777651a 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -125,6 +125,7 @@ typedef struct MOVStreamContext { int dts_shift; ///< dts shift when ctts is negative uint32_t palette[256]; int has_palette; + int64_t data_size; } MOVStreamContext; typedef struct MOVContext { diff --git a/libavformat/mov.c b/libavformat/mov.c index c6022d5d3a..9fb4a21c8c 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -1580,8 +1580,10 @@ static int mov_read_stsz(MOVContext *c, AVIOContext *pb, MOVAtom atom) init_get_bits(&gb, buf, 8*num_bytes); - for (i=0; isample_sizes[i] = get_bits_long(&gb, field_size); + sc->data_size += sc->sample_sizes[i]; + } av_free(buf); return 0; @@ -2258,6 +2260,7 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) distance++; dts += sample_duration; offset += sample_size; + sc->data_size += sample_size; } frag->moof_offset = offset; st->duration = dts + sc->time_offset; @@ -2576,6 +2579,16 @@ static int mov_read_header(AVFormatContext *s, AVFormatParameters *ap) if (pb->seekable && mov->chapter_track > 0) mov_read_chapters(s); + if (mov->trex_data) { + int i; + for (i = 0; i < s->nb_streams; i++) { + AVStream *st = s->streams[i]; + MOVStreamContext *sc = st->priv_data; + if (st->duration) + st->codec->bit_rate = sc->data_size * 8 * sc->time_scale / st->duration; + } + } + return 0; } From 33ec9ef96d4220c4c846a5d3f2e95ba528b8bb16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Mon, 9 Jan 2012 18:27:33 +0200 Subject: [PATCH 09/22] Add a tool for creating smooth streaming manifests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It can also optionally split the file into individual fragments, which allows it to be served from any web server without any server side support. Signed-off-by: Martin Storsjö --- libavformat/Makefile | 2 +- tools/ismindex.c | 514 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 515 insertions(+), 1 deletion(-) create mode 100644 tools/ismindex.c diff --git a/libavformat/Makefile b/libavformat/Makefile index a19ff3c48b..45f757690d 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -354,6 +354,6 @@ SKIPHEADERS-$(CONFIG_NETWORK) += network.h rtsp.h EXAMPLES = metadata output TESTPROGS = seek -TOOLS = aviocat pktdumper probetest +TOOLS = aviocat ismindex pktdumper probetest $(SUBDIR)output-example$(EXESUF): ELIBS = -lswscale diff --git a/tools/ismindex.c b/tools/ismindex.c new file mode 100644 index 0000000000..4e14d1970f --- /dev/null +++ b/tools/ismindex.c @@ -0,0 +1,514 @@ +/* + * Copyright (c) 2012 Martin Storsjo + * + * This file is part of Libav. + * + * 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. + * + * 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 Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* + * To create a simple file for smooth streaming: + * avconv -movflags frag_keyframe foo.ismv + * ismindex -n foo foo.ismv + * This step creates foo.ism and foo.ismc that is required by IIS for + * serving it. + * + * To pre-split files for serving as static files by a web server without + * any extra server support, create the ismv file as above, and split it: + * ismindex -split foo.ismv + * This step creates a file Manifest and directories QualityLevel(...), + * that can be read directly by a smooth streaming player. + */ + +#include +#include +#include +#include "libavformat/avformat.h" +#include "libavutil/intreadwrite.h" +#include "libavutil/mathematics.h" + +static int usage(const char *argv0, int ret) +{ + fprintf(stderr, "%s [-split] [-n basename] file1 [file2] ...\n", argv0); + return ret; +} + +struct MoofOffset { + int64_t time; + int64_t offset; + int duration; +}; + +struct VideoFile { + const char *name; + int64_t duration; + int bitrate; + int track_id; + int is_audio, is_video; + int width, height; + int chunks; + int sample_rate, channels; + uint8_t *codec_private; + int codec_private_size; + struct MoofOffset *offsets; + int timescale; + const char *fourcc; + int blocksize; + int tag; +}; + +struct VideoFiles { + int nb_files; + int64_t duration; + struct VideoFile **files; + int video_file, audio_file; + int nb_video_files, nb_audio_files; +}; + +static int copy_tag(AVIOContext *in, AVIOContext *out, int32_t tag_name) +{ + int32_t size, tag; + + size = avio_rb32(in); + tag = avio_rb32(in); + avio_wb32(out, size); + avio_wb32(out, tag); + if (tag != tag_name) + return -1; + size -= 8; + while (size > 0) { + char buf[1024]; + int len = FFMIN(sizeof(buf), size); + if (avio_read(in, buf, len) != len) + break; + avio_write(out, buf, len); + size -= len; + } + return 0; +} + +static int write_fragment(const char *filename, AVIOContext *in) +{ + AVIOContext *out = NULL; + int ret; + + if ((ret = avio_open2(&out, filename, AVIO_FLAG_WRITE, NULL, NULL)) < 0) + return ret; + copy_tag(in, out, MKBETAG('m', 'o', 'o', 'f')); + copy_tag(in, out, MKBETAG('m', 'd', 'a', 't')); + + avio_flush(out); + avio_close(out); + + return ret; +} + +static int write_fragments(struct VideoFiles *files, int start_index, + AVIOContext *in) +{ + char dirname[100], filename[500]; + int i, j; + + for (i = start_index; i < files->nb_files; i++) { + struct VideoFile *vf = files->files[i]; + const char *type = vf->is_video ? "video" : "audio"; + snprintf(dirname, sizeof(dirname), "QualityLevels(%d)", vf->bitrate); + mkdir(dirname, 0777); + for (j = 0; j < vf->chunks; j++) { + snprintf(filename, sizeof(filename), "%s/Fragments(%s=%"PRId64")", + dirname, type, vf->offsets[j].time); + avio_seek(in, vf->offsets[j].offset, SEEK_SET); + write_fragment(filename, in); + } + } + return 0; +} + +static int read_tfra(struct VideoFiles *files, int start_index, AVIOContext *f) +{ + int ret = AVERROR_EOF, track_id; + int version, fieldlength, i, j; + int64_t pos = avio_tell(f); + uint32_t size = avio_rb32(f); + struct VideoFile *vf = NULL; + + if (avio_rb32(f) != MKBETAG('t', 'f', 'r', 'a')) + goto fail; + version = avio_r8(f); + avio_rb24(f); + track_id = avio_rb32(f); /* track id */ + for (i = start_index; i < files->nb_files && !vf; i++) { + if (files->files[i]->track_id == track_id) + vf = files->files[i]; + } + if (!vf) { + /* Ok, continue parsing the next atom */ + ret = 0; + goto fail; + } + fieldlength = avio_rb32(f); + vf->chunks = avio_rb32(f); + vf->offsets = av_mallocz(sizeof(*vf->offsets) * vf->chunks); + if (!vf->offsets) { + ret = AVERROR(ENOMEM); + goto fail; + } + for (i = 0; i < vf->chunks; i++) { + if (version == 1) { + vf->offsets[i].time = avio_rb64(f); + vf->offsets[i].offset = avio_rb64(f); + } else { + vf->offsets[i].time = avio_rb32(f); + vf->offsets[i].offset = avio_rb32(f); + } + for (j = 0; j < ((fieldlength >> 4) & 3) + 1; j++) + avio_r8(f); + for (j = 0; j < ((fieldlength >> 2) & 3) + 1; j++) + avio_r8(f); + for (j = 0; j < ((fieldlength >> 0) & 3) + 1; j++) + avio_r8(f); + if (i > 0) + vf->offsets[i - 1].duration = vf->offsets[i].time - + vf->offsets[i - 1].time; + } + if (vf->chunks > 0) + vf->offsets[vf->chunks - 1].duration = vf->duration - + vf->offsets[vf->chunks - 1].time; + ret = 0; +fail: + avio_seek(f, pos + size, SEEK_SET); + return ret; +} + +static int read_mfra(struct VideoFiles *files, int start_index, + const char *file, int split) +{ + int err = 0; + AVIOContext *f = NULL; + int32_t mfra_size; + + if ((err = avio_open2(&f, file, AVIO_FLAG_READ, NULL, NULL)) < 0) + goto fail; + avio_seek(f, avio_size(f) - 4, SEEK_SET); + mfra_size = avio_rb32(f); + avio_seek(f, -mfra_size, SEEK_CUR); + if (avio_rb32(f) != mfra_size) + goto fail; + if (avio_rb32(f) != MKBETAG('m', 'f', 'r', 'a')) + goto fail; + while (!read_tfra(files, start_index, f)) { + /* Empty */ + } + + if (split) + write_fragments(files, start_index, f); + +fail: + if (f) + avio_close(f); + return err; +} + +static int get_private_data(struct VideoFile *vf, AVCodecContext *codec) +{ + vf->codec_private_size = codec->extradata_size; + vf->codec_private = av_mallocz(codec->extradata_size); + if (!vf->codec_private) + return AVERROR(ENOMEM); + memcpy(vf->codec_private, codec->extradata, codec->extradata_size); + return 0; +} + +static int get_video_private_data(struct VideoFile *vf, AVCodecContext *codec) +{ + AVIOContext *io = NULL; + uint16_t sps_size, pps_size; + int err = AVERROR(EINVAL); + + if (codec->codec_id == CODEC_ID_VC1) + return get_private_data(vf, codec); + + avio_open_dyn_buf(&io); + if (codec->extradata_size < 11 || codec->extradata[0] != 1) + goto fail; + sps_size = AV_RB16(&codec->extradata[6]); + if (11 + sps_size > codec->extradata_size) + goto fail; + avio_wb32(io, 0x00000001); + avio_write(io, &codec->extradata[8], sps_size); + pps_size = AV_RB16(&codec->extradata[9 + sps_size]); + if (11 + sps_size + pps_size > codec->extradata_size) + goto fail; + avio_wb32(io, 0x00000001); + avio_write(io, &codec->extradata[11 + sps_size], pps_size); + err = 0; +fail: + vf->codec_private_size = avio_close_dyn_buf(io, &vf->codec_private); + return err; +} + +static int handle_file(struct VideoFiles *files, const char *file, int split) +{ + AVFormatContext *ctx = NULL; + int err = 0, i, orig_files = files->nb_files; + char errbuf[50], *ptr; + struct VideoFile *vf; + + err = avformat_open_input(&ctx, file, NULL, NULL); + if (err < 0) { + av_strerror(err, errbuf, sizeof(errbuf)); + fprintf(stderr, "Unable to open %s: %s\n", file, errbuf); + return 1; + } + + err = avformat_find_stream_info(ctx, NULL); + if (err < 0) { + av_strerror(err, errbuf, sizeof(errbuf)); + fprintf(stderr, "Unable to identify %s: %s\n", file, errbuf); + goto fail; + } + + if (ctx->nb_streams < 1) { + fprintf(stderr, "No streams found in %s\n", file); + goto fail; + } + if (!files->duration) + files->duration = ctx->duration; + + for (i = 0; i < ctx->nb_streams; i++) { + AVStream *st = ctx->streams[i]; + vf = av_mallocz(sizeof(*vf)); + files->files = av_realloc(files->files, + sizeof(*files->files)*(files->nb_files + 1)); + files->files[files->nb_files] = vf; + + vf->name = file; + if ((ptr = strrchr(file, '/')) != NULL) + vf->name = ptr + 1; + + vf->bitrate = st->codec->bit_rate; + vf->track_id = st->id; + vf->timescale = st->time_base.den; + vf->duration = av_rescale_rnd(ctx->duration, vf->timescale, + AV_TIME_BASE, AV_ROUND_UP); + vf->is_audio = st->codec->codec_type == AVMEDIA_TYPE_AUDIO; + vf->is_video = st->codec->codec_type == AVMEDIA_TYPE_VIDEO; + + if (!vf->is_audio && !vf->is_video) { + fprintf(stderr, "Track %d in %s is neither video nor audio, " + "skipping\n", vf->track_id, file); + av_freep(&files->files[files->nb_files]); + continue; + } + + if (vf->is_audio) { + if (files->audio_file < 0) + files->audio_file = files->nb_files; + files->nb_audio_files++; + vf->channels = st->codec->channels; + vf->sample_rate = st->codec->sample_rate; + if (st->codec->codec_id == CODEC_ID_AAC) { + vf->fourcc = "AACL"; + vf->tag = 255; + vf->blocksize = 4; + } else if (st->codec->codec_id == CODEC_ID_WMAPRO) { + vf->fourcc = "WMAP"; + vf->tag = st->codec->codec_tag; + vf->blocksize = st->codec->block_align; + } + get_private_data(vf, st->codec); + } + if (vf->is_video) { + if (files->video_file < 0) + files->video_file = files->nb_files; + files->nb_video_files++; + vf->width = st->codec->width; + vf->height = st->codec->height; + if (st->codec->codec_id == CODEC_ID_H264) + vf->fourcc = "H264"; + else if (st->codec->codec_id == CODEC_ID_VC1) + vf->fourcc = "WVC1"; + get_video_private_data(vf, st->codec); + } + + files->nb_files++; + } + + avformat_close_input(&ctx); + + read_mfra(files, orig_files, file, split); + +fail: + if (ctx) + avformat_close_input(&ctx); + return err; +} + +static void output_server_manifest(struct VideoFiles *files, + const char *basename) +{ + char filename[1000]; + FILE *out; + int i; + + snprintf(filename, sizeof(filename), "%s.ism", basename); + out = fopen(filename, "w"); + if (!out) { + perror(filename); + return; + } + fprintf(out, "\n"); + fprintf(out, "\n"); + fprintf(out, "\t\n"); + fprintf(out, "\t\t\n", basename); + fprintf(out, "\t\n"); + fprintf(out, "\t\n"); + fprintf(out, "\t\t\n"); + for (i = 0; i < files->nb_files; i++) { + struct VideoFile *vf = files->files[i]; + const char *type = vf->is_video ? "video" : "audio"; + fprintf(out, "\t\t\t<%s src=\"%s\" systemBitrate=\"%d\">\n", + type, vf->name, vf->bitrate); + fprintf(out, "\t\t\t\t\n", vf->track_id); + fprintf(out, "\t\t\t\n", type); + } + fprintf(out, "\t\t\n"); + fprintf(out, "\t\n"); + fprintf(out, "\n"); + fclose(out); +} + +static void output_client_manifest(struct VideoFiles *files, + const char *basename, int split) +{ + char filename[1000]; + FILE *out; + int i, j; + + if (split) + snprintf(filename, sizeof(filename), "Manifest"); + else + snprintf(filename, sizeof(filename), "%s.ismc", basename); + out = fopen(filename, "w"); + if (!out) { + perror(filename); + return; + } + fprintf(out, "\n"); + fprintf(out, "\n", files->duration * 10); + if (files->video_file >= 0) { + struct VideoFile *vf = files->files[files->video_file]; + int index = 0; + fprintf(out, "\t\n", + files->nb_video_files, vf->chunks); + for (i = 0; i < files->nb_files; i++) { + vf = files->files[i]; + if (!vf->is_video) + continue; + fprintf(out, "\t\tbitrate, vf->fourcc, vf->width, vf->height); + for (j = 0; j < vf->codec_private_size; j++) + fprintf(out, "%02X", vf->codec_private[j]); + fprintf(out, "\" />\n"); + index++; + } + vf = files->files[files->video_file]; + for (i = 0; i < vf->chunks; i++) + fprintf(out, "\t\t\n", i, + vf->offsets[i].duration); + fprintf(out, "\t\n"); + } + if (files->audio_file >= 0) { + struct VideoFile *vf = files->files[files->audio_file]; + int index = 0; + fprintf(out, "\t\n", + files->nb_audio_files, vf->chunks); + for (i = 0; i < files->nb_files; i++) { + vf = files->files[i]; + if (!vf->is_audio) + continue; + fprintf(out, "\t\tbitrate, vf->fourcc, vf->sample_rate, + vf->channels, vf->blocksize, vf->tag); + for (j = 0; j < vf->codec_private_size; j++) + fprintf(out, "%02X", vf->codec_private[j]); + fprintf(out, "\" />\n"); + index++; + } + vf = files->files[files->audio_file]; + for (i = 0; i < vf->chunks; i++) + fprintf(out, "\t\t\n", + i, vf->offsets[i].duration); + fprintf(out, "\t\n"); + } + fprintf(out, "\n"); + fclose(out); +} + +static void clean_files(struct VideoFiles *files) +{ + int i; + for (i = 0; i < files->nb_files; i++) { + av_freep(&files->files[i]->codec_private); + av_freep(&files->files[i]->offsets); + av_freep(&files->files[i]); + } + av_freep(&files->files); + files->nb_files = 0; +} + +int main(int argc, char **argv) +{ + const char *basename = NULL; + int split = 0, i; + struct VideoFiles vf = { 0, .video_file = -1, .audio_file = -1 }; + + av_register_all(); + + for (i = 1; i < argc; i++) { + if (!strcmp(argv[i], "-n")) { + basename = argv[i + 1]; + i++; + } else if (!strcmp(argv[i], "-split")) { + split = 1; + } else if (argv[i][0] == '-') { + return usage(argv[0], 1); + } else { + handle_file(&vf, argv[i], split); + } + } + if (!vf.nb_files || (!basename && !split)) + return usage(argv[0], 1); + + if (!split) + output_server_manifest(&vf, basename); + output_client_manifest(&vf, basename, split); + + clean_files(&vf); + + return 0; +} From abe655a4723290497fd727df61fab2840d84b643 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Thu, 19 Jan 2012 16:10:13 +0100 Subject: [PATCH 10/22] Drop unnecessary prefix from *sink* variable and struct names. --- avconv.c | 6 +++--- avplay.c | 6 +++--- cmdutils.c | 20 ++++++++++---------- cmdutils.h | 4 ++-- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/avconv.c b/avconv.c index 46f3090755..77d6648a53 100644 --- a/avconv.c +++ b/avconv.c @@ -550,7 +550,7 @@ static int configure_video_filters(InputStream *ist, OutputStream *ost) /** filter graph containing all filters including input & output */ AVCodecContext *codec = ost->st->codec; AVCodecContext *icodec = ist->st->codec; - AVSinkContext avsink_ctx = { .pix_fmt = codec->pix_fmt }; + SinkContext sink_ctx = { .pix_fmt = codec->pix_fmt }; AVRational sample_aspect_ratio; char args[255]; int ret; @@ -570,8 +570,8 @@ static int configure_video_filters(InputStream *ist, OutputStream *ost) "src", args, NULL, ost->graph); if (ret < 0) return ret; - ret = avfilter_graph_create_filter(&ost->output_video_filter, &avsink, - "out", NULL, &avsink_ctx, ost->graph); + ret = avfilter_graph_create_filter(&ost->output_video_filter, &sink, + "out", NULL, &sink_ctx, ost->graph); if (ret < 0) return ret; last_filter = ost->input_video_filter; diff --git a/avplay.c b/avplay.c index 27ac01ae33..19e2bdcc18 100644 --- a/avplay.c +++ b/avplay.c @@ -1706,7 +1706,7 @@ static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const c { char sws_flags_str[128]; int ret; - AVSinkContext avsink_ctx = { .pix_fmt = PIX_FMT_YUV420P }; + SinkContext sink_ctx = { .pix_fmt = PIX_FMT_YUV420P }; AVFilterContext *filt_src = NULL, *filt_out = NULL; snprintf(sws_flags_str, sizeof(sws_flags_str), "flags=%d", sws_flags); graph->scale_sws_opts = av_strdup(sws_flags_str); @@ -1714,8 +1714,8 @@ static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const c if ((ret = avfilter_graph_create_filter(&filt_src, &input_filter, "src", NULL, is, graph)) < 0) return ret; - if ((ret = avfilter_graph_create_filter(&filt_out, &avsink, "out", - NULL, &avsink_ctx, graph)) < 0) + if ((ret = avfilter_graph_create_filter(&filt_out, &sink, "out", + NULL, &sink_ctx, graph)) < 0) return ret; if (vfilters) { diff --git a/cmdutils.c b/cmdutils.c index a489a0f06e..0a87deedbb 100644 --- a/cmdutils.c +++ b/cmdutils.c @@ -1031,34 +1031,34 @@ AVDictionary **setup_find_stream_info_opts(AVFormatContext *s, #if CONFIG_AVFILTER -static int avsink_init(AVFilterContext *ctx, const char *args, void *opaque) +static int sink_init(AVFilterContext *ctx, const char *args, void *opaque) { - AVSinkContext *priv = ctx->priv; + SinkContext *priv = ctx->priv; if (!opaque) return AVERROR(EINVAL); - *priv = *(AVSinkContext *)opaque; + *priv = *(SinkContext *)opaque; return 0; } static void null_end_frame(AVFilterLink *inlink) { } -static int avsink_query_formats(AVFilterContext *ctx) +static int sink_query_formats(AVFilterContext *ctx) { - AVSinkContext *priv = ctx->priv; + SinkContext *priv = ctx->priv; enum PixelFormat pix_fmts[] = { priv->pix_fmt, PIX_FMT_NONE }; avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts)); return 0; } -AVFilter avsink = { - .name = "avsink", - .priv_size = sizeof(AVSinkContext), - .init = avsink_init, +AVFilter sink = { + .name = "sink", + .priv_size = sizeof(SinkContext), + .init = sink_init, - .query_formats = avsink_query_formats, + .query_formats = sink_query_formats, .inputs = (AVFilterPad[]) {{ .name = "default", .type = AVMEDIA_TYPE_VIDEO, diff --git a/cmdutils.h b/cmdutils.h index eb96645eed..37fd4d3b67 100644 --- a/cmdutils.h +++ b/cmdutils.h @@ -363,9 +363,9 @@ FILE *get_preset_file(char *filename, size_t filename_size, typedef struct { enum PixelFormat pix_fmt; -} AVSinkContext; +} SinkContext; -extern AVFilter avsink; +extern AVFilter sink; /** * Extract a frame from sink. From 33ad8c3cab30ebf8a08c891a5ec8cbcba15feabb Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Wed, 18 Jan 2012 18:47:59 +0100 Subject: [PATCH 11/22] cosmetics: Remove some unnecessary block braces. --- libavcodec/motion_est.c | 34 +++++++++++++++----------------- libavfilter/vf_hflip.c | 2 -- libswscale/ppc/swscale_altivec.c | 10 ---------- 3 files changed, 16 insertions(+), 30 deletions(-) diff --git a/libavcodec/motion_est.c b/libavcodec/motion_est.c index c4512a91dd..2aa89786a1 100644 --- a/libavcodec/motion_est.c +++ b/libavcodec/motion_est.c @@ -1290,28 +1290,26 @@ static int ff_estimate_motion_b(MpegEncContext * s, break; case ME_X1: case ME_EPZS: - { - P_LEFT[0] = mv_table[mot_xy - 1][0]; - P_LEFT[1] = mv_table[mot_xy - 1][1]; + P_LEFT[0] = mv_table[mot_xy - 1][0]; + P_LEFT[1] = mv_table[mot_xy - 1][1]; - if(P_LEFT[0] > (c->xmax<xmax< (c->xmax << shift)) P_LEFT[0] = (c->xmax << shift); - /* special case for first line */ - if (!s->first_slice_line) { - P_TOP[0] = mv_table[mot_xy - mot_stride ][0]; - P_TOP[1] = mv_table[mot_xy - mot_stride ][1]; - P_TOPRIGHT[0] = mv_table[mot_xy - mot_stride + 1 ][0]; - P_TOPRIGHT[1] = mv_table[mot_xy - mot_stride + 1 ][1]; - if(P_TOP[1] > (c->ymax<ymax<xmin<xmin< (c->ymax<ymax<first_slice_line) { + P_TOP[0] = mv_table[mot_xy - mot_stride ][0]; + P_TOP[1] = mv_table[mot_xy - mot_stride ][1]; + P_TOPRIGHT[0] = mv_table[mot_xy - mot_stride + 1][0]; + P_TOPRIGHT[1] = mv_table[mot_xy - mot_stride + 1][1]; + if (P_TOP[1] > (c->ymax << shift)) P_TOP[1] = (c->ymax << shift); + if (P_TOPRIGHT[0] < (c->xmin << shift)) P_TOPRIGHT[0] = (c->xmin << shift); + if (P_TOPRIGHT[1] > (c->ymax << shift)) P_TOPRIGHT[1] = (c->ymax << shift); - P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]); - P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]); - } - c->pred_x= P_LEFT[0]; - c->pred_y= P_LEFT[1]; + P_MEDIAN[0] = mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]); + P_MEDIAN[1] = mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]); } + c->pred_x = P_LEFT[0]; + c->pred_y = P_LEFT[1]; if(mv_table == s->b_forw_mv_table){ mv_scale= (s->pb_time<<16) / (s->pp_time<>vsub; i++) { switch (step) { case 1: - { for (j = 0; j < (inlink->w >> hsub); j++) outrow[j] = inrow[-j]; - } break; case 2: diff --git a/libswscale/ppc/swscale_altivec.c b/libswscale/ppc/swscale_altivec.c index 87059d9430..13c63e8acb 100644 --- a/libswscale/ppc/swscale_altivec.c +++ b/libswscale/ppc/swscale_altivec.c @@ -99,7 +99,6 @@ yuv2planeX_altivec(const int16_t *filter, int filterSize, const uint8_t *dither, int offset) { register int i, j; - { DECLARE_ALIGNED(16, int, val)[dstW]; for (i=0; i>7, (1<<15)-1); } - } break; case 8: - { for (i=0; i>7, (1<<15)-1); } - } break; case 16: - { for (i=0; i>7, (1<<15)-1); } - } break; default: - { for (i=0; i Date: Wed, 25 Jan 2012 13:47:47 +0200 Subject: [PATCH 12/22] pktdumper: Use usleep instead of sleep MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MinGW doesn't have sleep, only _sleep (which is deprecated), Sleep (which is defined in winbase.h and not in the standard C headers) and usleep. Signed-off-by: Martin Storsjö --- tools/pktdumper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/pktdumper.c b/tools/pktdumper.c index e9e5acfdec..54dd3f559f 100644 --- a/tools/pktdumper.c +++ b/tools/pktdumper.c @@ -120,7 +120,7 @@ int main(int argc, char **argv) avformat_close_input(&fctx); while (donotquit) - sleep(60); + usleep(60 * 1000000); return 0; } From 366ac22ea5a8bab63c7f46cdad2ddb2ff22cdbed Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Mon, 23 Jan 2012 21:33:34 +0100 Subject: [PATCH 13/22] indeo5: prevent null pointer dereference on broken files Found by John Villamil --- libavcodec/indeo5.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libavcodec/indeo5.c b/libavcodec/indeo5.c index 019fa2b8da..5263251f8d 100644 --- a/libavcodec/indeo5.c +++ b/libavcodec/indeo5.c @@ -453,6 +453,10 @@ static int decode_mb_info(IVI5DecContext *ctx, IVIBandDesc *band, ref_mb = tile->ref_mbs; offs = tile->ypos * band->pitch + tile->xpos; + if (!ref_mb && + ((band->qdelta_present && band->inherit_qdelta) || band->inherit_mv)) + return AVERROR_INVALIDDATA; + /* scale factor for motion vectors */ mv_scale = (ctx->planes[0].bands[0].mb_size >> 3) - (band->mb_size >> 3); mv_x = mv_y = 0; From 07a873a27775d6004536bff1186c26c6e52c2b50 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Wed, 25 Jan 2012 13:35:19 +0100 Subject: [PATCH 14/22] build: Automatically include architecture-specific library Makefile snippets. --- Makefile | 1 + libavcodec/Makefile | 2 -- libavfilter/Makefile | 2 -- 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Makefile b/Makefile index d1b55ba3d1..c9821b754e 100644 --- a/Makefile +++ b/Makefile @@ -112,6 +112,7 @@ define DOSUBDIR $(foreach V,$(SUBDIR_VARS),$(eval $(call RESET,$(V)))) SUBDIR := $(1)/ include $(SRC_PATH)/$(1)/Makefile +-include $(SRC_PATH)/$(1)/$(ARCH)/Makefile include $(SRC_PATH)/library.mak endef diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 620c99e980..fbb8112eea 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -670,8 +670,6 @@ OBJS-$(CONFIG_MLIB) += mlib/dsputil_mlib.o \ # well. OBJS-$(!CONFIG_SMALL) += inverse.o --include $(SRC_PATH)/$(SUBDIR)$(ARCH)/Makefile - SKIPHEADERS += %_tablegen.h \ %_tables.h \ aac_tablegen_decl.h \ diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 09865c148d..8af152da22 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -69,8 +69,6 @@ OBJS-$(CONFIG_TESTSRC_FILTER) += vsrc_testsrc.o OBJS-$(CONFIG_NULLSINK_FILTER) += vsink_nullsink.o --include $(SRC_PATH)/$(SUBDIR)$(ARCH)/Makefile - DIRS = x86 TOOLS = graph2dot lavfi-showfiltfmts From 50639cbefef8cc9f3df19241be7cf23cde8313b7 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Wed, 25 Jan 2012 14:56:24 +0100 Subject: [PATCH 15/22] Ignore generated aviocat and ismindex tools. --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 3508635b05..754051d79d 100644 --- a/.gitignore +++ b/.gitignore @@ -34,8 +34,10 @@ tests/tiny_psnr tests/videogen tests/vsynth1 tests/vsynth2 +tools/aviocat tools/cws2fws tools/graph2dot +tools/ismindex tools/lavfi-showfiltfmts tools/pktdumper tools/probetest From 4e81b5f517443c0e60df3f2c6ddc8cac96a34af8 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Wed, 25 Jan 2012 15:03:18 +0100 Subject: [PATCH 16/22] tools: K&R reformatting cosmetics --- tools/aviocat.c | 6 ++- tools/cws2fws.c | 56 ++++++++++------------ tools/graph2dot.c | 36 +++++++++------ tools/ismindex.c | 95 ++++++++++++++++++++------------------ tools/lavfi-showfiltfmts.c | 6 ++- tools/pktdumper.c | 24 ++++++---- tools/probetest.c | 28 ++++++----- tools/qt-faststart.c | 1 - tools/trasher.c | 39 ++++++++-------- 9 files changed, 158 insertions(+), 133 deletions(-) diff --git a/tools/aviocat.c b/tools/aviocat.c index 92483c345a..f5da526ba9 100644 --- a/tools/aviocat.c +++ b/tools/aviocat.c @@ -21,6 +21,7 @@ #include #include #include + #include "libavformat/avformat.h" static int usage(const char *argv0, int ret) @@ -80,13 +81,14 @@ int main(int argc, char **argv) stream_pos += n; if (bps) { avio_flush(output); - while ((av_gettime() - start_time)*bps/AV_TIME_BASE < stream_pos) - usleep(50*1000); + while ((av_gettime() - start_time) * bps / AV_TIME_BASE < stream_pos) + usleep(50 * 1000); } } avio_flush(output); avio_close(output); + fail: avio_close(input); avformat_network_deinit(); diff --git a/tools/cws2fws.c b/tools/cws2fws.c index 35fce35683..68f7953b56 100644 --- a/tools/cws2fws.c +++ b/tools/cws2fws.c @@ -26,46 +26,42 @@ int main(int argc, char *argv[]) z_stream zstream; struct stat statbuf; - if (argc < 3) - { + if (argc < 3) { printf("Usage: %s \n", argv[0]); return 1; } fd_in = open(argv[1], O_RDONLY); - if (fd_in < 0) - { + if (fd_in < 0) { perror("Error opening input file"); return 1; } - fd_out = open(argv[2], O_WRONLY|O_CREAT, 00644); - if (fd_out < 0) - { + fd_out = open(argv[2], O_WRONLY | O_CREAT, 00644); + if (fd_out < 0) { perror("Error opening output file"); close(fd_in); return 1; } - if (read(fd_in, &buf_in, 8) != 8) - { + if (read(fd_in, &buf_in, 8) != 8) { printf("Header error\n"); close(fd_in); close(fd_out); return 1; } - if (buf_in[0] != 'C' || buf_in[1] != 'W' || buf_in[2] != 'S') - { + if (buf_in[0] != 'C' || buf_in[1] != 'W' || buf_in[2] != 'S') { printf("Not a compressed flash file\n"); return 1; } fstat(fd_in, &statbuf); - comp_len = statbuf.st_size; + comp_len = statbuf.st_size; uncomp_len = buf_in[4] | (buf_in[5] << 8) | (buf_in[6] << 16) | (buf_in[7] << 24); - printf("Compressed size: %d Uncompressed size: %d\n", comp_len-4, uncomp_len-4); + printf("Compressed size: %d Uncompressed size: %d\n", + comp_len - 4, uncomp_len - 4); // write out modified header buf_in[0] = 'F'; @@ -75,36 +71,35 @@ int main(int argc, char *argv[]) } zstream.zalloc = NULL; - zstream.zfree = NULL; + zstream.zfree = NULL; zstream.opaque = NULL; inflateInit(&zstream); - for (i = 0; i < comp_len-8;) - { + for (i = 0; i < comp_len - 8;) { int ret, len = read(fd_in, &buf_in, 1024); dbgprintf("read %d bytes\n", len); last_out = zstream.total_out; - zstream.next_in = &buf_in[0]; - zstream.avail_in = len; - zstream.next_out = &buf_out[0]; + zstream.next_in = &buf_in[0]; + zstream.avail_in = len; + zstream.next_out = &buf_out[0]; zstream.avail_out = 65536; ret = inflate(&zstream, Z_SYNC_FLUSH); - if (ret != Z_STREAM_END && ret != Z_OK) - { + if (ret != Z_STREAM_END && ret != Z_OK) { printf("Error while decompressing: %d\n", ret); inflateEnd(&zstream); return 1; } dbgprintf("a_in: %d t_in: %lu a_out: %d t_out: %lu -- %lu out\n", - zstream.avail_in, zstream.total_in, zstream.avail_out, zstream.total_out, - zstream.total_out-last_out); + zstream.avail_in, zstream.total_in, zstream.avail_out, + zstream.total_out, zstream.total_out - last_out); - if (write(fd_out, &buf_out, zstream.total_out - last_out) < zstream.total_out - last_out) { + if (write(fd_out, &buf_out, zstream.total_out - last_out) < + zstream.total_out - last_out) { perror("Error writing output file"); return 1; } @@ -115,15 +110,14 @@ int main(int argc, char *argv[]) break; } - if (zstream.total_out != uncomp_len-8) - { + if (zstream.total_out != uncomp_len - 8) { printf("Size mismatch (%lu != %d), updating header...\n", - zstream.total_out, uncomp_len-8); + zstream.total_out, uncomp_len - 8); - buf_in[0] = (zstream.total_out+8) & 0xff; - buf_in[1] = ((zstream.total_out+8) >> 8) & 0xff; - buf_in[2] = ((zstream.total_out+8) >> 16) & 0xff; - buf_in[3] = ((zstream.total_out+8) >> 24) & 0xff; + buf_in[0] = (zstream.total_out + 8) & 0xff; + buf_in[1] = ((zstream.total_out + 8) >> 8) & 0xff; + buf_in[2] = ((zstream.total_out + 8) >> 16) & 0xff; + buf_in[3] = ((zstream.total_out + 8) >> 24) & 0xff; lseek(fd_out, 4, SEEK_SET); if (write(fd_out, &buf_in, 4) < 4) { diff --git a/tools/graph2dot.c b/tools/graph2dot.c index 5ec6e204f7..15a9012989 100644 --- a/tools/graph2dot.c +++ b/tools/graph2dot.c @@ -63,19 +63,25 @@ static void print_digraph(FILE *outfile, AVFilterGraph *graph) char dst_filter_ctx_label[128]; const AVFilterContext *dst_filter_ctx = link->dst; - snprintf(dst_filter_ctx_label, sizeof(dst_filter_ctx_label), "%s (%s)", + snprintf(dst_filter_ctx_label, sizeof(dst_filter_ctx_label), + "%s (%s)", dst_filter_ctx->name, dst_filter_ctx->filter->name); - fprintf(outfile, "\"%s\" -> \"%s\"", filter_ctx_label, dst_filter_ctx_label); + fprintf(outfile, "\"%s\" -> \"%s\"", + filter_ctx_label, dst_filter_ctx_label); if (link->type == AVMEDIA_TYPE_VIDEO) { - fprintf(outfile, " [ label= \"fmt:%s w:%d h:%d tb:%d/%d\" ]", + fprintf(outfile, + " [ label= \"fmt:%s w:%d h:%d tb:%d/%d\" ]", av_pix_fmt_descriptors[link->format].name, - link->w, link->h, link->time_base.num, link->time_base.den); + link->w, link->h, link->time_base.num, + link->time_base.den); } else if (link->type == AVMEDIA_TYPE_AUDIO) { char buf[255]; - av_get_channel_layout_string(buf, sizeof(buf), -1, link->channel_layout); - fprintf(outfile, " [ label= \"fmt:%s sr:%"PRId64" cl:%s\" ]", + av_get_channel_layout_string(buf, sizeof(buf), -1, + link->channel_layout); + fprintf(outfile, + " [ label= \"fmt:%s sr:%"PRId64 " cl:%s\" ]", av_get_sample_fmt_name(link->format), link->sample_rate, buf); } @@ -89,17 +95,17 @@ static void print_digraph(FILE *outfile, AVFilterGraph *graph) int main(int argc, char **argv) { const char *outfilename = NULL; - const char *infilename = NULL; - FILE *outfile = NULL; - FILE *infile = NULL; - char *graph_string = NULL; + const char *infilename = NULL; + FILE *outfile = NULL; + FILE *infile = NULL; + char *graph_string = NULL; AVFilterGraph *graph = av_mallocz(sizeof(AVFilterGraph)); char c; av_log_set_level(AV_LOG_DEBUG); while ((c = getopt(argc, argv, "hi:o:")) != -1) { - switch(c) { + switch (c) { case 'h': usage(); return 0; @@ -118,7 +124,8 @@ int main(int argc, char **argv) infilename = "/dev/stdin"; infile = fopen(infilename, "r"); if (!infile) { - fprintf(stderr, "Impossible to open input file '%s': %s\n", infilename, strerror(errno)); + fprintf(stderr, "Impossible to open input file '%s': %s\n", + infilename, strerror(errno)); return 1; } @@ -126,7 +133,8 @@ int main(int argc, char **argv) outfilename = "/dev/stdout"; outfile = fopen(outfilename, "w"); if (!outfile) { - fprintf(stderr, "Impossible to open output file '%s': %s\n", outfilename, strerror(errno)); + fprintf(stderr, "Impossible to open output file '%s': %s\n", + outfilename, strerror(errno)); return 1; } @@ -141,7 +149,7 @@ int main(int argc, char **argv) struct line *new_line = av_malloc(sizeof(struct line)); count += strlen(last_line->data); last_line->next = new_line; - last_line = new_line; + last_line = new_line; } last_line->next = NULL; diff --git a/tools/ismindex.c b/tools/ismindex.c index 4e14d1970f..59d1286c46 100644 --- a/tools/ismindex.c +++ b/tools/ismindex.c @@ -35,6 +35,7 @@ #include #include #include + #include "libavformat/avformat.h" #include "libavutil/intreadwrite.h" #include "libavutil/mathematics.h" @@ -82,7 +83,7 @@ static int copy_tag(AVIOContext *in, AVIOContext *out, int32_t tag_name) int32_t size, tag; size = avio_rb32(in); - tag = avio_rb32(in); + tag = avio_rb32(in); avio_wb32(out, size); avio_wb32(out, tag); if (tag != tag_name) @@ -123,7 +124,7 @@ static int write_fragments(struct VideoFiles *files, int start_index, for (i = start_index; i < files->nb_files; i++) { struct VideoFile *vf = files->files[i]; - const char *type = vf->is_video ? "video" : "audio"; + const char *type = vf->is_video ? "video" : "audio"; snprintf(dirname, sizeof(dirname), "QualityLevels(%d)", vf->bitrate); mkdir(dirname, 0777); for (j = 0; j < vf->chunks; j++) { @@ -140,7 +141,7 @@ static int read_tfra(struct VideoFiles *files, int start_index, AVIOContext *f) { int ret = AVERROR_EOF, track_id; int version, fieldlength, i, j; - int64_t pos = avio_tell(f); + int64_t pos = avio_tell(f); uint32_t size = avio_rb32(f); struct VideoFile *vf = NULL; @@ -149,17 +150,16 @@ static int read_tfra(struct VideoFiles *files, int start_index, AVIOContext *f) version = avio_r8(f); avio_rb24(f); track_id = avio_rb32(f); /* track id */ - for (i = start_index; i < files->nb_files && !vf; i++) { + for (i = start_index; i < files->nb_files && !vf; i++) if (files->files[i]->track_id == track_id) vf = files->files[i]; - } if (!vf) { /* Ok, continue parsing the next atom */ ret = 0; goto fail; } fieldlength = avio_rb32(f); - vf->chunks = avio_rb32(f); + vf->chunks = avio_rb32(f); vf->offsets = av_mallocz(sizeof(*vf->offsets) * vf->chunks); if (!vf->offsets) { ret = AVERROR(ENOMEM); @@ -167,10 +167,10 @@ static int read_tfra(struct VideoFiles *files, int start_index, AVIOContext *f) } for (i = 0; i < vf->chunks; i++) { if (version == 1) { - vf->offsets[i].time = avio_rb64(f); + vf->offsets[i].time = avio_rb64(f); vf->offsets[i].offset = avio_rb64(f); } else { - vf->offsets[i].time = avio_rb32(f); + vf->offsets[i].time = avio_rb32(f); vf->offsets[i].offset = avio_rb32(f); } for (j = 0; j < ((fieldlength >> 4) & 3) + 1; j++) @@ -187,6 +187,7 @@ static int read_tfra(struct VideoFiles *files, int start_index, AVIOContext *f) vf->offsets[vf->chunks - 1].duration = vf->duration - vf->offsets[vf->chunks - 1].time; ret = 0; + fail: avio_seek(f, pos + size, SEEK_SET); return ret; @@ -224,7 +225,7 @@ fail: static int get_private_data(struct VideoFile *vf, AVCodecContext *codec) { vf->codec_private_size = codec->extradata_size; - vf->codec_private = av_mallocz(codec->extradata_size); + vf->codec_private = av_mallocz(codec->extradata_size); if (!vf->codec_private) return AVERROR(ENOMEM); memcpy(vf->codec_private, codec->extradata, codec->extradata_size); @@ -254,6 +255,7 @@ static int get_video_private_data(struct VideoFile *vf, AVCodecContext *codec) avio_wb32(io, 0x00000001); avio_write(io, &codec->extradata[11 + sps_size], pps_size); err = 0; + fail: vf->codec_private_size = avio_close_dyn_buf(io, &vf->codec_private); return err; @@ -291,24 +293,25 @@ static int handle_file(struct VideoFiles *files, const char *file, int split) AVStream *st = ctx->streams[i]; vf = av_mallocz(sizeof(*vf)); files->files = av_realloc(files->files, - sizeof(*files->files)*(files->nb_files + 1)); + sizeof(*files->files) * (files->nb_files + 1)); files->files[files->nb_files] = vf; vf->name = file; if ((ptr = strrchr(file, '/')) != NULL) vf->name = ptr + 1; - vf->bitrate = st->codec->bit_rate; - vf->track_id = st->id; + vf->bitrate = st->codec->bit_rate; + vf->track_id = st->id; vf->timescale = st->time_base.den; - vf->duration = av_rescale_rnd(ctx->duration, vf->timescale, - AV_TIME_BASE, AV_ROUND_UP); - vf->is_audio = st->codec->codec_type == AVMEDIA_TYPE_AUDIO; - vf->is_video = st->codec->codec_type == AVMEDIA_TYPE_VIDEO; + vf->duration = av_rescale_rnd(ctx->duration, vf->timescale, + AV_TIME_BASE, AV_ROUND_UP); + vf->is_audio = st->codec->codec_type == AVMEDIA_TYPE_AUDIO; + vf->is_video = st->codec->codec_type == AVMEDIA_TYPE_VIDEO; if (!vf->is_audio && !vf->is_video) { - fprintf(stderr, "Track %d in %s is neither video nor audio, " - "skipping\n", vf->track_id, file); + fprintf(stderr, + "Track %d in %s is neither video nor audio, skipping\n", + vf->track_id, file); av_freep(&files->files[files->nb_files]); continue; } @@ -317,15 +320,15 @@ static int handle_file(struct VideoFiles *files, const char *file, int split) if (files->audio_file < 0) files->audio_file = files->nb_files; files->nb_audio_files++; - vf->channels = st->codec->channels; + vf->channels = st->codec->channels; vf->sample_rate = st->codec->sample_rate; if (st->codec->codec_id == CODEC_ID_AAC) { - vf->fourcc = "AACL"; - vf->tag = 255; + vf->fourcc = "AACL"; + vf->tag = 255; vf->blocksize = 4; } else if (st->codec->codec_id == CODEC_ID_WMAPRO) { - vf->fourcc = "WMAP"; - vf->tag = st->codec->codec_tag; + vf->fourcc = "WMAP"; + vf->tag = st->codec->codec_tag; vf->blocksize = st->codec->block_align; } get_private_data(vf, st->codec); @@ -334,7 +337,7 @@ static int handle_file(struct VideoFiles *files, const char *file, int split) if (files->video_file < 0) files->video_file = files->nb_files; files->nb_video_files++; - vf->width = st->codec->width; + vf->width = st->codec->width; vf->height = st->codec->height; if (st->codec->codec_id == CODEC_ID_H264) vf->fourcc = "H264"; @@ -379,7 +382,7 @@ static void output_server_manifest(struct VideoFiles *files, fprintf(out, "\t\t\n"); for (i = 0; i < files->nb_files; i++) { struct VideoFile *vf = files->files[i]; - const char *type = vf->is_video ? "video" : "audio"; + const char *type = vf->is_video ? "video" : "audio"; fprintf(out, "\t\t\t<%s src=\"%s\" systemBitrate=\"%d\">\n", type, vf->name, vf->bitrate); fprintf(out, "\t\t\t\t\n"); fprintf(out, "\n", files->duration * 10); + "Duration=\"%"PRId64 "\">\n", files->duration * 10); if (files->video_file >= 0) { struct VideoFile *vf = files->files[files->video_file]; int index = 0; - fprintf(out, "\t\n", - files->nb_video_files, vf->chunks); + fprintf(out, + "\t\n", + files->nb_video_files, vf->chunks); for (i = 0; i < files->nb_files; i++) { vf = files->files[i]; if (!vf->is_video) continue; - fprintf(out, "\t\tbitrate, vf->fourcc, vf->width, vf->height); + fprintf(out, + "\t\tbitrate, vf->fourcc, vf->width, vf->height); for (j = 0; j < vf->codec_private_size; j++) fprintf(out, "%02X", vf->codec_private[j]); fprintf(out, "\" />\n"); @@ -440,20 +445,22 @@ static void output_client_manifest(struct VideoFiles *files, if (files->audio_file >= 0) { struct VideoFile *vf = files->files[files->audio_file]; int index = 0; - fprintf(out, "\t\n", - files->nb_audio_files, vf->chunks); + fprintf(out, + "\t\n", + files->nb_audio_files, vf->chunks); for (i = 0; i < files->nb_files; i++) { vf = files->files[i]; if (!vf->is_audio) continue; - fprintf(out, "\t\tbitrate, vf->fourcc, vf->sample_rate, - vf->channels, vf->blocksize, vf->tag); + fprintf(out, + "\t\tbitrate, vf->fourcc, vf->sample_rate, + vf->channels, vf->blocksize, vf->tag); for (j = 0; j < vf->codec_private_size; j++) fprintf(out, "%02X", vf->codec_private[j]); fprintf(out, "\" />\n"); diff --git a/tools/lavfi-showfiltfmts.c b/tools/lavfi-showfiltfmts.c index 30d472559c..a75a3cb49b 100644 --- a/tools/lavfi-showfiltfmts.c +++ b/tools/lavfi-showfiltfmts.c @@ -50,11 +50,13 @@ int main(int argc, char **argv) } if (avfilter_open(&filter_ctx, filter, NULL) < 0) { - fprintf(stderr, "Inpossible to open filter with name '%s'\n", filter_name); + fprintf(stderr, "Inpossible to open filter with name '%s'\n", + filter_name); return 1; } if (avfilter_init_filter(filter_ctx, filter_args, NULL) < 0) { - fprintf(stderr, "Impossible to init filter '%s' with arguments '%s'\n", filter_name, filter_args); + fprintf(stderr, "Impossible to init filter '%s' with arguments '%s'\n", + filter_name, filter_args); return 1; } diff --git a/tools/pktdumper.c b/tools/pktdumper.c index 54dd3f559f..bfccd7c769 100644 --- a/tools/pktdumper.c +++ b/tools/pktdumper.c @@ -24,9 +24,10 @@ #include #include #include + #include "libavformat/avformat.h" -#define PKTFILESUFF "_%08"PRId64"_%02d_%010"PRId64"_%06d_%c.bin" +#define PKTFILESUFF "_%08" PRId64 "_%02d_%010" PRId64 "_%06d_%c.bin" #undef strcat @@ -46,10 +47,10 @@ int main(int argc, char **argv) char pktfilename[PATH_MAX]; AVFormatContext *fctx = NULL; AVPacket pkt; - int64_t pktnum = 0; + int64_t pktnum = 0; int64_t maxpkts = 0; - int donotquit = 0; - int nowrite = 0; + int donotquit = 0; + int nowrite = 0; int err; if ((argc > 1) && !strncmp(argv[1], "-", 1)) { @@ -64,16 +65,16 @@ int main(int argc, char **argv) return usage(1); if (argc > 2) maxpkts = atoi(argv[2]); - strncpy(fntemplate, argv[1], PATH_MAX-1); + strncpy(fntemplate, argv[1], PATH_MAX - 1); if (strrchr(argv[1], '/')) - strncpy(fntemplate, strrchr(argv[1], '/')+1, PATH_MAX-1); + strncpy(fntemplate, strrchr(argv[1], '/') + 1, PATH_MAX - 1); if (strrchr(fntemplate, '.')) *strrchr(fntemplate, '.') = '\0'; if (strchr(fntemplate, '%')) { fprintf(stderr, "can't use filenames containing '%%'\n"); return usage(1); } - if (strlen(fntemplate) + sizeof(PKTFILESUFF) >= PATH_MAX-1) { + if (strlen(fntemplate) + sizeof(PKTFILESUFF) >= PATH_MAX - 1) { fprintf(stderr, "filename too long\n"); return usage(1); } @@ -99,11 +100,14 @@ int main(int argc, char **argv) while ((err = av_read_frame(fctx, &pkt)) >= 0) { int fd; - snprintf(pktfilename, PATH_MAX-1, fntemplate, pktnum, pkt.stream_index, pkt.pts, pkt.size, (pkt.flags & AV_PKT_FLAG_KEY)?'K':'_'); - printf(PKTFILESUFF"\n", pktnum, pkt.stream_index, pkt.pts, pkt.size, (pkt.flags & AV_PKT_FLAG_KEY)?'K':'_'); + snprintf(pktfilename, PATH_MAX - 1, fntemplate, pktnum, + pkt.stream_index, pkt.pts, pkt.size, + (pkt.flags & AV_PKT_FLAG_KEY) ? 'K' : '_'); + printf(PKTFILESUFF "\n", pktnum, pkt.stream_index, pkt.pts, pkt.size, + (pkt.flags & AV_PKT_FLAG_KEY) ? 'K' : '_'); //printf("open(\"%s\")\n", pktfilename); if (!nowrite) { - fd = open(pktfilename, O_WRONLY|O_CREAT, 0644); + fd = open(pktfilename, O_WRONLY | O_CREAT, 0644); err = write(fd, pkt.data, pkt.size); if (err < 0) { fprintf(stderr, "write: error %d\n", err); diff --git a/tools/probetest.c b/tools/probetest.c index 7f8d54e973..678f4dd3a7 100644 --- a/tools/probetest.c +++ b/tools/probetest.c @@ -39,7 +39,8 @@ static void probe(AVProbeData *pd, int type, int p, int size) int score = fmt->read_probe(pd); if (score > score_array[i] && score > AVPROBE_SCORE_MAX / 4) { score_array[i] = score; - fprintf(stderr, "Failure of %s probing code with score=%d type=%d p=%X size=%d\n", + fprintf(stderr, + "Failure of %s probing code with score=%d type=%d p=%X size=%d\n", fmt->name, score, type, p, size); failures++; } @@ -75,9 +76,8 @@ int main(void) init_put_bits(&pb, pd.buf, size); switch (type) { case 0: - for (i = 0; i < size * 8; i++) { + for (i = 0; i < size * 8; i++) put_bits(&pb, 1, (av_lfg_get(&state) & 0xFFFFFFFF) > p << 20); - } break; case 1: for (i = 0; i < size * 8; i++) { @@ -89,10 +89,10 @@ int main(void) break; case 2: for (i = 0; i < size * 8; i++) { - unsigned int p2 = (p >> (hist*3)) & 7; + unsigned int p2 = (p >> (hist * 3)) & 7; unsigned int v = (av_lfg_get(&state) & 0xFFFFFFFF) > p2 << 29; put_bits(&pb, 1, v); - hist = (2*hist + v) & 3; + hist = (2 * hist + v) & 3; } break; case 3: @@ -100,12 +100,18 @@ int main(void) int c = 0; while (p & 63) { c = (av_lfg_get(&state) & 0xFFFFFFFF) >> 24; - if (c >= 'a' && c <= 'z' && (p & 1)) break; - else if(c >= 'A' && c <= 'Z' && (p & 2)) break; - else if(c >= '0' && c <= '9' && (p & 4)) break; - else if(c == ' ' && (p & 8)) break; - else if(c == 0 && (p & 16)) break; - else if(c == 1 && (p & 32)) break; + if (c >= 'a' && c <= 'z' && (p & 1)) + break; + else if (c >= 'A' && c <= 'Z' && (p & 2)) + break; + else if (c >= '0' && c <= '9' && (p & 4)) + break; + else if (c == ' ' && (p & 8)) + break; + else if (c == 0 && (p & 16)) + break; + else if (c == 1 && (p & 32)) + break; } pd.buf[i] = c; } diff --git a/tools/qt-faststart.c b/tools/qt-faststart.c index 71fe845565..8d2196c683 100644 --- a/tools/qt-faststart.c +++ b/tools/qt-faststart.c @@ -138,7 +138,6 @@ int main(int argc, char *argv[]) } start_offset = ftello(infile); } else { - /* 64-bit special case */ if (atom_size == 1) { if (fread(atom_bytes, ATOM_PREAMBLE_SIZE, 1, infile) != 1) { diff --git a/tools/trasher.c b/tools/trasher.c index e099aa30d6..11605b8a8e 100644 --- a/tools/trasher.c +++ b/tools/trasher.c @@ -23,47 +23,50 @@ #include static uint32_t state; -static uint32_t ran(void){ - return state= state*1664525+1013904223; +static uint32_t ran(void) +{ + return state = state * 1664525 + 1013904223; } -int main(int argc, char** argv) +int main(int argc, char **argv) { FILE *f; int count, maxburst, length; - if (argc < 5){ + if (argc < 5) { printf("USAGE: trasher \n"); return 1; } - f= fopen(argv[1], "rb+"); - if (!f){ + f = fopen(argv[1], "rb+"); + if (!f) { perror(argv[1]); return 2; } - count= atoi(argv[2]); - maxburst= atoi(argv[3]); - state= atoi(argv[4]); + count = atoi(argv[2]); + maxburst = atoi(argv[3]); + state = atoi(argv[4]); fseek(f, 0, SEEK_END); - length= ftell(f); + length = ftell(f); fseek(f, 0, SEEK_SET); - while(count--){ - int burst= 1 + ran() * (uint64_t) (abs(maxburst)-1) / UINT32_MAX; - int pos= ran() * (uint64_t) length / UINT32_MAX; + while (count--) { + int burst = 1 + ran() * (uint64_t) (abs(maxburst) - 1) / UINT32_MAX; + int pos = ran() * (uint64_t) length / UINT32_MAX; fseek(f, pos, SEEK_SET); - if(maxburst<0) burst= -maxburst; + if (maxburst < 0) + burst = -maxburst; - if(pos + burst > length) + if (pos + burst > length) continue; - while(burst--){ - int val= ran() * 256ULL / UINT32_MAX; + while (burst--) { + int val = ran() * 256ULL / UINT32_MAX; - if(maxburst<0) val=0; + if (maxburst < 0) + val = 0; fwrite(&val, 1, 1, f); } From c3e10ae4127c998b809066926a410f40ebd47593 Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Tue, 24 Jan 2012 21:50:50 +0100 Subject: [PATCH 17/22] rv20: prevent calling ff_h263_decode_mba() with unset height/width Prevents a crash of VLC during playback of a invalid matroska file, found by John Villamil . CC: libav-stable@libav.org --- libavcodec/rv10.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c index 9f2fe77af7..1d7fd6b468 100644 --- a/libavcodec/rv10.c +++ b/libavcodec/rv10.c @@ -362,7 +362,8 @@ static int rv20_decode_picture_header(MpegEncContext *s) if(s->avctx->debug & FF_DEBUG_PICT_INFO){ av_log(s->avctx, AV_LOG_DEBUG, "F %d/%d\n", f, rpr_bits); } - } + } else if (av_image_check_size(s->width, s->height, 0, s->avctx) < 0) + return AVERROR_INVALIDDATA; mb_pos = ff_h263_decode_mba(s); From d55fa1cb25244eab9f919d6e04f1e9b3faf7b7c9 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Wed, 25 Jan 2012 20:11:32 +0100 Subject: [PATCH 18/22] tools: Remove some unnecessary #undefs. --- tools/graph2dot.c | 1 - tools/pktdumper.c | 2 -- 2 files changed, 3 deletions(-) diff --git a/tools/graph2dot.c b/tools/graph2dot.c index 15a9012989..a52416db31 100644 --- a/tools/graph2dot.c +++ b/tools/graph2dot.c @@ -20,7 +20,6 @@ #include /* getopt */ -#undef HAVE_AV_CONFIG_H #include "libavutil/pixdesc.h" #include "libavutil/audioconvert.h" #include "libavfilter/avfiltergraph.h" diff --git a/tools/pktdumper.c b/tools/pktdumper.c index bfccd7c769..c3a3a218ef 100644 --- a/tools/pktdumper.c +++ b/tools/pktdumper.c @@ -29,8 +29,6 @@ #define PKTFILESUFF "_%08" PRId64 "_%02d_%010" PRId64 "_%06d_%c.bin" -#undef strcat - static int usage(int ret) { fprintf(stderr, "dump (up to maxpkts) AVPackets as they are demuxed by libavformat.\n"); From 990a746cec2fb82ca76b3a6fc28b35006e8d39bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Wed, 25 Jan 2012 12:40:05 +0200 Subject: [PATCH 19/22] movenc: Reindent a block MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also add some space around operators and wrap a comment that extends past the 80 char "limit"/guideline. Signed-off-by: Martin Storsjö --- libavformat/movenc.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 95d92aa71c..5e8bed2001 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -2863,20 +2863,22 @@ static int mov_write_trailer(AVFormatContext *s) int64_t moov_pos = avio_tell(pb); if (!(mov->flags & FF_MOV_FLAG_FRAGMENT)) { - /* Write size of mdat tag */ - if (mov->mdat_size+8 <= UINT32_MAX) { - avio_seek(pb, mov->mdat_pos, SEEK_SET); - avio_wb32(pb, mov->mdat_size+8); - } else { - /* overwrite 'wide' placeholder atom */ - 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); - } - avio_seek(pb, moov_pos, SEEK_SET); + /* Write size of mdat tag */ + if (mov->mdat_size + 8 <= UINT32_MAX) { + avio_seek(pb, mov->mdat_pos, SEEK_SET); + avio_wb32(pb, mov->mdat_size + 8); + } else { + /* overwrite 'wide' placeholder atom */ + avio_seek(pb, mov->mdat_pos - 8, SEEK_SET); + /* special value: real atom size will be 64 bit value after + * tag field */ + avio_wb32(pb, 1); + ffio_wfourcc(pb, "mdat"); + avio_wb64(pb, mov->mdat_size + 16); + } + avio_seek(pb, moov_pos, SEEK_SET); - mov_write_moov_tag(pb, mov, s); + mov_write_moov_tag(pb, mov, s); } else { mov_flush_fragment(s); mov_write_mfra_tag(pb, mov); From 6cb288290dcc66a405e0c226b26f31a7d248b7cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Wed, 25 Jan 2012 12:43:19 +0200 Subject: [PATCH 20/22] doc: Update APIchanges with info on muxer flushing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- doc/APIchanges | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/APIchanges b/doc/APIchanges index 904e3462f7..aa5729196e 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -13,6 +13,12 @@ libavutil: 2011-04-18 API changes, most recent first: +2012-01-25 - lavf 53.22.0 + f1caf01 Allow doing av_write_frame(ctx, NULL) for flushing possible + buffered data within a muxer. Added AVFMT_ALLOW_FLUSH for + muxers supporting it (av_write_frame makes sure it is called + only for muxers with this flag). + 2012-01-15 - lavc 53.34.0 New audio encoding API: b2c75b6 Add CODEC_CAP_VARIABLE_FRAME_SIZE capability for use by audio From 9f9c45f4b635457543a3bc37b09a679daa9dabea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Mon, 23 Jan 2012 14:56:56 +0200 Subject: [PATCH 21/22] movenc: Don't require frame_size to be set for modes other than mov MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The field frame_size isn't written to the output anywhere except than in mov. This facilitates stream copy from formats that don't set frame_size. Signed-off-by: Martin Storsjö --- libavformat/movenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 5e8bed2001..48b474bfc6 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -2757,7 +2757,7 @@ static int mov_write_header(AVFormatContext *s) } /* set audio_vbr for compressed audio */ if (av_get_bits_per_sample(st->codec->codec_id) < 8) { - if (!st->codec->frame_size) { + if (!st->codec->frame_size && track->mode == MODE_MOV) { av_log(s, AV_LOG_ERROR, "track %d: codec frame size is not set\n", i); goto error; } From d78bb1a4b2a3a415b68e4e6dd448779eccec64e3 Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Tue, 24 Jan 2012 18:43:43 -0800 Subject: [PATCH 22/22] wma: Clip WMA1 and WMA2 frame length to 11 bits. The MDCT buffers in the decoder are only sized for up to 11 bits. The reverse engineered documentation for WMA1/2 headers say that that for all samplerates above 32kHz 11 bits are used. 12 and 13 bit support were added for WMAPro. I was unable to make any Microsoft tools generate a test file at a samplerate above 48kHz. Discovered by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind CC: libav-stable@libav.org --- libavcodec/wma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/wma.c b/libavcodec/wma.c index 4cdffcd101..d82fde7b18 100644 --- a/libavcodec/wma.c +++ b/libavcodec/wma.c @@ -85,7 +85,7 @@ int av_cold ff_wma_get_frame_len_bits(int sample_rate, int version, } else if (sample_rate <= 22050 || (sample_rate <= 32000 && version == 1)) { frame_len_bits = 10; - } else if (sample_rate <= 48000) { + } else if (sample_rate <= 48000 || version < 3) { frame_len_bits = 11; } else if (sample_rate <= 96000) { frame_len_bits = 12;