+ return -1;
+ }
+
+ int prog_id = 1;
+ AVProgram *prog = av_new_program(fmt_ctx, prog_id);
+ for( int i=0; i< ffvideo.size(); ++i )
+ av_program_add_stream_index(fmt_ctx, prog_id, ffvideo[i]->fidx);
+ for( int i=0; i< ffaudio.size(); ++i )
+ av_program_add_stream_index(fmt_ctx, prog_id, ffaudio[i]->fidx);
+ int pi = fmt_ctx->nb_programs;
+ while( --pi >= 0 && fmt_ctx->programs[pi]->id != prog_id );
+ AVDictionary **meta = &prog->metadata;
+ av_dict_set(meta, "service_provider", "cin5", 0);
+ const char *path = fmt_ctx->filename, *bp = strrchr(path,'/');
+ if( bp ) path = bp + 1;
+ av_dict_set(meta, "title", path, 0);
+
+ if( ffaudio.size() ) {
+ const char *ep = getenv("CIN_AUDIO_LANG"), *lp = 0;
+ if( !ep && (lp=getenv("LANG")) ) { // some are guesses
+ static struct { const char lc[3], lng[4]; } lcode[] = {
+ { "en", "eng" }, { "de", "ger" }, { "es", "spa" },
+ { "eu", "bas" }, { "fr", "fre" }, { "el", "gre" },
+ { "hi", "hin" }, { "it", "ita" }, { "ja", "jap" },
+ { "ko", "kor" }, { "du", "dut" }, { "pl", "pol" },
+ { "pt", "por" }, { "ru", "rus" }, { "sl", "slv" },
+ { "uk", "ukr" }, { "vi", "vie" }, { "zh", "chi" },
+ };
+ for( int i=sizeof(lcode)/sizeof(lcode[0]); --i>=0 && !ep; )
+ if( !strncmp(lcode[i].lc,lp,2) ) ep = lcode[i].lng;
+ }
+ if( !ep ) ep = "und";
+ char lang[5];
+ strncpy(lang,ep,3); lang[3] = 0;
+ AVStream *st = ffaudio[0]->st;
+ av_dict_set(&st->metadata,"language",lang,0);