📄 mov.c
字号:
if((uint64_t)atom.size > (1<<30)) return -1; // currently SVQ3 decoder expect full STSD header - so let's fake it // this should be fixed and just SMI header should be passed av_free(st->codec->extradata); st->codec->extradata_size = 0x5a + atom.size; st->codec->extradata = (uint8_t*) av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); if (st->codec->extradata) { strcpy(st->codec->extradata, "SVQ3"); // fake get_buffer(pb, st->codec->extradata + 0x5a, atom.size); dprintf("Reading SMI %"PRId64" %s\n", atom.size, (char*)st->codec->extradata + 0x5a); } else url_fskip(pb, atom.size); return 0;}static int mov_read_enda(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom){ AVStream *st = c->fc->streams[c->fc->nb_streams-1]; int little_endian = get_be16(pb); if (little_endian) { switch (st->codec->codec_id) { case CODEC_ID_PCM_S24BE: st->codec->codec_id = CODEC_ID_PCM_S24LE; break; case CODEC_ID_PCM_S32BE: st->codec->codec_id = CODEC_ID_PCM_S32LE; break; default: break; } } return 0;}static int mov_read_alac(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom){ AVStream *st = c->fc->streams[c->fc->nb_streams-1]; // currently ALAC decoder expect full atom header - so let's fake it // this should be fixed and just ALAC header should be passed av_free(st->codec->extradata); st->codec->extradata_size = 36; st->codec->extradata = (uint8_t*) av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); if (st->codec->extradata) { strcpy(st->codec->extradata + 4, "alac"); // fake get_buffer(pb, st->codec->extradata + 8, 36 - 8); dprintf("Reading alac %d %s\n", st->codec->extradata_size, (char*)st->codec->extradata); } else url_fskip(pb, atom.size); return 0;}static int mov_read_wave(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom){ offset_t start_pos = url_ftell(pb); AVStream *st = c->fc->streams[c->fc->nb_streams-1]; if((uint64_t)atom.size > (1<<30)) return -1; if (st->codec->codec_id == CODEC_ID_QDM2) { // pass all frma atom to codec, needed at least for QDM2 av_free(st->codec->extradata); st->codec->extradata_size = atom.size; st->codec->extradata = (uint8_t*) av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); if (st->codec->extradata) { get_buffer(pb, st->codec->extradata, atom.size); } else url_fskip(pb, atom.size); } else if (atom.size > 8) { /* to read frma, esds atoms */ mov_read_default(c, pb, atom); } else if (atom.size > 0) url_fskip(pb, atom.size); /* in any case, skip garbage */ url_fskip(pb, atom.size - ((url_ftell(pb) - start_pos))); return 0;}static int mov_read_jp2h(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom){ AVStream *st = c->fc->streams[c->fc->nb_streams-1]; if((uint64_t)atom.size > (1<<30)) return -1; av_free(st->codec->extradata); st->codec->extradata_size = atom.size + 8; st->codec->extradata = (uint8_t*) av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); /* pass all jp2h atom to codec */ if (st->codec->extradata) { strcpy(st->codec->extradata + 4, "jp2h"); get_buffer(pb, st->codec->extradata + 8, atom.size); } else url_fskip(pb, atom.size); return 0;}static int mov_read_avcC(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom){ AVStream *st = c->fc->streams[c->fc->nb_streams-1]; if((uint64_t)atom.size > (1<<30)) return -1; av_free(st->codec->extradata); st->codec->extradata_size = atom.size; st->codec->extradata = (uint8_t*) av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); if (st->codec->extradata) { get_buffer(pb, st->codec->extradata, atom.size); } else url_fskip(pb, atom.size); return 0;}static int mov_read_stco(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom){ AVStream *st = c->fc->streams[c->fc->nb_streams-1]; MOVStreamContext *sc = (MOVStreamContext *)st->priv_data; unsigned int i, entries; get_byte(pb); /* version */ get_byte(pb); get_byte(pb); get_byte(pb); /* flags */ entries = get_be32(pb); if(entries >= UINT_MAX/sizeof(int64_t)) return -1; sc->chunk_count = entries; sc->chunk_offsets = (int64_t*) av_malloc(entries * sizeof(int64_t)); if (!sc->chunk_offsets) return -1; if (atom.type == MKTAG('s', 't', 'c', 'o')) { for(i=0; i<entries; i++) { sc->chunk_offsets[i] = get_be32(pb); } } else if (atom.type == MKTAG('c', 'o', '6', '4')) { for(i=0; i<entries; i++) { sc->chunk_offsets[i] = get_be64(pb); } } else return -1; for(i=0; i<c->fc->nb_streams; i++){ MOVStreamContext *sc2 = (MOVStreamContext *)c->fc->streams[i]->priv_data; if(sc2 && sc2->chunk_offsets){ int64_t first= sc2->chunk_offsets[0]; int64_t last= sc2->chunk_offsets[sc2->chunk_count-1]; if(first >= sc->chunk_offsets[entries-1] || last <= sc->chunk_offsets[0]) c->ni=1; } } return 0;}static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom){ AVStream *st = c->fc->streams[c->fc->nb_streams-1]; MOVStreamContext *sc = (MOVStreamContext *)st->priv_data; int entries, frames_per_sample; uint32_t format; uint8_t codec_name[32]; /* for palette traversal */ int color_depth; int color_start; int color_count; int color_end; int color_index; int color_dec; int color_greyscale; unsigned char *color_table; int j; unsigned char r, g, b; get_byte(pb); /* version */ get_byte(pb); get_byte(pb); get_byte(pb); /* flags */ entries = get_be32(pb); while(entries--) { //Parsing Sample description table enum CodecID id; MOV_atom_t a = { 0, 0, 0 }; offset_t start_pos = url_ftell(pb); int size = get_be32(pb); /* size */ format = get_le32(pb); /* data format */ get_be32(pb); /* reserved */ get_be16(pb); /* reserved */ get_be16(pb); /* index */ dprintf("size=%d 4CC= %c%c%c%c codec_type=%d\n", size, (format >> 0) & 0xff, (format >> 8) & 0xff, (format >> 16) & 0xff, (format >> 24) & 0xff, st->codec->codec_type); st->codec->codec_tag = format; id = codec_get_id(mov_audio_tags, format); if (id > 0) { st->codec->codec_type = CODEC_TYPE_AUDIO; } else if (format != MKTAG('m', 'p', '4', 's')) { /* skip old asf mpeg4 tag */ id = codec_get_id(mov_video_tags, format); if (id <= 0) id = codec_get_id(codec_bmp_tags, format); if (id > 0) st->codec->codec_type = CODEC_TYPE_VIDEO; } if(st->codec->codec_type==CODEC_TYPE_VIDEO) { st->codec->codec_id = id; get_be16(pb); /* version */ get_be16(pb); /* revision level */ get_be32(pb); /* vendor */ get_be32(pb); /* temporal quality */ get_be32(pb); /* spacial quality */ if(st->codec->codec_id == CODEC_ID_MPEG4){ //FIXME this is silly get_be16(pb); get_be16(pb); }else{ st->codec->width = get_be16(pb); /* width */ st->codec->height = get_be16(pb); /* height */ } get_be32(pb); /* horiz resolution */ get_be32(pb); /* vert resolution */ get_be32(pb); /* data size, always 0 */ frames_per_sample = get_be16(pb); /* frames per samples */#ifdef DEBUG av_log(NULL, AV_LOG_DEBUG, "frames/samples = %d\n", frames_per_sample);#endif get_buffer(pb, codec_name, 32); /* codec name, pascal string (FIXME: true for mp4?) */ if (codec_name[0] <= 31) { memcpy(st->codec->codec_name, &codec_name[1],codec_name[0]); st->codec->codec_name[codec_name[0]] = 0; } st->codec->bits_per_sample = get_be16(pb); /* depth */ st->codec->color_table_id = get_be16(pb); /* colortable id *//* These are set in mov_read_stts and might already be set! st->codec->time_base.den = 25; st->codec->time_base.num = 1;*/ /* figure out the palette situation */ color_depth = st->codec->bits_per_sample & 0x1F; color_greyscale = st->codec->bits_per_sample & 0x20; /* if the depth is 2, 4, or 8 bpp, file is palettized */ if ((color_depth == 2) || (color_depth == 4) || (color_depth == 8)) { if (color_greyscale) { /* compute the greyscale palette */ color_count = 1 << color_depth; color_index = 255; color_dec = 256 / (color_count - 1); for (j = 0; j < color_count; j++) { r = g = b = color_index; c->palette_control.palette[j] = (r << 16) | (g << 8) | (b); color_index -= color_dec; if (color_index < 0) color_index = 0; } } else if (st->codec->color_table_id & 0x08) { /* if flag bit 3 is set, use the default palette */ color_count = 1 << color_depth; if (color_depth == 2) color_table = ff_qt_default_palette_4; else if (color_depth == 4) color_table = ff_qt_default_palette_16; else color_table = ff_qt_default_palette_256; for (j = 0; j < color_count; j++) { r = color_table[j * 4 + 0]; g = color_table[j * 4 + 1]; b = color_table[j * 4 + 2]; c->palette_control.palette[j] = (r << 16) | (g << 8) | (b); } } else { /* load the palette from the file */ color_start = get_be32(pb); color_count = get_be16(pb); color_end = get_be16(pb); for (j = color_start; j <= color_end; j++) { /* each R, G, or B component is 16 bits; * only use the top 8 bits; skip alpha bytes * up front */ get_byte(pb); get_byte(pb); r = get_byte(pb); get_byte(pb); g = get_byte(pb); get_byte(pb); b = get_byte(pb); get_byte(pb); c->palette_control.palette[j] = (r << 16) | (g << 8) | (b); } } st->codec->palctrl = &c->palette_control; st->codec->palctrl->palette_changed = 1; } else st->codec->palctrl = NULL; } else if(st->codec->codec_type==CODEC_TYPE_AUDIO) { uint16_t version = get_be16(pb); st->codec->codec_id = id; get_be16(pb); /* revision level */ get_be32(pb); /* vendor */ st->codec->channels = get_be16(pb); /* channel count */ st->codec->bits_per_sample = get_be16(pb); /* sample size */ /* do we need to force to 16 for AMR ? */ /* handle specific s8 codec */ get_be16(pb); /* compression id = 0*/ get_be16(pb); /* packet size = 0 */ st->codec->sample_rate = ((get_be32(pb) >> 16)); switch (st->codec->codec_id) { case CODEC_ID_PCM_S16LE: case CODEC_ID_PCM_S16BE: if (st->codec->bits_per_sample == 8) st->codec->codec_id = CODEC_ID_PCM_S8; st->codec->bit_rate = st->codec->sample_rate * 8; break; case CODEC_ID_PCM_U8: if (st->codec->bits_per_sample == 16) st->codec->codec_id = CODEC_ID_PCM_S16BE; st->codec->bit_rate = st->codec->sample_rate * 8; break; case CODEC_ID_AMR_WB: st->codec->sample_rate = 16000; /* should really we ? */ st->codec->channels=1; /* really needed */ break; case CODEC_ID_AMR_NB: st->codec->sample_rate = 8000; /* should really we ? */ st->codec->channels=1; /* really needed */ break; default: break; } //Read QT version 1 fields. In version 0 theese dont exist dprintf("version =%d mp4=%d\n",version,c->mp4); if(version==1) { get_be32(pb); /* samples per packet */ get_be32(pb); /* bytes per packet */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -