static int id3v1_create_tag(AVFormatContext *s, uint8_t *buf) { AVMetadataTag *tag; int i, count = 0; memset(buf, 0, ID3v1_TAG_SIZE); /* fail safe */ buf[0] = 'T'; buf[1] = 'A'; buf[2] = 'G'; count += id3v1_set_string(s, "TIT2", buf + 3, 30); //title count += id3v1_set_string(s, "TPE1", buf + 33, 30); //author|artist count += id3v1_set_string(s, "TALB", buf + 63, 30); //album count += id3v1_set_string(s, "TDRL", buf + 93, 4); //date count += id3v1_set_string(s, "comment", buf + 97, 30); if ((tag = av_metadata_get(s->metadata, "TRCK", NULL, 0))) { //track buf[125] = 0; buf[126] = atoi(tag->value); count++; } buf[127] = 0xFF; /* default to unknown genre */ if ((tag = av_metadata_get(s->metadata, "TCON", NULL, 0))) { //genre for(i = 0; i <= ID3v1_GENRE_MAX; i++) { if (!strcasecmp(tag->value, ff_id3v1_genre_str[i])) { buf[127] = i; count++; break; } } } return count; }
static int extract_metadata_core(struct media_file_info *mfi, AVMetadata *md, const struct metadata_map *md_map) { AVMetadataTag *mdt; char **strval; uint32_t *intval; int mdcount; int i; int ret; #if 0 /* Dump all the metadata reported by ffmpeg */ mdt = NULL; while ((mdt = av_metadata_get(md, "", mdt, AV_METADATA_IGNORE_SUFFIX)) != NULL) fprintf(stderr, " -> %s = %s\n", mdt->key, mdt->value); #endif mdcount = 0; /* Extract actual metadata */ for (i = 0; md_map[i].key != NULL; i++) { mdt = av_metadata_get(md, md_map[i].key, NULL, 0); if (mdt == NULL) continue; if ((mdt->value == NULL) || (strlen(mdt->value) == 0)) continue; if (md_map[i].handler_function) { mdcount += md_map[i].handler_function(mfi, mdt->value); continue; } mdcount++; if (!md_map[i].as_int) { strval = (char **) ((char *) mfi + md_map[i].offset); if (*strval == NULL) *strval = strdup(mdt->value); } else { intval = (uint32_t *) ((char *) mfi + md_map[i].offset); if (*intval == 0) { ret = safe_atou32(mdt->value, intval); if (ret < 0) continue; } } } return mdcount; }
const char *FFMpegDecoder::genre() { if (m_format && m_format->metadata) { AVMetadataTag *tag; if ((tag=av_metadata_get(m_format->metadata, "TCON", NULL, AV_METADATA_IGNORE_SUFFIX)) || (tag=av_metadata_get(m_format->metadata, "genre", NULL, AV_METADATA_IGNORE_SUFFIX))) return tag->value; } return NULL; }
const char *FFMpegDecoder::artist() { if (m_format && m_format->metadata) { AVMetadataTag *tag; if ((tag=av_metadata_get(m_format->metadata, "TPE1", NULL, AV_METADATA_IGNORE_SUFFIX)) || (tag=av_metadata_get(m_format->metadata, "artist", NULL, AV_METADATA_IGNORE_SUFFIX)) || (tag=av_metadata_get(m_format->metadata, "author", NULL, AV_METADATA_IGNORE_SUFFIX))) return tag->value; } return NULL; }
void DefaultReader::readHeader() { av_metadata_conv( this->pFormatContext_.get(), NULL, this->pFormatContext_->iformat->metadata_conv ); AVMetadataTag * mt = NULL; if( ( mt = av_metadata_get( this->pFormatContext_->metadata, "title", NULL, 0 ) ) ) { this->setTitle( mt->value ); } if( ( mt = av_metadata_get( this->pFormatContext_->metadata, "author", NULL, 0 ) ) ) { this->setArtist( mt->value ); } if( ( mt = av_metadata_get( this->pFormatContext_->metadata, "copyright", NULL, 0 ) ) ) { this->setCopyright( mt->value ); } if( ( mt = av_metadata_get( this->pFormatContext_->metadata, "comment", NULL, 0 ) ) ) { this->setComment( mt->value ); } if( ( mt = av_metadata_get( this->pFormatContext_->metadata, "album", NULL, 0 ) ) ) { this->setAlbum( mt->value ); } if( ( mt = av_metadata_get( this->pFormatContext_->metadata, "year", NULL, 0 ) ) ) { this->setYear( std::atoi( mt->value ) ); } if( ( mt = av_metadata_get( this->pFormatContext_->metadata, "track", NULL, 0 ) ) ) { this->setIndex( std::atoi( mt->value ) ); } if( ( mt = av_metadata_get( this->pFormatContext_->metadata, "genre", NULL, 0 ) ) ) { this->setGenre( mt->value ); } }
JNIEXPORT jstring JNICALL Java_net_sourceforge_servestream_media_MediaMetadataRetriever_extractMetadata(JNIEnv * env, jclass obj, jstring jkey) { //__android_log_write(ANDROID_LOG_INFO, "Java_net_sourceforge_servestream_media_MediaMetadataRetriever", "extractMetadata called"); AVMetadataTag *tag = NULL; const char * key; key = (*env)->GetStringUTFChars(env, jkey, NULL) ; if (!key) { return NULL; } if (strcmp(key, DURATION) == 0) { char stringDuration[30]; sprintf(stringDuration, "%lu", duration); jstring jstrBuf = (*env)->NewStringUTF(env, stringDuration); return jstrBuf; } else { tag = av_metadata_get(metadata, key, NULL, AV_DICT_IGNORE_SUFFIX); if (tag) { jstring jstrBuf = (*env)->NewStringUTF(env, tag->value); return jstrBuf; } else { return NULL; } } }
static int mp3_read_header(AVFormatContext *s, AVFormatParameters *ap) { AVStream *st; int64_t off; st = av_new_stream(s, 0); if (!st) return AVERROR(ENOMEM); st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_MP3; st->need_parsing = AVSTREAM_PARSE_FULL; st->start_time = 0; // lcm of all mp3 sample rates av_set_pts_info(st, 64, 1, 14112000); off = url_ftell(s->pb); if (!av_metadata_get(s->metadata, "", NULL, AV_METADATA_IGNORE_SUFFIX)) ff_id3v1_read(s); if (mp3_parse_vbr_tags(s, st, off) < 0) url_fseek(s->pb, off, SEEK_SET); /* the parameters will be extracted from the compressed bitstream */ return 0; }
static rstr_t * ffmpeg_metadata_rstr(AVMetadata *m, const char *key) { AVMetadataTag *tag; int len; rstr_t *ret; const char *str; char *d; if((tag = av_metadata_get(m, key, NULL, AV_METADATA_IGNORE_SUFFIX)) == NULL) return NULL; if(!utf8_verify(tag->value)) return NULL; str = tag->value; len = strlen(str); ret = rstr_allocl(str, len); d = rstr_data(ret); while(len > 0) { len--; if(d[len] <= ' ' || d[len] == '-') d[len] = 0; else break; } if(*d == 0 || !strncasecmp(d, "http://", 7)) { rstr_release(ret); return NULL; } return ret; }
static int wv_read_header(AVFormatContext *s, AVFormatParameters *ap) { ByteIOContext *pb = s->pb; WVContext *wc = s->priv_data; AVStream *st; wc->block_parsed = 0; if(wv_read_block_header(s, pb, 0) < 0) return -1; /* now we are ready: build format streams */ st = av_new_stream(s, 0); if (!st) return -1; st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_WAVPACK; st->codec->channels = wc->chan; st->codec->channel_layout = wc->chmask; st->codec->sample_rate = wc->rate; st->codec->bits_per_coded_sample = wc->bpp; av_set_pts_info(st, 64, 1, wc->rate); st->start_time = 0; st->duration = wc->samples; if(!url_is_streamed(s->pb)) { int64_t cur = url_ftell(s->pb); ff_ape_parse_tag(s); if(!av_metadata_get(s->metadata, "", NULL, AV_METADATA_IGNORE_SUFFIX)) ff_id3v1_read(s); url_fseek(s->pb, cur, SEEK_SET); } return 0; }
void metadata_conv(AVMetadata **pm, const AVMetadataConv *d_conv, const AVMetadataConv *s_conv) { /* TODO: use binary search to look up the two conversion tables if the tables are getting big enough that it would matter speed wise */ const AVMetadataConv *sc, *dc; AVMetadataTag *mtag = NULL; AVMetadata *dst = NULL; const char *key; while((mtag=av_metadata_get(*pm, "", mtag, AV_METADATA_IGNORE_SUFFIX))) { key = mtag->key; if (s_conv != d_conv) { if (s_conv) for (sc=s_conv; sc->native; sc++) if (!strcasecmp(key, sc->native)) { key = sc->generic; break; } if (d_conv) for (dc=d_conv; dc->native; dc++) if (!strcasecmp(key, dc->generic)) { key = dc->native; break; } } av_metadata_set2(&dst, key, mtag->value, 0); } av_metadata_free(pm); *pm = dst; }
static int get_id3v1_tag(AVFormatContext *s, audio_tag_info *audio_tag) { AVMetadataTag *tag; int count = 0; if (!audio_tag->title[0]) { count += metadata_set_string(s, "title", audio_tag->title, 30); } if (!audio_tag->author[0]) { count += metadata_set_string(s, "author", audio_tag->author, 30); } if (!audio_tag->album[0]) { count += metadata_set_string(s, "album", audio_tag->album, 30); } if (!audio_tag->year[0]) { count += metadata_set_string(s, "year", audio_tag->year, 4); } if (!audio_tag->comment[0]) { count += metadata_set_string(s, "comment", audio_tag->comment, 30); } if (!audio_tag->genre[0]) { count += metadata_set_string(s, "genre", audio_tag->genre, 32); } if ((tag = av_metadata_get(s->metadata, "track", NULL, 0))) { if (!audio_tag->track) { audio_tag->track = atoi(tag->value); } count++; } return count; }
static int get_id3v2_tag(AVFormatContext *s, audio_tag_info *audio_tag) { AVMetadataTag *tag; int count = 0; if (!audio_tag->title[0]) { count += metadata_set_string(s, "TIT2", audio_tag->title, 512); } if (!audio_tag->author[0]) { count += metadata_set_string(s, "TPE1", audio_tag->author, 512); } if (!audio_tag->album[0]) { count += metadata_set_string(s, "TALB", audio_tag->album, 512); } if (!audio_tag->year[0]) { count += metadata_set_string(s, "TYER", audio_tag->year, 4); } if (!audio_tag->comment[0]) { count += metadata_set_string(s, "COMM", audio_tag->comment, 512); } if (!audio_tag->genre[0]) { count += metadata_set_string(s, "TCON", audio_tag->genre, 32); } if ((tag = av_metadata_get(s->metadata, "TRCK", NULL, 0))) { if (!audio_tag->track) { audio_tag->track = atoi(tag->value); } count++; } return count; }
static void show_format(AVFormatContext *fmt_ctx) { AVMetadataTag *tag = NULL; char val_str[128]; printf("[FORMAT]\n"); printf("filename=%s\n", fmt_ctx->filename); printf("nb_streams=%d\n", fmt_ctx->nb_streams); printf("format_name=%s\n", fmt_ctx->iformat->name); printf("format_long_name=%s\n", fmt_ctx->iformat->long_name); printf("start_time=%s\n", time_value_string(val_str, sizeof(val_str), fmt_ctx->start_time, &AV_TIME_BASE_Q)); printf("duration=%s\n", time_value_string(val_str, sizeof(val_str), fmt_ctx->duration, &AV_TIME_BASE_Q)); printf("size=%s\n", value_string(val_str, sizeof(val_str), fmt_ctx->file_size, unit_byte_str)); printf("bit_rate=%s\n", value_string(val_str, sizeof(val_str), fmt_ctx->bit_rate, unit_bit_per_second_str)); while ((tag = av_metadata_get(fmt_ctx->metadata, "", tag, AV_METADATA_IGNORE_SUFFIX))) printf("TAG:%s=%s\n", tag->key, tag->value); printf("[/FORMAT]\n"); }
void av_metadata_copy(AVMetadata **dst, AVMetadata *src, int flags) { AVMetadataTag *t = NULL; while ((t = av_metadata_get(src, "", t, AV_METADATA_IGNORE_SUFFIX))) av_metadata_set2(dst, t->key, t->value, flags); }
static int id3v1_set_string(AVFormatContext *s, const char *key, uint8_t *buf, int buf_size) { AVMetadataTag *tag; if ((tag = av_metadata_get(s->metadata, key, NULL, 0))) strncpy(buf, tag->value, buf_size); return !!tag; }
int main(int argc,char* argv[]) { char file[255] = {""}; int err, i; if (argc < 2) { printf("give me a filename please\n"); return -1; } if (strstr(argv[1], "://") == NULL) { strcpy(file, "file://"); } strcat(file, argv[1]); av_register_all(); if ((err = av_open_input_file(&avContext, file, NULL, 0, NULL)) != 0) { char error[512]; printf("av_open_input_file failed %d (%s)\n", err, file); #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52, 64, 0) av_strerror(err, error, 512); printf("Cause: %s\n", error); #endif return -1; } if (av_find_stream_info(avContext) < 0) { printf("Error av_find_stream_info\n"); } printf("\n***\n"); dump_metadata(); printf("\nstream specific metadata:\n"); for (i = 0; i < avContext->nb_streams; i++) { AVStream* stream = avContext->streams[i]; if (stream) { AVMetadataTag *tag = NULL; if (stream->metadata != NULL) while ((tag = av_metadata_get(stream->metadata, "", tag, AV_METADATA_IGNORE_SUFFIX))) printf("%s: %s\n", tag->key, tag->value); } } return 0; }
static int mpc_read_header(AVFormatContext *s, AVFormatParameters *ap) { MPCContext *c = s->priv_data; AVStream *st; if(avio_rl24(s->pb) != MKTAG('M', 'P', '+', 0)) { av_log(s, AV_LOG_ERROR, "Not a Musepack file\n"); return -1; } c->ver = avio_r8(s->pb); if(c->ver != 0x07 && c->ver != 0x17) { av_log(s, AV_LOG_ERROR, "Can demux Musepack SV7, got version %02X\n", c->ver); return -1; } c->fcount = avio_rl32(s->pb); if((int64_t)c->fcount * sizeof(MPCFrame) >= UINT_MAX) { av_log(s, AV_LOG_ERROR, "Too many frames, seeking is not possible\n"); return -1; } c->frames = av_malloc(c->fcount * sizeof(MPCFrame)); c->curframe = 0; c->lastframe = -1; c->curbits = 8; c->frames_noted = 0; st = av_new_stream(s, 0); if (!st) return AVERROR(ENOMEM); st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_MUSEPACK7; st->codec->channels = 2; st->codec->bits_per_coded_sample = 16; st->codec->extradata_size = 16; st->codec->extradata = av_mallocz(st->codec->extradata_size+FF_INPUT_BUFFER_PADDING_SIZE); avio_read(s->pb, st->codec->extradata, 16); st->codec->sample_rate = mpc_rate[st->codec->extradata[2] & 3]; av_set_pts_info(st, 32, MPC_FRAMESIZE, st->codec->sample_rate); /* scan for seekpoints */ st->start_time = 0; st->duration = c->fcount; /* try to read APE tags */ if (s->pb->seekable) { int64_t pos = avio_tell(s->pb); ff_ape_parse_tag(s); if (!av_metadata_get(s->metadata, "", NULL, AV_METADATA_IGNORE_SUFFIX)) ff_id3v1_read(s); avio_seek(s->pb, pos, SEEK_SET); } return 0; }
void FFmpegImportFileHandle::GetMetadata(Tags *tags, const wxChar *tag, const char *name) { AVMetadataTag *meta; meta = av_metadata_get(mFormatContext->metadata, name, NULL, AV_METADATA_IGNORE_SUFFIX); if (meta) { tags->SetTag(tag, wxString::FromUTF8(meta->value)); } }
static void write_tags(ByteIOContext *s, AVMetadata *m) { AVMetadataTag *t = NULL; while ((t = av_metadata_get(m, "", t, AV_METADATA_IGNORE_SUFFIX))) { write_escape_str(s, t->key); put_byte(s, '='); write_escape_str(s, t->value); put_byte(s, '\n'); } }
static int ffmpeg_metadata_int(AVMetadata *m, const char *key, int def) { AVMetadataTag *tag; if((tag = av_metadata_get(m, key, NULL, AV_METADATA_IGNORE_SUFFIX)) == NULL) return def; return tag->value && tag->value[0] >= '0' && tag->value[0] <= '9' ? atoi(tag->value) : def; }
void av_metadata_copy(AVMetadata **dst, AVMetadata *src, int flags) { AVMetadataTag *t = NULL, *tag; while ((t = av_metadata_get(src, "", t, AV_METADATA_IGNORE_SUFFIX))) { av_metadata_set_custom(dst, &tag, t->type, t->key, t->value, t->len, flags); if (tag) av_metadata_copy_attributes(tag, t); } }
void dump_metadata() { #if LIBAVCODEC_VERSION_MAJOR < 54 AVMetadataTag *tag = NULL; while ((tag = av_metadata_get(avContext->metadata, "", tag, AV_METADATA_IGNORE_SUFFIX))) #else AVDictionaryEntry *tag = NULL; while ((tag = av_dict_get(avContext->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) #endif printf("%s: %s\n", tag->key, tag->value); }
void FFmpegMeta::print(bool isOutFormat) { LOG(ffmpeg, trace, "ffmpeg::dump_format() ..."); if (isOutFormat) { dump_format(_pFormatContext, 0, _pFormatContext->filename, 1); } else { dump_format(_pFormatContext, 0, _pFormatContext->filename, 0); AVMetadataTag* tag = 0; LOG(ffmpeg, trace, "ffmpeg::av_metadata_get() ..."); while ((tag = av_metadata_get(_pFormatContext->metadata, "", tag, AV_METADATA_IGNORE_SUFFIX))) { std::clog << tag->key << ", " << tag->value << std::endl; // addTag(tag->key, tag->value); } } }
static int sox_write_header(AVFormatContext *s) { SoXContext *sox = s->priv_data; ByteIOContext *pb = s->pb; AVCodecContext *enc = s->streams[0]->codec; AVMetadataTag *comment; size_t comment_len = 0, comment_size; comment = av_metadata_get(s->metadata, "comment", NULL, 0); if (comment) comment_len = strlen(comment->value); comment_size = (comment_len + 7) & ~7; sox->header_size = SOX_FIXED_HDR + comment_size; if (enc->codec_id == CODEC_ID_PCM_S32LE) { put_tag(pb, ".SoX"); put_le32(pb, sox->header_size); put_le64(pb, 0); /* number of samples */ put_le64(pb, av_dbl2int(enc->sample_rate)); put_le32(pb, enc->channels); put_le32(pb, comment_size); } else if (enc->codec_id == CODEC_ID_PCM_S32BE) { put_tag(pb, "XoS."); put_be32(pb, sox->header_size); put_be64(pb, 0); /* number of samples */ put_be64(pb, av_dbl2int(enc->sample_rate)); put_be32(pb, enc->channels); put_be32(pb, comment_size); } else { av_log(s, AV_LOG_ERROR, "invalid codec; use pcm_s32le or pcm_s32be\n"); return -1; } if (comment_len) put_buffer(pb, comment->value, comment_len); for ( ; comment_size > comment_len; comment_len++) put_byte(pb, 0); put_flush_packet(pb); return 0; }
Omm::AvStream::Meta* FFmpegTagger::tag(const std::string& uri) { FFmpegMeta* pMeta = new FFmpegMeta; int error; pMeta->_useAvOpenInputStream = false; // AVFormatParameters avFormatParameters; // memset(&avFormatParameters, 0, sizeof(avFormatParameters)); // avFormatParameters.prealloced_context = 1; // pMeta->_pFormatContext->probesize = 5000; // pMeta->_pFormatContext->max_analyze_duration = 1000000; LOG(ffmpeg, trace, "ffmpeg::av_open_input_file() ..."); // error = av_open_input_file(&pMeta->_pFormatContext, uri.c_str(), 0, 0, &avFormatParameters); error = av_open_input_file(&pMeta->_pFormatContext, uri.c_str(), 0, 0, 0); if (error < 0) { LOGNS(Omm::AvStream, avstream, error, "av_open_input_file() failed."); return 0; } AVMetadataTag* tag = 0; LOG(ffmpeg, trace, "ffmpeg::av_metadata_get() ..."); while ((tag = av_metadata_get(pMeta->_pFormatContext->metadata, "", tag, AV_METADATA_IGNORE_SUFFIX))) { std::clog << tag->key << ", " << tag->value << std::endl; pMeta->setTag(tag->key, tag->value); } LOG(ffmpeg, trace, "ffmpeg::av_find_stream_info() ..."); error = av_find_stream_info(pMeta->_pFormatContext); if (error < 0) { LOGNS(Omm::AvStream, avstream, error, "av_find_stream_info() failed, could not find codec parameters"); return 0; } for(int streamNr = 0; streamNr < pMeta->_pFormatContext->nb_streams; streamNr++) { FFmpegStreamInfo* pStreamInfo = new FFmpegStreamInfo; pStreamInfo->_pAvStream = pMeta->_pFormatContext->streams[streamNr]; pMeta->addStream(pStreamInfo); } return pMeta; }
int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size) { AVMetadataTag *title = av_metadata_get(ac[0]->metadata, "title", NULL, 0); struct sdp_session_level s; int i, j, port, ttl; char dst[32]; memset(buff, 0, size); memset(&s, 0, sizeof(struct sdp_session_level)); s.user = "******"; s.src_addr = "127.0.0.1"; /* FIXME: Properly set this */ s.name = title ? title->value : "No Name"; port = 0; ttl = 0; if (n_files == 1) { port = sdp_get_address(dst, sizeof(dst), &ttl, ac[0]->filename); resolve_destination(dst, sizeof(dst)); if (dst[0]) { s.dst_addr = dst; s.ttl = ttl; } } sdp_write_header(buff, size, &s); dst[0] = 0; for (i = 0; i < n_files; i++) { if (n_files != 1) { port = sdp_get_address(dst, sizeof(dst), &ttl, ac[i]->filename); resolve_destination(dst, sizeof(dst)); } for (j = 0; j < ac[i]->nb_streams; j++) { sdp_write_media(buff, size, ac[i]->streams[j]->codec, dst[0] ? dst : NULL, (port > 0) ? port + j * 2 : 0, ttl); if (port <= 0) { av_strlcatf(buff, size, "a=control:streamid=%d\r\n", i + j); } } } return 0; }
int av_metadata_setdata(AVMetadata **pm, const char *key, const char *value, const char *data, int data_length, int flags) { AVMetadata *m= *pm; AVMetadataTag *tag= av_metadata_get(m, key, NULL, AV_METADATA_MATCH_CASE); if(!m) m=*pm= av_mallocz(sizeof(*m)); if(tag){ av_free(tag->value); av_free(tag->key); *tag= m->elems[--m->count]; }else{ AVMetadataTag *tmp= av_realloc(m->elems, (m->count+1) * sizeof(*m->elems)); if(tmp){ m->elems= tmp; }else return AVERROR(ENOMEM); } if(value || data){ if(flags & AV_METADATA_DONT_STRDUP_KEY){ m->elems[m->count].key = key; }else m->elems[m->count].key = av_strdup(key ); if(flags & AV_METADATA_DONT_STRDUP_VAL){ m->elems[m->count].value= value; }else if (value){ m->elems[m->count].value= av_strdup(value); } else { m->elems[m->count].value=0; } m->elems[m->count].data= data; m->elems[m->count].data_size=data_length; m->count++; } if(!m->count) { av_free(m->elems); av_freep(pm); } return 0; }
void ff_metadata_conv2(AVMetadata **dst, AVMetadata **pm, const AVMetadataConv *d_conv, const AVMetadataConv *s_conv) { /* TODO: use binary search to look up the two conversion tables if the tables are getting big enough that it would matter speed wise */ const AVMetadataConv *sc, *dc; AVMetadataTag *mtag = NULL, *tag; AVMetadata *tmp = NULL; const char *key; if (d_conv == s_conv) return; while((mtag=av_metadata_get(*pm, "", mtag, AV_METADATA_IGNORE_SUFFIX))) { key = mtag->key; if (s_conv) for (sc=s_conv; sc->native; sc++) if (!strcasecmp(key, sc->native)) { key = sc->generic; break; } if (d_conv) for (dc=d_conv; dc->native; dc++) if (!strcasecmp(key, dc->generic)) { key = dc->native; break; } av_metadata_set_custom(&tmp, &tag, mtag->type, key, mtag->value, mtag->len, 0); av_metadata_copy_attributes(tag, mtag); } if (dst) { *dst = tmp; } else { av_metadata_free(pm); *pm = tmp; } }
static int set_sstream_info(play_para_t *p_para) { mstream_info_t *info = &p_para->media_info.stream_info; msub_info_t *sinfo; AVFormatContext *pCtx = p_para->pFormatCtx; if (!info || !pCtx) { return -1; } if (info->has_sub) { unsigned int i; int snum = 0; AVStream *pStream; for (i = 0; i < pCtx->nb_streams; i ++) { pStream = pCtx->streams[i]; if (pStream->codec->codec_type == CODEC_TYPE_SUBTITLE) { AVMetadataTag *lang = av_metadata_get(pStream->metadata, "language", NULL, 0); sinfo = MALLOC(sizeof(msub_info_t)); MEMSET(sinfo, 0, sizeof(msub_info_t)); sinfo->id = pStream->id; sinfo->internal_external = 0; sinfo->width = pStream->codec->width; sinfo->height = pStream->codec->height; sinfo->sub_type = pStream->codec->codec_id; //sinfo->subtitle_size; if (lang) { sinfo->sub_language = lang->value; } p_para->media_info.sub_info[snum] = sinfo; snum ++; if (snum > p_para->media_info.stream_info.total_sub_num) { log_error("[set_sstream_info]sub streams exceed!\n"); return -2; } } } } return 0; }
static int tta_read_header(AVFormatContext *s, AVFormatParameters *ap) { TTAContext *c = s->priv_data; AVStream *st; int i, channels, bps, samplerate, datalen, framelen; uint64_t framepos, start_offset; if (!av_metadata_get(s->metadata, "", NULL, AV_METADATA_IGNORE_SUFFIX)) ff_id3v1_read(s); start_offset = url_ftell(s->pb); if (avio_rl32(s->pb) != AV_RL32("TTA1")) return -1; // not tta file url_fskip(s->pb, 2); // FIXME: flags channels = avio_rl16(s->pb); bps = avio_rl16(s->pb); samplerate = avio_rl32(s->pb); if(samplerate <= 0 || samplerate > 1000000){ av_log(s, AV_LOG_ERROR, "nonsense samplerate\n"); return -1; } datalen = avio_rl32(s->pb); if(datalen < 0){ av_log(s, AV_LOG_ERROR, "nonsense datalen\n"); return -1; } url_fskip(s->pb, 4); // header crc framelen = samplerate*256/245; c->totalframes = datalen / framelen + ((datalen % framelen) ? 1 : 0); c->currentframe = 0; if(c->totalframes >= UINT_MAX/sizeof(uint32_t)){ av_log(s, AV_LOG_ERROR, "totalframes too large\n"); return -1; } st = av_new_stream(s, 0); if (!st) return AVERROR(ENOMEM); av_set_pts_info(st, 64, 1, samplerate); st->start_time = 0; st->duration = datalen; framepos = url_ftell(s->pb) + 4*c->totalframes + 4; for (i = 0; i < c->totalframes; i++) { uint32_t size = avio_rl32(s->pb); av_add_index_entry(st, framepos, i*framelen, size, 0, AVINDEX_KEYFRAME); framepos += size; } url_fskip(s->pb, 4); // seektable crc st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_TTA; st->codec->channels = channels; st->codec->sample_rate = samplerate; st->codec->bits_per_coded_sample = bps; st->codec->extradata_size = url_ftell(s->pb) - start_offset; if(st->codec->extradata_size+FF_INPUT_BUFFER_PADDING_SIZE <= (unsigned)st->codec->extradata_size){ //this check is redundant as avio_read should fail av_log(s, AV_LOG_ERROR, "extradata_size too large\n"); return -1; } st->codec->extradata = av_mallocz(st->codec->extradata_size+FF_INPUT_BUFFER_PADDING_SIZE); url_fseek(s->pb, start_offset, SEEK_SET); avio_read(s->pb, st->codec->extradata, st->codec->extradata_size); return 0; }