~medibuntu-maintainers/mplayer/medibuntu.precise

« back to all changes in this revision

Viewing changes to ffmpeg/libavformat/movenc.c

  • Committer: Gauvain Pocentek
  • Date: 2012-03-06 11:59:12 UTC
  • mfrom: (66.1.15 precise)
  • Revision ID: gauvain@pocentek.net-20120306115912-h9d6kt9j0l532oo5
* Merge from Ubuntu:
  - put back faac support
  - recommends apport-hooks-medibuntu
  - change Maintainer, Uploaders & Vcs-* fields.
* New upstream snapshot
* upload to unstable
* Build against external libmpeg2
* drop 51_FTBFS_arm.patch again
* no longer build depend on libcdparanoia-dev on the Hurd
* Fix FTBFS on the hurd.
  Thanks to Samuel Thibault <sthibault@debian.org> (Closes: #654974)
* Fix FTBFS on arm
* New upstream snapshot, Closes: #650339, #643621, #481807
* Imported Upstream version 1.0~rc4+svn34492
* Bump standards version
* Bump dependency on libav >= 4:0.8~, Closes: #653887
* Fix build-indep
* Build mplayer-gui again, Closes: #568514
* Drop debian/all-lang-config-mak.sh, no longer needed
* include .dfsg1 in version number
* remove get-orig-source target
* no longer prune compiler flags from the environment
* No longer advertise nor build 3fdx, mga and dxr3 backends,
  Closes: #496106, #442181, #533546
* beautify mplayer version identification string
* Brown paperbag upload.
* Next try to fix build failure on sparce after recent binutils change.
* Brown paperbag upload.
* Really fix build failure on sparc after recent binutils change.
* Properly set Replaces/Conflicts on mplayer2{,-dbg} to avoid
  file overwrite errors.
* Adjust versioning of mplayer listed in the mplayer-dbg's Depends field.
* Fix build failure on sparc after recent binutils change.
* Urgency medium bumped because of RC-level bugfix
  and speeding up x264 transition.
* Update to my @debian.org email.
* Upload to unstable
* Enable joystick support on Linux only, Closes: #638408
* Rebuild fixes toolchain issue on arm, Closes: #637077
* New upstream snapshot
* following the discussion started by Diego Biurrun <diego@biurrun.de>
  in debian-devel, I have prepared a new packaging of 'mplayer'
  (with code that comes from CVS)
* the upstream tar.bz cannot be distributed by Debian, since it contains
   CSS code; so I am repackaging it 
* I have tried my best to address all known issues:
  - the package contains the detailed Copyright made by Diego Biurrun 
  - the package does not contain CSS code, or  AFAIK other code on which 
     there is active patent enforcement
  - there is a script  debian/cvs-changelog.sh  that shows all changes
     done to files included in this source.
    This should comply with GPLv2 sec 2.a  (in spirit if not in letter)
    For this reason, the source code contains CVS directories.
* needs   make (>= 3.80) for 'html-chunked-$(1)' in DOCS/xml/Makefile

* some corrections, as suggested Diego Biurrun
  - binary codecs should go into /usr/lib/codecs (upstream default)
  - better template 'mplayer/install_codecs'
  - an empty 'font=' in mplayer.conf breaks mplayer: postinst corrected
* correction in 'mplayer/cfgnote'
* better mplayer.postinst and mplayer.config

* New upstream release
* better debian/copyright file
* do not ship a skin
* New upstream release
* changed DEB_BUILD_OPTIONS to DEB_BUILD_CONFIGURE ,
  DEB_BUILD_OPTIONS is used as in debian policy
* use gcc-3.4
* changed xlibs-dev to a long list of dependencies, for Debian/etch
* try to adhere to  http://www.mplayerhq.hu/DOCS/tech/binary-packaging.txt
  (see README.Debian for details)
* removed dependency on xlibmesa-dev, disabled opengl
* New upstream release
* Simon McVittie <hacks@pseudorandom.co.uk> wonderful work:
- Work around Debian bug #267442 (glibc's sys/uio.h and gcc's altivec.h have
  conflicting uses for __vector) by re-ordering #includes
- Fix potential symlink attack in ./configure
- Disable support for binary codecs on platforms for which those codecs
  aren't available; also disable the corresponding Debconf note when it's
  inappropriate
- Changed Build-Depends: so it works in pbuilder
- Explicitly build-depend on libjpeg62-dev, libfontconfig1-dev,
  libungif4-dev 
- Tweak debian/rules to avoid certain errors being ignored
- Use --language=all
* provide a target  'debian/rules get-orig-source' 
  that recreates the orig.tar.gz ; then use the above orig.tar.gz
* rewrote some parts of debian/rules
* don't clean and recompile docs if upstream ships them
* mplayer-doc was shipping too much stuff
* translated man pages where not installed properly
* compile with libdv4-dev
* correct README.Debian
* Forgot build-dep on libtheora
* Must not depend on libxvidcore
* New upstream release
* new release.
* rc1 to become 0.90
* new pre-release
* new pre-release
* gtk bug fixed.
* new release.
* version bumped
* 0.60 pre2 release
* 0.60 pre-release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include "libavcodec/put_bits.h"
33
33
#include "internal.h"
34
34
#include "libavutil/avstring.h"
 
35
#include "libavutil/intfloat.h"
 
36
#include "libavutil/mathematics.h"
35
37
#include "libavutil/opt.h"
36
38
#include "libavutil/dict.h"
37
39
#include "rtpenc.h"
 
40
#include "mov_chan.h"
38
41
 
39
42
#undef NDEBUG
40
43
#include <assert.h>
41
44
 
42
45
static const AVOption options[] = {
43
 
    { "movflags", "MOV muxer flags", offsetof(MOVMuxContext, flags), FF_OPT_TYPE_FLAGS, {.dbl = 0}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
44
 
    { "rtphint", "Add RTP hint tracks", 0, FF_OPT_TYPE_CONST, {.dbl = FF_MOV_FLAG_RTP_HINT}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
 
46
    { "movflags", "MOV muxer flags", offsetof(MOVMuxContext, flags), AV_OPT_TYPE_FLAGS, {.dbl = 0}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
 
47
    { "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" },
45
48
    FF_RTP_FLAG_OPTS(MOVMuxContext, rtp_flags),
 
49
    { "skip_iods", "Skip writing iods atom.", offsetof(MOVMuxContext, iods_skip), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
 
50
    { "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},
 
51
    { "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},
46
52
    { NULL },
47
53
};
48
54
 
49
 
static const AVClass mov_muxer_class = {
50
 
    .class_name = "MOV/3GP/MP4/3G2 muxer",
51
 
    .item_name  = av_default_item_name,
52
 
    .option     = options,
53
 
    .version    = LIBAVUTIL_VERSION_INT,
 
55
#define MOV_CLASS(flavor)\
 
56
static const AVClass flavor ## _muxer_class = {\
 
57
    .class_name = #flavor " muxer",\
 
58
    .item_name  = av_default_item_name,\
 
59
    .option     = options,\
 
60
    .version    = LIBAVUTIL_VERSION_INT,\
54
61
};
55
62
 
56
63
//FIXME support 64 bit variant with wide placeholders
206
213
    avio_wb32(pb, 11);
207
214
    ffio_wfourcc(pb, "dac3");
208
215
 
209
 
    init_get_bits(&gbc, track->vosData+4, track->vosLen-4);
 
216
    init_get_bits(&gbc, track->vosData+4, (track->vosLen-4) * 8);
210
217
    fscod      = get_bits(&gbc, 2);
211
218
    frmsizecod = get_bits(&gbc, 6);
212
219
    bsid       = get_bits(&gbc, 5);
239
246
 
240
247
/**
241
248
 * This function writes extradata "as is".
242
 
 * Extradata must be formated like a valid atom (with size and tag)
 
249
 * Extradata must be formatted like a valid atom (with size and tag).
243
250
 */
244
251
static int mov_write_extradata_tag(AVIOContext *pb, MOVTrack *track)
245
252
{
335
342
    return updateSize(pb, pos);
336
343
}
337
344
 
 
345
static int mov_write_chan_tag(AVIOContext *pb, MOVTrack *track)
 
346
{
 
347
    uint32_t layout_tag, bitmap;
 
348
    int64_t pos = avio_tell(pb);
 
349
 
 
350
    layout_tag = ff_mov_get_channel_layout_tag(track->enc->codec_id,
 
351
                                               track->enc->channel_layout,
 
352
                                               &bitmap);
 
353
    if (!layout_tag) {
 
354
        av_log(track->enc, AV_LOG_WARNING, "not writing 'chan' tag due to "
 
355
               "lack of channel information\n");
 
356
        return 0;
 
357
    }
 
358
 
 
359
    avio_wb32(pb, 0);           // Size
 
360
    ffio_wfourcc(pb, "chan");   // Type
 
361
    avio_w8(pb, 0);             // Version
 
362
    avio_wb24(pb, 0);           // Flags
 
363
    avio_wb32(pb, layout_tag);  // mChannelLayoutTag
 
364
    avio_wb32(pb, bitmap);      // mChannelBitmap
 
365
    avio_wb32(pb, 0);           // mNumberChannelDescriptions
 
366
 
 
367
    return updateSize(pb, pos);
 
368
}
 
369
 
338
370
static int mov_write_wave_tag(AVIOContext *pb, MOVTrack *track)
339
371
{
340
372
    int64_t pos = avio_tell(pb);
357
389
    } else if (track->enc->codec_id == CODEC_ID_AMR_NB) {
358
390
        mov_write_amr_tag(pb, track);
359
391
    } else if (track->enc->codec_id == CODEC_ID_AC3) {
 
392
        mov_write_chan_tag(pb, track);
360
393
        mov_write_ac3_tag(pb, track);
361
394
    } else if (track->enc->codec_id == CODEC_ID_ALAC) {
362
395
        mov_write_extradata_tag(pb, track);
415
448
    uint32_t tag = track->tag;
416
449
 
417
450
    if (track->mode == MODE_MOV) {
418
 
        if (track->timescale > UINT16_MAX) {
419
 
            if (mov_get_lpcm_flags(track->enc->codec_id))
420
 
                tag = AV_RL32("lpcm");
421
 
            version = 2;
422
 
        } else if (track->audio_vbr || mov_pcm_le_gt16(track->enc->codec_id) ||
423
 
                   track->enc->codec_id == CODEC_ID_ADPCM_MS ||
424
 
                   track->enc->codec_id == CODEC_ID_ADPCM_IMA_WAV) {
425
 
            version = 1;
426
 
        }
 
451
        if (mov_get_lpcm_flags(track->enc->codec_id))
 
452
            tag = AV_RL32("lpcm");
 
453
        version = 2;
427
454
    }
428
455
 
429
456
    avio_wb32(pb, 0); /* size */
444
471
        avio_wb16(pb, 0);
445
472
        avio_wb32(pb, 0x00010000);
446
473
        avio_wb32(pb, 72);
447
 
        avio_wb64(pb, av_dbl2int(track->timescale));
 
474
        avio_wb64(pb, av_double2int(track->timescale));
448
475
        avio_wb32(pb, track->enc->channels);
449
476
        avio_wb32(pb, 0x7F000000);
450
477
        avio_wb32(pb, av_get_bits_per_sample(track->enc->codec_id));
451
478
        avio_wb32(pb, mov_get_lpcm_flags(track->enc->codec_id));
452
479
        avio_wb32(pb, track->sampleSize);
453
 
        avio_wb32(pb, track->enc->frame_size);
 
480
        avio_wb32(pb, track->audio_vbr ? track->enc->frame_size : 1);
454
481
    } else {
455
 
        if (track->mode == MODE_MOV) {
456
 
            avio_wb16(pb, track->enc->channels);
457
 
            if (track->enc->codec_id == CODEC_ID_PCM_U8 ||
458
 
                track->enc->codec_id == CODEC_ID_PCM_S8)
459
 
                avio_wb16(pb, 8); /* bits per sample */
460
 
            else
461
 
                avio_wb16(pb, 16);
462
 
            avio_wb16(pb, track->audio_vbr ? -2 : 0); /* compression ID */
463
 
        } else { /* reserved for mp4/3gp */
464
 
            avio_wb16(pb, 2);
465
 
            avio_wb16(pb, 16);
466
 
            avio_wb16(pb, 0);
467
 
        }
 
482
        /* reserved for mp4/3gp */
 
483
        avio_wb16(pb, 2);
 
484
        avio_wb16(pb, 16);
 
485
        avio_wb16(pb, 0);
468
486
 
469
487
        avio_wb16(pb, 0); /* packet size (= 0) */
470
488
        avio_wb16(pb, track->timescale); /* Time scale */
471
489
        avio_wb16(pb, 0); /* Reserved */
472
490
    }
473
491
 
474
 
    if(version == 1) { /* SoundDescription V1 extended info */
475
 
        avio_wb32(pb, track->enc->frame_size); /* Samples per packet */
476
 
        avio_wb32(pb, track->sampleSize / track->enc->channels); /* Bytes per packet */
477
 
        avio_wb32(pb, track->sampleSize); /* Bytes per frame */
478
 
        avio_wb32(pb, 2); /* Bytes per sample */
479
 
    }
480
 
 
481
492
    if(track->mode == MODE_MOV &&
482
493
       (track->enc->codec_id == CODEC_ID_AAC ||
483
494
        track->enc->codec_id == CODEC_ID_AC3 ||
709
720
            if (!tag) { // if no mac fcc found, try with Microsoft tags
710
721
                tag = ff_codec_get_tag(ff_codec_bmp_tags, track->enc->codec_id);
711
722
                if (tag)
712
 
                    av_log(s, AV_LOG_INFO, "Warning, using MS style video codec tag, "
 
723
                    av_log(s, AV_LOG_WARNING, "Using MS style video codec tag, "
713
724
                           "the file may be unplayable!\n");
714
725
            }
715
726
        } else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) {
718
729
                int ms_tag = ff_codec_get_tag(ff_codec_wav_tags, track->enc->codec_id);
719
730
                if (ms_tag) {
720
731
                    tag = MKTAG('m', 's', ((ms_tag >> 8) & 0xff), (ms_tag & 0xff));
721
 
                    av_log(s, AV_LOG_INFO, "Warning, using MS style audio codec tag, "
 
732
                    av_log(s, AV_LOG_WARNING, "Using MS style audio codec tag, "
722
733
                           "the file may be unplayable!\n");
723
734
                }
724
735
            }
772
783
    return 28;
773
784
}
774
785
 
 
786
static const uint16_t fiel_data[] = {
 
787
    0x0000, 0x0100, 0x0201, 0x0206, 0x0209, 0x020e
 
788
};
 
789
 
 
790
static int mov_write_fiel_tag(AVIOContext *pb, MOVTrack *track)
 
791
{
 
792
    unsigned mov_field_order = 0;
 
793
    if (track->enc->field_order < FF_ARRAY_ELEMS(fiel_data))
 
794
        mov_field_order = fiel_data[track->enc->field_order];
 
795
    else
 
796
        return 0;
 
797
    avio_wb32(pb, 10);
 
798
    ffio_wfourcc(pb, "fiel");
 
799
    avio_wb16(pb, mov_field_order);
 
800
    return 10;
 
801
}
 
802
 
775
803
static int mov_write_subtitle_tag(AVIOContext *pb, MOVTrack *track)
776
804
{
777
805
    int64_t pos = avio_tell(pb);
858
886
        mov_write_avcc_tag(pb, track);
859
887
        if(track->mode == MODE_IPOD)
860
888
            mov_write_uuid_tag_ipod(pb);
861
 
    } else if(track->vosLen > 0)
 
889
    } else if (track->enc->field_order != AV_FIELD_UNKNOWN)
 
890
        mov_write_fiel_tag(pb, track);
 
891
    else if(track->vosLen > 0)
862
892
        mov_write_glbl_tag(pb, track);
863
893
 
864
894
    if (track->enc->sample_aspect_ratio.den && track->enc->sample_aspect_ratio.num &&
1214
1244
 
1215
1245
    avio_wb32(pb, 0); /* reserved */
1216
1246
    avio_wb32(pb, 0); /* reserved */
1217
 
    avio_wb32(pb, 0x0); /* reserved (Layer & Alternate group) */
 
1247
    avio_wb16(pb, 0); /* layer */
 
1248
    avio_wb16(pb, st ? st->codec->codec_type : 0); /* alternate group) */
1218
1249
    /* Volume, only for audio */
1219
1250
    if(track->enc->codec_type == AVMEDIA_TYPE_AUDIO)
1220
1251
        avio_wb16(pb, 0x0100);
1277
1308
    avio_wb32(pb, track->enc->height << 16);
1278
1309
 
1279
1310
    return updateSize(pb, pos);
1280
 
};
 
1311
}
1281
1312
 
1282
1313
// This box seems important for the psp playback ... without it the movie seems to hang
1283
1314
static int mov_write_edts_tag(AVIOContext *pb, MOVTrack *track)
1398
1429
    return updateSize(pb, pos);
1399
1430
}
1400
1431
 
1401
 
#if 0
1402
 
/* TODO: Not sorted out, but not necessary either */
1403
1432
static int mov_write_iods_tag(AVIOContext *pb, MOVMuxContext *mov)
1404
1433
{
1405
 
    avio_wb32(pb, 0x15); /* size */
 
1434
    int i, has_audio = 0, has_video = 0;
 
1435
    int64_t pos = avio_tell(pb);
 
1436
    int audio_profile = mov->iods_audio_profile;
 
1437
    int video_profile = mov->iods_video_profile;
 
1438
    for (i = 0; i < mov->nb_streams; i++) {
 
1439
        if(mov->tracks[i].entry > 0) {
 
1440
            has_audio |= mov->tracks[i].enc->codec_type == AVMEDIA_TYPE_AUDIO;
 
1441
            has_video |= mov->tracks[i].enc->codec_type == AVMEDIA_TYPE_VIDEO;
 
1442
        }
 
1443
    }
 
1444
    if (audio_profile < 0)
 
1445
        audio_profile = 0xFF - has_audio;
 
1446
    if (video_profile < 0)
 
1447
        video_profile = 0xFF - has_video;
 
1448
    avio_wb32(pb, 0x0); /* size */
1406
1449
    ffio_wfourcc(pb, "iods");
1407
1450
    avio_wb32(pb, 0);    /* version & flags */
1408
 
    avio_wb16(pb, 0x1007);
1409
 
    avio_w8(pb, 0);
1410
 
    avio_wb16(pb, 0x4fff);
1411
 
    avio_wb16(pb, 0xfffe);
1412
 
    avio_wb16(pb, 0x01ff);
1413
 
    return 0x15;
 
1451
    putDescr(pb, 0x10, 7);
 
1452
    avio_wb16(pb, 0x004f);
 
1453
    avio_w8(pb, 0xff);
 
1454
    avio_w8(pb, 0xff);
 
1455
    avio_w8(pb, audio_profile);
 
1456
    avio_w8(pb, video_profile);
 
1457
    avio_w8(pb, 0xff);
 
1458
    return updateSize(pb, pos);
1414
1459
}
1415
 
#endif
1416
1460
 
1417
1461
static int mov_write_mvhd_tag(AVIOContext *pb, MOVMuxContext *mov)
1418
1462
{
1820
1864
    }
1821
1865
 
1822
1866
    mov_write_mvhd_tag(pb, mov);
1823
 
    //mov_write_iods_tag(pb, mov);
 
1867
    if (mov->mode != MODE_MOV && !mov->iods_skip)
 
1868
        mov_write_iods_tag(pb, mov);
1824
1869
    for (i=0; i<mov->nb_streams; i++) {
1825
1870
        if(mov->tracks[i].entry > 0) {
1826
1871
            mov_write_trak_tag(pb, &(mov->tracks[i]), i < s->nb_streams ? s->streams[i] : NULL);
1993
2038
    AVCodecContext *enc = trk->enc;
1994
2039
    unsigned int samplesInChunk = 0;
1995
2040
    int size= pkt->size;
 
2041
    uint8_t *reformatted_data = NULL;
1996
2042
 
1997
2043
    if (!s->pb->seekable) return 0; /* Can't handle that */
1998
2044
    if (!size) return 0; /* Discard 0 sized packets */
2000
2046
    if (enc->codec_id == CODEC_ID_AMR_NB) {
2001
2047
        /* We must find out how many AMR blocks there are in one packet */
2002
2048
        static uint16_t packed_size[16] =
2003
 
            {13, 14, 16, 18, 20, 21, 27, 32, 6, 0, 0, 0, 0, 0, 0, 0};
 
2049
            {13, 14, 16, 18, 20, 21, 27, 32, 6, 0, 0, 0, 0, 0, 0, 1};
2004
2050
        int len = 0;
2005
2051
 
2006
2052
        while (len < size && samplesInChunk < 100) {
2011
2057
            av_log(s, AV_LOG_ERROR, "fatal error, input is not a single packet, implement a AVParser for it\n");
2012
2058
            return -1;
2013
2059
        }
2014
 
    } else if (enc->codec_id == CODEC_ID_ADPCM_MS ||
2015
 
               enc->codec_id == CODEC_ID_ADPCM_IMA_WAV) {
2016
 
        samplesInChunk = enc->frame_size;
2017
2060
    } else if (trk->sampleSize)
2018
2061
        samplesInChunk = size/trk->sampleSize;
2019
2062
    else
2029
2072
    if (enc->codec_id == CODEC_ID_H264 && trk->vosLen > 0 && *(uint8_t *)trk->vosData != 1) {
2030
2073
        /* from x264 or from bytestream h264 */
2031
2074
        /* nal reformating needed */
2032
 
        size = ff_avc_parse_nal_units(pb, pkt->data, pkt->size);
 
2075
        if (trk->hint_track >= 0 && trk->hint_track < mov->nb_streams) {
 
2076
            ff_avc_parse_nal_units_buf(pkt->data, &reformatted_data,
 
2077
                                       &size);
 
2078
            avio_write(pb, reformatted_data, size);
 
2079
        } else {
 
2080
            size = ff_avc_parse_nal_units(pb, pkt->data, pkt->size);
 
2081
        }
2033
2082
    } else {
2034
2083
        avio_write(pb, pkt->data, size);
2035
2084
    }
2084
2133
    avio_flush(pb);
2085
2134
 
2086
2135
    if (trk->hint_track >= 0 && trk->hint_track < mov->nb_streams)
2087
 
        ff_mov_add_hinted_packet(s, pkt, trk->hint_track, trk->entry);
 
2136
        ff_mov_add_hinted_packet(s, pkt, trk->hint_track, trk->entry,
 
2137
                                 reformatted_data, size);
 
2138
    av_free(reformatted_data);
2088
2139
    return 0;
2089
2140
}
2090
2141
 
2100
2151
    track->mode = mov->mode;
2101
2152
    track->tag = MKTAG('t','e','x','t');
2102
2153
    track->timescale = MOV_TIMESCALE;
2103
 
    track->enc = avcodec_alloc_context();
 
2154
    track->enc = avcodec_alloc_context3(NULL);
2104
2155
    track->enc->codec_type = AVMEDIA_TYPE_SUBTITLE;
2105
2156
 
2106
2157
    for (i = 0; i < s->nb_chapters; i++) {
2127
2178
{
2128
2179
    AVIOContext *pb = s->pb;
2129
2180
    MOVMuxContext *mov = s->priv_data;
 
2181
    AVDictionaryEntry *t;
2130
2182
    int i, hint_track = 0;
2131
2183
 
2132
2184
    if (!s->pb->seekable) {
2219
2271
                       "or choose different container.\n");
2220
2272
        }else if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO){
2221
2273
            track->timescale = st->codec->sample_rate;
2222
 
            if(!st->codec->frame_size && !av_get_bits_per_sample(st->codec->codec_id)) {
2223
 
                av_log(s, AV_LOG_ERROR, "track %d: codec frame size is not set\n", i);
2224
 
                goto error;
2225
 
            }else if(st->codec->codec_id == CODEC_ID_ADPCM_MS ||
2226
 
                     st->codec->codec_id == CODEC_ID_ADPCM_IMA_WAV){
 
2274
            /* set sampleSize for PCM and ADPCM */
 
2275
            if (av_get_bits_per_sample(st->codec->codec_id)) {
2227
2276
                if (!st->codec->block_align) {
2228
 
                    av_log(s, AV_LOG_ERROR, "track %d: codec block align is not set for adpcm\n", i);
 
2277
                    av_log(s, AV_LOG_ERROR, "track %d: codec block align is not set\n", i);
2229
2278
                    goto error;
2230
2279
                }
2231
2280
                track->sampleSize = st->codec->block_align;
2232
 
            }else if(st->codec->frame_size > 1){ /* assume compressed audio */
 
2281
            }
 
2282
            /* set audio_vbr for compressed audio */
 
2283
            if (av_get_bits_per_sample(st->codec->codec_id) < 8) {
 
2284
                if (!st->codec->frame_size) {
 
2285
                    av_log(s, AV_LOG_ERROR, "track %d: codec frame size is not set\n", i);
 
2286
                    goto error;
 
2287
                }
2233
2288
                track->audio_vbr = 1;
2234
 
            }else{
2235
 
                st->codec->frame_size = 1;
2236
 
                track->sampleSize = (av_get_bits_per_sample(st->codec->codec_id) >> 3) * st->codec->channels;
2237
2289
            }
2238
2290
            if (track->mode != MODE_MOV) {
2239
2291
                if (track->timescale > UINT16_MAX) {
2253
2305
        if (!track->height)
2254
2306
            track->height = st->codec->height;
2255
2307
 
2256
 
        av_set_pts_info(st, 64, 1, track->timescale);
 
2308
        avpriv_set_pts_info(st, 64, 1, track->timescale);
2257
2309
    }
2258
2310
 
2259
2311
    mov_write_mdat_tag(pb, mov);
2260
 
    mov->time = s->timestamp + 0x7C25B080; //1970 based -> 1904 based
 
2312
 
 
2313
#if FF_API_TIMESTAMP
 
2314
    if (s->timestamp)
 
2315
        mov->time = s->timestamp;
 
2316
    else
 
2317
#endif
 
2318
    if (t = av_dict_get(s->metadata, "creation_time", NULL, 0))
 
2319
        mov->time = ff_iso8601_to_unix_time(t->value);
 
2320
    if (mov->time)
 
2321
        mov->time += 0x7C25B080; // 1970 based -> 1904 based
2261
2322
 
2262
2323
    if (mov->chapter_track)
2263
2324
        mov_create_chapter_track(s, mov->chapter_track);
2326
2387
}
2327
2388
 
2328
2389
#if CONFIG_MOV_MUXER
 
2390
MOV_CLASS(mov)
2329
2391
AVOutputFormat ff_mov_muxer = {
2330
 
    "mov",
2331
 
    NULL_IF_CONFIG_SMALL("MOV format"),
2332
 
    NULL,
2333
 
    "mov",
2334
 
    sizeof(MOVMuxContext),
2335
 
    CODEC_ID_AAC,
2336
 
    CODEC_ID_MPEG4,
2337
 
    mov_write_header,
2338
 
    ff_mov_write_packet,
2339
 
    mov_write_trailer,
 
2392
    .name              = "mov",
 
2393
    .long_name         = NULL_IF_CONFIG_SMALL("MOV format"),
 
2394
    .extensions        = "mov",
 
2395
    .priv_data_size    = sizeof(MOVMuxContext),
 
2396
    .audio_codec       = CODEC_ID_AAC,
 
2397
#if CONFIG_LIBX264_ENCODER
 
2398
    .video_codec       = CODEC_ID_H264,
 
2399
#else
 
2400
    .video_codec       = CODEC_ID_MPEG4,
 
2401
#endif
 
2402
    .write_header      = mov_write_header,
 
2403
    .write_packet      = ff_mov_write_packet,
 
2404
    .write_trailer     = mov_write_trailer,
2340
2405
    .flags = AVFMT_GLOBALHEADER,
2341
2406
    .codec_tag = (const AVCodecTag* const []){codec_movvideo_tags, codec_movaudio_tags, 0},
2342
2407
    .priv_class = &mov_muxer_class,
2343
2408
};
2344
2409
#endif
2345
2410
#if CONFIG_TGP_MUXER
 
2411
MOV_CLASS(tgp)
2346
2412
AVOutputFormat ff_tgp_muxer = {
2347
 
    "3gp",
2348
 
    NULL_IF_CONFIG_SMALL("3GP format"),
2349
 
    NULL,
2350
 
    "3gp",
2351
 
    sizeof(MOVMuxContext),
2352
 
    CODEC_ID_AMR_NB,
2353
 
    CODEC_ID_H263,
2354
 
    mov_write_header,
2355
 
    ff_mov_write_packet,
2356
 
    mov_write_trailer,
 
2413
    .name              = "3gp",
 
2414
    .long_name         = NULL_IF_CONFIG_SMALL("3GP format"),
 
2415
    .extensions        = "3gp",
 
2416
    .priv_data_size    = sizeof(MOVMuxContext),
 
2417
    .audio_codec       = CODEC_ID_AMR_NB,
 
2418
    .video_codec       = CODEC_ID_H263,
 
2419
    .write_header      = mov_write_header,
 
2420
    .write_packet      = ff_mov_write_packet,
 
2421
    .write_trailer     = mov_write_trailer,
2357
2422
    .flags = AVFMT_GLOBALHEADER,
2358
2423
    .codec_tag = (const AVCodecTag* const []){codec_3gp_tags, 0},
2359
 
    .priv_class = &mov_muxer_class,
 
2424
    .priv_class = &tgp_muxer_class,
2360
2425
};
2361
2426
#endif
2362
2427
#if CONFIG_MP4_MUXER
 
2428
MOV_CLASS(mp4)
2363
2429
AVOutputFormat ff_mp4_muxer = {
2364
 
    "mp4",
2365
 
    NULL_IF_CONFIG_SMALL("MP4 format"),
2366
 
    "application/mp4",
2367
 
    "mp4",
2368
 
    sizeof(MOVMuxContext),
2369
 
    CODEC_ID_AAC,
2370
 
    CODEC_ID_MPEG4,
2371
 
    mov_write_header,
2372
 
    ff_mov_write_packet,
2373
 
    mov_write_trailer,
 
2430
    .name              = "mp4",
 
2431
    .long_name         = NULL_IF_CONFIG_SMALL("MP4 format"),
 
2432
    .mime_type         = "application/mp4",
 
2433
    .extensions        = "mp4",
 
2434
    .priv_data_size    = sizeof(MOVMuxContext),
 
2435
    .audio_codec       = CODEC_ID_AAC,
 
2436
#if CONFIG_LIBX264_ENCODER
 
2437
    .video_codec       = CODEC_ID_H264,
 
2438
#else
 
2439
    .video_codec       = CODEC_ID_MPEG4,
 
2440
#endif
 
2441
    .write_header      = mov_write_header,
 
2442
    .write_packet      = ff_mov_write_packet,
 
2443
    .write_trailer     = mov_write_trailer,
2374
2444
    .flags = AVFMT_GLOBALHEADER,
2375
2445
    .codec_tag = (const AVCodecTag* const []){ff_mp4_obj_type, 0},
2376
 
    .priv_class = &mov_muxer_class,
 
2446
    .priv_class = &mp4_muxer_class,
2377
2447
};
2378
2448
#endif
2379
2449
#if CONFIG_PSP_MUXER
 
2450
MOV_CLASS(psp)
2380
2451
AVOutputFormat ff_psp_muxer = {
2381
 
    "psp",
2382
 
    NULL_IF_CONFIG_SMALL("PSP MP4 format"),
2383
 
    NULL,
2384
 
    "mp4,psp",
2385
 
    sizeof(MOVMuxContext),
2386
 
    CODEC_ID_AAC,
2387
 
    CODEC_ID_MPEG4,
2388
 
    mov_write_header,
2389
 
    ff_mov_write_packet,
2390
 
    mov_write_trailer,
 
2452
    .name              = "psp",
 
2453
    .long_name         = NULL_IF_CONFIG_SMALL("PSP MP4 format"),
 
2454
    .extensions        = "mp4,psp",
 
2455
    .priv_data_size    = sizeof(MOVMuxContext),
 
2456
    .audio_codec       = CODEC_ID_AAC,
 
2457
#if CONFIG_LIBX264_ENCODER
 
2458
    .video_codec       = CODEC_ID_H264,
 
2459
#else
 
2460
    .video_codec       = CODEC_ID_MPEG4,
 
2461
#endif
 
2462
    .write_header      = mov_write_header,
 
2463
    .write_packet      = ff_mov_write_packet,
 
2464
    .write_trailer     = mov_write_trailer,
2391
2465
    .flags = AVFMT_GLOBALHEADER,
2392
2466
    .codec_tag = (const AVCodecTag* const []){ff_mp4_obj_type, 0},
2393
 
    .priv_class = &mov_muxer_class,
 
2467
    .priv_class = &psp_muxer_class,
2394
2468
};
2395
2469
#endif
2396
2470
#if CONFIG_TG2_MUXER
 
2471
MOV_CLASS(tg2)
2397
2472
AVOutputFormat ff_tg2_muxer = {
2398
 
    "3g2",
2399
 
    NULL_IF_CONFIG_SMALL("3GP2 format"),
2400
 
    NULL,
2401
 
    "3g2",
2402
 
    sizeof(MOVMuxContext),
2403
 
    CODEC_ID_AMR_NB,
2404
 
    CODEC_ID_H263,
2405
 
    mov_write_header,
2406
 
    ff_mov_write_packet,
2407
 
    mov_write_trailer,
 
2473
    .name              = "3g2",
 
2474
    .long_name         = NULL_IF_CONFIG_SMALL("3GP2 format"),
 
2475
    .extensions        = "3g2",
 
2476
    .priv_data_size    = sizeof(MOVMuxContext),
 
2477
    .audio_codec       = CODEC_ID_AMR_NB,
 
2478
    .video_codec       = CODEC_ID_H263,
 
2479
    .write_header      = mov_write_header,
 
2480
    .write_packet      = ff_mov_write_packet,
 
2481
    .write_trailer     = mov_write_trailer,
2408
2482
    .flags = AVFMT_GLOBALHEADER,
2409
2483
    .codec_tag = (const AVCodecTag* const []){codec_3gp_tags, 0},
2410
 
    .priv_class = &mov_muxer_class,
 
2484
    .priv_class = &tg2_muxer_class,
2411
2485
};
2412
2486
#endif
2413
2487
#if CONFIG_IPOD_MUXER
 
2488
MOV_CLASS(ipod)
2414
2489
AVOutputFormat ff_ipod_muxer = {
2415
 
    "ipod",
2416
 
    NULL_IF_CONFIG_SMALL("iPod H.264 MP4 format"),
2417
 
    "application/mp4",
2418
 
    "m4v,m4a",
2419
 
    sizeof(MOVMuxContext),
2420
 
    CODEC_ID_AAC,
2421
 
    CODEC_ID_H264,
2422
 
    mov_write_header,
2423
 
    ff_mov_write_packet,
2424
 
    mov_write_trailer,
 
2490
    .name              = "ipod",
 
2491
    .long_name         = NULL_IF_CONFIG_SMALL("iPod H.264 MP4 format"),
 
2492
    .mime_type         = "application/mp4",
 
2493
    .extensions        = "m4v,m4a",
 
2494
    .priv_data_size    = sizeof(MOVMuxContext),
 
2495
    .audio_codec       = CODEC_ID_AAC,
 
2496
    .video_codec       = CODEC_ID_H264,
 
2497
    .write_header      = mov_write_header,
 
2498
    .write_packet      = ff_mov_write_packet,
 
2499
    .write_trailer     = mov_write_trailer,
2425
2500
    .flags = AVFMT_GLOBALHEADER,
2426
2501
    .codec_tag = (const AVCodecTag* const []){codec_ipod_tags, 0},
2427
 
    .priv_class = &mov_muxer_class,
 
2502
    .priv_class = &ipod_muxer_class,
2428
2503
};
2429
2504
#endif