/**
      \fn DIA_v2v
      \brief  handle vob2vobsub dialog 
*/
uint8_t  DIA_v2v(char **vobname, char **ifoname,char **vobsubname)
{
uint8_t ret=0;
char *tmp=NULL,*tmp2=NULL,*tmp3=NULL;

        
        diaElemFile eVob(0,&tmp,QT_TR_NOOP("_VOB file(s):"), NULL, QT_TR_NOOP("Select VOB file(s)"));
        diaElemFile eIfo(0,&tmp2,QT_TR_NOOP("_IFO file:"), NULL, QT_TR_NOOP("Select IFO file"));
        diaElemFile eVsub(1,&tmp3,QT_TR_NOOP("VobSub file:"), NULL, QT_TR_NOOP("Select VobSub file"));
        
        while(1)
        {
           diaElem *tabs[]={&eVob,&eIfo,&eVsub};
          if( diaFactoryRun(QT_TR_NOOP("VOB to VobSub"),3,tabs))
	  {
              if(!ADM_fileExist(tmp))
              {
                GUI_Error_HIG(QT_TR_NOOP("The selected vobfile does not exist"), NULL); 
                continue;
              }
              if(!ADM_fileExist(tmp2))
              {
                GUI_Error_HIG(QT_TR_NOOP("The selected vobfile does not exist"), NULL); 
                continue;
              }
              if(strlen(tmp3)<3)
              {
                 GUI_Error_HIG(QT_TR_NOOP("Please select a correct VobSub path/dir"), NULL); 
                 continue;
              }
                  if(*vobname) ADM_dealloc(*vobname);
                  if(*ifoname) ADM_dealloc(*ifoname);
                  if(*vobsubname) ADM_dealloc(*vobsubname);

                    *vobname=*ifoname=*vobsubname=NULL;

                  *vobname=ADM_strdup(tmp);
                  *ifoname=ADM_strdup(tmp2);
                  *vobsubname=(char *)ADM_alloc(strlen(tmp3)+5); //ADM_strdup(tmp3);
                  strcpy(*vobsubname,tmp3);
                  if(tmp3[strlen(tmp3)-1]!='x'|| tmp3[strlen(tmp3)-2]!='d') 
                          strcat(*vobsubname,".idx");
                  ADM_dealloc(tmp);
                  ADM_dealloc(tmp2);
                  ADM_dealloc(tmp3);
                  return 1;
          } 
          else return 0;
        }
        return 0;
}
void checkCrashFile(void)
{
  char *baseDir=ADM_getBaseDir();
  const char *name=CRASH_FILE;
  static int crashCount=0;
  char *where=new char[strlen(baseDir)+strlen(name)+2];
  strcpy(where,baseDir);
  strcat(where,name);
  if(ADM_fileExist(where))
  {
	  IScriptEngine *engine = getDefaultScriptEngine();

	  if (engine != NULL)
	  {
    if(GUI_Confirmation_HIG(QT_TR_NOOP("Load it"),QT_TR_NOOP("Crash file"),
       QT_TR_NOOP("I have detected a crash file. \nDo you want to load it  ?\n(It will be deleted in all cases, you should save it if you want to keep it)")))
    {
       A_parseScript(engine,where);
    }
	  }

    unlink(where);
  }else
  {
    printf("No crash file (%s)\n",where);
  }
  delete [] where;
}
extern "C"  uint32_t         probe(uint32_t magic, const char *fileName)
{
char *index=(char *)alloca(strlen(fileName)+6);
int count=0;
    printf("[TS Demuxer] Probing...\n");
    if( !detectTs(fileName))
    {
        printf(" [TS Demuxer] Not a ts file\n");
        return false;
    }
    sprintf(index,"%s.idx2",fileName);
again:    
    if(ADM_fileExist(index)) 
    {
        printf(" [TS Demuxer] There is an index for that file \n");
        FILE *f=ADM_fopen(index,"rt");
        char signature[10];
        fread(signature,4,1,f);
        signature[4]=0;
        fclose(f);
        if(!strcmp(signature,"PSD1"))
        {
                // Check if it is a valid index for us...
                 indexFile indexFile;
                 char *type;
                 if(!indexFile.open(index))
                 {
                    printf("[tsDemux] Cannot open index file %s\n",index);
                    indexFile.close();
                    return false;
                  }
                 if(!indexFile.readSection("System"))
                {
                    printf("[tsDemux] Cannot read system section\n");
                    indexFile.close();
                    return false;
                }
                type=indexFile.getAsString("Type");
                if(!type || type[0]!='T')
                    {
                        printf("[TsDemux] Incorrect or not found type\n");
                        indexFile.close();
                        return false;
                    }
                return 50;
        }
        printf("[TSDemuxer] Not a valid index\n");
        return false;

     }
    if(count) return false;
    printf("[TSDemuxer] Analyzing file..\n");
    count++;

  
    if(true==tsIndexer(fileName)) goto again;
    printf("[TSDemuxer] Failed..\n");
   return 0;
}
bool
FileSystem::exists( string path_ )
{
    return ADM_fileExist(path_.c_str());
/*
    struct stat buf;
    return stat( path_.c_str(), &buf ) == 0;
*/
}
Example #5
0
void Ui_vobsubWindow::idxSel(bool i)
{
    char fileIdx[1024];

    if(FileSel_SelectRead(QT_TR_NOOP("Select Idx File"),fileIdx,1023, NULL) && ADM_fileExist(fileIdx))
    {
        // Set entry
        ui.lineEditIdx->setText(fileIdx);
        fillLanguage(fileIdx);
    }
}
Example #6
0
/**
 * \fn loadShader
 * @param src
 * @return 
 */
bool shaderLoader::loadShader(const char *src)
{
    
    if(!ADM_fileExist(src))
    {
        ADM_warning("Shader file does not exist (%s)\n",src);
        return false;
    }
    
    int sourceSize=ADM_fileSize(src);
    if(sourceSize<5)
    {
        ADM_warning("Shader file is too short(%s)\n",src);
        return false;
    }
    
    uint8_t *buffer=(uint8_t *)admAlloca(sourceSize+1);
    FILE *f=fopen(params.shaderFile.c_str(),"rt");
    if(!f)
    {
        ADM_warning("Cannot open file %s\n",src);
        return false;
    }
        
    fread(buffer,sourceSize,1,f);
    buffer[sourceSize]=0;
    fclose(f);
    f=NULL;

    if(glProgramY)
    {
        delete glProgramY;
        glProgramY=NULL;
    }
    glProgramY =    createShaderFromSource(QOpenGLShader::Fragment,(char *)buffer);
    if(!glProgramY)
    {
        ADM_error("Shader compiling failed\n");
        return false;
    }
    ADM_info("Shader %s successfully loaded an compiled\n",src);
    return true;
}
/**
    \fn addFile
    \brief	Load or append a file.	The file type is determined automatically and the ad-hoc video decoder is spawned
    
    @param name: filename
    @param mode: 0 open, 1 append
    @param forcedType : if !=Unknown_FileType, it enables to force the file type

    @return 1 on success, 0 on failure
        

*/
uint8_t ADM_Composer::addFile (const char *name, uint8_t mode,fileType forcedType)
{
  uint8_t    ret =    0;
  aviInfo    info;
  WAVHeader *    _wavinfo;
//  aviHeader *    tmp;
  fileType    type =    forcedType;

UNUSED_ARG(mode);
	_haveMarkers=0; // by default no markers are present

  if (_nb_video == (max_videos - 1))
  {
	  max_videos += MAX_VIDEO;
	  printf("extending max_videos: %i\n", max_videos);

	  _VIDEOS *vid = new _VIDEOS[max_videos];

	  memset(vid, 0, sizeof(_VIDEOS) * max_videos);
	  memcpy(vid, _videos, sizeof(_VIDEOS) * (max_videos - MAX_VIDEO));

	  delete _videos;
	  _videos = vid;
  }

  if (_nb_segment == max_seg - 1)
	  extendSegmentBuffer();

  ADM_assert (_nb_segment < max_seg);
  ADM_assert (_nb_video < max_videos);

  // Autodetect file type ?
  if(Unknown_FileType==type)
  {
      if (!identify (name, &type))
        return 0;
  }


#define OPEN_AS(x,y) case x:\
						_videos[_nb_video]._aviheader=new y; \
						 ret = _videos[_nb_video]._aviheader->open(name); \
						break;
  switch (type)
    {
      case VCodec_FileType:
      		loadVideoCodecConf(name);      		
		return ADM_IGN; // we do it but it wil fail, no problem with that
      		break;
      OPEN_AS (Mp4_FileType, mp4Header);
      OPEN_AS (H263_FileType, h263Header);
      
      case ASF_FileType:
              _videos[_nb_video]._aviheader=new asfHeader; 
              ret = _videos[_nb_video]._aviheader->open(name); 
              if(!ret)
              {
                delete _videos[_nb_video]._aviheader;
                printf("Trying mpeg\n"); 
                goto thisIsMpeg; 
              }
              break;
      OPEN_AS (NewMpeg_FileType,dmxHeader);
      // For AVI we first try top open it as openDML
      case AVI_FileType:
      			_videos[_nb_video]._aviheader=new OpenDMLHeader; 
			 ret = _videos[_nb_video]._aviheader->open(name); 			
			break;
      
    case Nuppel_FileType:
	{ // look if the idx exists
	  char *tmpname = (char*)ADM_alloc(strlen(name)+strlen(".idx")+1);
		ADM_assert(tmpname);
		sprintf(tmpname,"%s.idx",name);
		if(addFile(tmpname))
		{
			return 1; // Memleak ?
		}
		ADM_dealloc(tmpname);
		// open .nuv file
		_videos[_nb_video]._aviheader=new nuvHeader;
		ret = _videos[_nb_video]._aviheader->open(name);
		// we store the native .nuv file in the edl
		// the next load of the edl will open .idx instead
		break;
	}
      OPEN_AS (BMP_FileType, picHeader);
      OPEN_AS (Matroska_FileType, mkvHeader);
      OPEN_AS (FLV_FileType, flvHeader);
      OPEN_AS (AvsProxy_FileType, avsHeader);
      OPEN_AS (_3GPP_FileType, MP4Header);
      OPEN_AS (Ogg_FileType, oggHeader);
      OPEN_AS (AMV_FileType, amvHeader);

    case Mpeg_FileType:
thisIsMpeg:
    	// look if the idx exists
	char tmpname[256];
	ADM_assert(strlen(name)+5<256);
	strcpy(tmpname,name);
	strcat(tmpname,".idx");
        if(ADM_fileExist(tmpname))
        {
	       return addFile(tmpname);
        }
	/* check for "Read-only file system" */
	{
                int fd = ADM_open(tmpname,O_CREAT|O_EXCL|O_WRONLY,S_IRUSR|S_IWUSR);
                if( fd >= 0 )
                {
                    close(fd);
                    unlink(tmpname);
                    printf("Filesystem is writable\n");
		}else if( errno == EROFS ){
		  char *tmpdir = getenv("TMPDIR");
#ifdef __WIN32
                        printf("Filesystem is not writable, looking for somewhere else\n");
			if( !tmpdir )
				tmpdir = "c:";
			snprintf(tmpname,256,"%s%s.idx",tmpdir,strrchr(name,'\\'));
#else
			if( !tmpdir )
				tmpdir = "/tmp";
			snprintf(tmpname,256,"%s%s.idx",tmpdir,strrchr(name,'/'));
#endif
			tmpname[255] = 0;
                        printf("Storing index in %s\n",tmpname);
                    if(ADM_fileExist(tmpname))
                    {
                        printf("Index present, loading it\n");
                        return addFile(tmpname);
                    }
                }
        }
        if(tryIndexing(name,tmpname))
        {
                return addFile (tmpname);
        }
        return 0;
      break;
	case WorkBench_FileType:

  		return loadWorbench(name);
#if 0
        case Script_FileType:
                return parseScript(name);
#endif
	case ECMAScript_FileType:
                printf("****** This is an ecmascript, run it with avidemux2 --run yourscript *******\n");
                printf("****** This is an ecmascript, run it with avidemux2 --run yourscript *******\n");
                printf("****** This is an ecmascript, run it with avidemux2 --run yourscript *******\n");
                return 0;
		
                
    default:
      if (type == Unknown_FileType)
	{
	  printf ("\n not identified ...\n");
	}
      else
        GUI_Error_HIG(QT_TR_NOOP("File type identified but no loader support detected..."),
                      QT_TR_NOOP("May be related to an old index file."));
      return 0;
    }

   // check opening was successful
   if (ret == 0) {
     char str[512+1];
     snprintf(str,512,QT_TR_NOOP("Attempt to open %s failed!"), name);
      str[512] = '\0';
      GUI_Error_HIG(str,NULL);
      delete _videos[_nb_video]._aviheader;
      return 0;
   }

   /* check for resolution */
   if( _nb_video ){
      /* append operation */
      aviInfo info0, infox;
      _videos[   0     ]._aviheader->getVideoInfo (&info0);
      _videos[_nb_video]._aviheader->getVideoInfo (&infox);

      if(info0.width != infox.width || info0.height != infox.height)
	  {
         GUI_Error_HIG(QT_TR_NOOP("Video dimensions don't match."), QT_TR_NOOP("You cannot mix different video dimensions yet. Using the partial video filter later will not work around this problem. The workaround is:\n\n1) \"Resize\" / \"Add Border\" / \"Crop\" each stream to the same resolution\n2) Concatenate them together"));
		 delete _videos[_nb_video]._aviheader;
         return 0;
      }
   }
 
  // else update info
  _videos[_nb_video]._aviheader->getVideoInfo (&info);
  _videos[_nb_video]._aviheader->setMyName (name);
  
  // Printf some info about extradata
  {
    uint32_t l=0;
    uint8_t *d=NULL;
    _videos[_nb_video]._aviheader->getExtraHeaderData(&l,&d);
    if(l && d)
    {
        printf("The video codec has some extradata (%d bytes)\n",l);
        mixDump(d,l);
        printf("\n");
    }
  }
  // 1st if it is our first video we update postproc
 if(!_nb_video)
 {
        uint32_t type,value;

        if(!prefs->get(DEFAULT_POSTPROC_TYPE,&type)) type=3;
        if(!prefs->get(DEFAULT_POSTPROC_VALUE,&value)) value=3; 	

	deletePostProc(&_pp );
 	initPostProc(&_pp,info.width,info.height);
	_pp.postProcType=type;
	_pp.postProcStrength=value;
	_pp.forcedQuant=0;
	updatePostProc(&_pp);

	if(_imageBuffer) delete _imageBuffer;
	_imageBuffer=new ADMImage(info.width,info.height);
 	_imageBuffer->_qSize= ((info.width+15)>>4)*((info.height+15)>>4);
	_imageBuffer->quant=new uint8_t[_imageBuffer->_qSize];
	_imageBuffer->_qStride=(info.width+15)>>4;
 }
Example #8
0
/**
    \fn setup
*/
bool x265Encoder::setup(void)
{
    ADM_info("=============x265, setting up==============\n");
    MMSET(param);

    x265_param_default( &param);
    firstIdr=true;
    image=new ADMImageDefault(getWidth(),getHeight());

    // -------------- preset, tune, idc ------------
    if(!x265Settings.useAdvancedConfiguration)
    {
        char tune[200] = {0};
        strcat(tune, x265Settings.general.tuning);
        x265_param_default_preset(&param, x265Settings.general.preset, tune);
    }
    param.logLevel=x265Settings.level;

    // Threads..
#if X265_BUILD < 47
    switch(x265Settings.general.poolThreads)
    {
    case 0:
    case 1:
    case 2:
        param.poolNumThreads = x265Settings.general.poolThreads;
        break;
    case 99:
        break; //auto
    default:
        ADM_error("UNKNOWN NB OF THREADS\n");
        break;
    }
#endif

    switch(x265Settings.general.frameThreads)
    {
    case 0:
    case 1:
    case 2:
        param.frameNumThreads = x265Settings.general.frameThreads;
        break;
    case 99:
        break; //auto
    default:
        ADM_error("UNKNOWN NB OF THREADS\n");
        break;
    }
    param.sourceWidth = getWidth();
    param.sourceHeight = getHeight();
    param.internalCsp = X265_CSP_I420;
    param.internalBitDepth = 8;
    param.logLevel=X265_LOG_INFO; //DEBUG; //INFO;

    //Framerate
    int n,d;
    uint64_t f=source->getInfo()->frameIncrement;
    usSecondsToFrac(f,&n,&d);
    param.fpsNum = d;
    param.fpsDenom = n;

    // -------------- vui------------
#undef MKPARAM
#undef MKPARAMD
#undef MKPARAMB
#define MKPARAM(x,y) {param.vui.x = x265Settings.vui.y;aprintf("[x265] vui."#x" = %d\n",param.vui.x);}
#define MKPARAMD(x,y) {param.vui.x = (double)x265Settings.vui.y; aprintf("[x265] vui."#x" = %.2f\n",param.vui.x);}
#define MKPARAMB(x,y) {param.vui.x = x265Settings.vui.y ;aprintf("[x265] vui."#x" = %s\n",TrueFalse[param.vui.x&1]);}
    MKPARAM (sarWidth,sar_width)
    MKPARAM (sarHeight,sar_height)

    // -------------- rate control------------
    switch(x265Settings.general.params.mode)
    {
    case COMPRESS_2PASS:
    case COMPRESS_2PASS_BITRATE:
        uint32_t bitrate;
        if(passNumber!=1 && passNumber!=2)
        {
            ADM_error("No pass number specified! (%d)\n",(int)passNumber);
            return false;
        }
        ADM_info("Starting pass :%d\n",passNumber);
        if(x265Settings.general.params.mode==COMPRESS_2PASS)
        {
            uint64_t duration=source->getInfo()->totalDuration; // in us
            ADM_info("Source duration :%s\n",ADM_us2plain(duration));
            ADM_info("Target size     :%d\n",(int)x265Settings.general.params.finalsize);
            uint32_t avg;
            if(false==ADM_computeAverageBitrateFromDuration(duration,
                    x265Settings.general.params.finalsize,
                    &avg))
            {
                ADM_error("[x265] No source duration!\n");
                return false;
            }
            bitrate=(uint32_t)avg;
        }
        else
            bitrate=x265Settings.general.params.avg_bitrate;
        ADM_info("Using average bitrate of %d kb/s\n",(int)bitrate);
        param.rc.rateControlMode = X265_RC_ABR;
        param.rc.bitrate =  bitrate;
        if(passNumber==1)
        {
            param.rc.bStatWrite=1;
            param.rc.bStatRead=0;
            param.rc.statFileName=strdup(logFile);

        } else
        {
            param.rc.bStatWrite=0;
            param.rc.bStatRead=1;
            param.rc.statFileName=strdup(logFile);
            if(!ADM_fileExist(logFile))
            {
                ADM_error("Logfile %s does not exist \n",logFile);
                return false;
            }
        }
        break;
    case COMPRESS_AQ:
        param.rc.rateControlMode = X265_RC_CRF;
        param.rc.rfConstant = x265Settings.general.params.qz;
        break;
    case COMPRESS_CQ:
        param.rc.rateControlMode = X265_RC_CQP;
        param.rc.qp = x265Settings.general.params.qz;
        break;

    case COMPRESS_CBR:
        param.rc.rateControlMode = X265_RC_ABR;
        param.rc.bitrate =  x265Settings.general.params.bitrate;
        param.rc.qp = 0;
        param.rc.rfConstant = 0;
        break;
    default:
        GUI_Error_HIG("Not coded","this mode has notbeen implemented\n");
        return false;
        break;

    }

    if(globalHeader)
        param.bRepeatHeaders=0;
    else
        param.bRepeatHeaders=1;

    if(x265Settings.useAdvancedConfiguration)
    {

#undef MKPARAM
#undef MKPARAMD
#undef MKPARAMB
#define MKPARAM(x,y) {param.x = x265Settings.y;aprintf("[x265] "#x" = %d\n",param.x);}
#define MKPARAMD(x,y) {param.x = (double)x265Settings.y; aprintf("[x265] "#x" = %.2f\n",param.x);}
#define MKPARAMB(x,y) {param.x = x265Settings.y ;aprintf("[x265] "#x" = %s\n",TrueFalse[param.x&1]);}
        MKPARAM(maxNumReferences,MaxRefFrames);
        MKPARAM(keyframeMin,MinIdr);
        MKPARAM(keyframeMax,MaxIdr);
        MKPARAM(scenecutThreshold,i_scenecut_threshold);
        MKPARAM(bframes,MaxBFrame);

        MKPARAM(bFrameAdaptive,i_bframe_adaptive);
        MKPARAM(bFrameBias,i_bframe_bias);
        MKPARAM(bBPyramid,i_bframe_pyramid);
        MKPARAMB(bEnableLoopFilter,b_deblocking_filter);
        MKPARAMB(interlaceMode,interlaced_mode);
        MKPARAMB(bEnableConstrainedIntra,constrained_intra);
        MKPARAM(lookaheadDepth,lookahead);

        MKPARAMB(bEnableWeightedBiPred,weighted_bipred)
        MKPARAM (bEnableWeightedPred,weighted_pred)
        MKPARAM (cbQpOffset,cb_chroma_offset)
        MKPARAM (crQpOffset,cr_chroma_offset)

        MKPARAM (searchMethod,me_method)
        MKPARAM (searchRange,me_range)
        MKPARAM (subpelRefine,subpel_refine)
        MKPARAM (bFrameAdaptive,trellis)
        MKPARAMB(bEnableEarlySkip,fast_pskip)
        MKPARAMB(bEnableTSkipFast,dct_decimate)
        MKPARAMD(psyRd,psy_rd)

#if X265_BUILD >= 40
        MKPARAM (noiseReductionIntra,noise_reduction_intra)
        MKPARAM (noiseReductionInter,noise_reduction_inter)
#else
        MKPARAM (noiseReduction,noise_reduction)
#endif

        //---------------- ratecontrol -------------------
#undef MKPARAM
#undef MKPARAMD
#undef MKPARAMB
#define MKPARAM(x,y)  {param.rc.x = x265Settings.ratecontrol.y;aprintf("[x265] rc."#x" = %d\n",param.rc.x);}
#define MKPARAMD(x,y) {param.rc.x = (double)x265Settings.ratecontrol.y; aprintf("[x265] rc."#x" = %.2f\n",param.rc.x);}
#define MKPARAMB(x,y) {param.rc.x = x265Settings.ratecontrol.y ;aprintf("[x265] rc."#x" = %s\n",TrueFalse[param.rc.x&1]);}

        MKPARAM(qpStep,qp_step);

#if X265_BUILD >= 41
        MKPARAMB(bStrictCbr,strict_cbr);
#else
        MKPARAM(rateTolerance,rate_tolerance);
#endif

        MKPARAM(ipFactor,ip_factor);
        MKPARAM(pbFactor,pb_factor);
        MKPARAMB(cuTree,cu_tree);
        MKPARAM(aqMode,aq_mode);
        MKPARAMD(aqStrength,aq_strength);
    }

    if(!param.bframes)  encoderDelay=0;
    else
    {
        if(2>=param.maxNumReferences)
        {
            encoderDelay=f*2*2;
        }
        else
        {
            encoderDelay=2*f*(x265Settings.MaxRefFrames-1);
        }
    }

    if(!x265Settings.useAdvancedConfiguration)
    {
        x265_param_apply_profile(&param, x265Settings.general.profile);
    }

    dumpx265Setup(&param);
    ADM_info("Creating x265 encoder\n");
    handle = x265_encoder_open (&param);
    if (!handle)
    {
        ADM_error("Cannot initialize x265\n");
        return 0;
    }


    ADM_info("x265, setup ok\n");
    if (globalHeader)
    {
        ADM_info("Creating global header\n");
        return createHeader ();
    } else
        ADM_info("No need for global header\n");

    return true;
}
void x264CustomMatrixDialog::loadFileButton_pressed()
{
	char cqmFileName[1024];
	uint8_t intra4x4Luma[16], intra4x4Chroma[16];
	uint8_t inter4x4Luma[16], inter4x4Chroma[16];
	uint8_t intra8x8Luma[64], inter8x8Luma[64];

	if (FileSel_SelectRead(QT_TR_NOOP("Select Matrix File"), cqmFileName, 1023, NULL) && ADM_fileExist(cqmFileName))
		if (x264_cqm_parse_file(cqmFileName, intra4x4Luma, intra4x4Chroma, inter4x4Luma, inter4x4Chroma, intra8x8Luma, inter8x8Luma) == 0)
		{
			setIntra4x4Luma(intra4x4Luma);
			setIntraChroma(intra4x4Chroma);
			setInter4x4Luma(inter4x4Luma);
			setInterChroma(inter4x4Chroma);
			setIntra8x8Luma(intra8x8Luma);
			setInter8x8Luma(inter8x8Luma);
		}
		else
			GUI_Error_HIG(QT_TR_NOOP("Read Error"), QT_TR_NOOP("Error reading custom matrix file."));
}
void Ui_vobsubWindow::idxSel()
{
	char fileIdx[1024];
	
	if(FileSel_SelectRead(tr("Select Idx File").toUtf8().constData(),fileIdx,1023, NULL) && ADM_fileExist(fileIdx))
	{
		// Set entry
		ui.lineEditIdx->setText(fileIdx);
		fillLanguage(fileIdx);
	}
}
/**
	Load or append a file.
	The file type is determined automatically and the ad-hoc video decoder is spawned


*/
uint8_t ADM_Composer::addFile (char *name, uint8_t mode)
{
  uint8_t    ret =    0;
  aviInfo    info;
  WAVHeader *    _wavinfo;
//  aviHeader *    tmp;
  fileType    type =    Unknown_FileType;

UNUSED_ARG(mode);
	_haveMarkers=0; // by default no markers are present
  ADM_assert (_nb_segment < MAX_SEG);
  ADM_assert (_nb_video < MAX_VIDEO);

  if (!identify (name, &type))
    return 0;


#define OPEN_AS(x,y) case x:\
						_videos[_nb_video]._aviheader=new y; \
						 ret = _videos[_nb_video]._aviheader->open(name); \
						break;
  switch (type)
    {
      case VCodec_FileType:
      		loadVideoCodecConf(name);      		
		return ADM_IGN; // we do it but it wil fail, no problem with that
      		break;
      OPEN_AS (Mp4_FileType, mp4Header);
      OPEN_AS (H263_FileType, h263Header);
      OPEN_AS (ASF_FileType, asfHeader);
      OPEN_AS (NewMpeg_FileType,dmxHeader);
      // For AVI we first try top open it as openDML
      case AVI_FileType:
      			_videos[_nb_video]._aviheader=new OpenDMLHeader; 
			 ret = _videos[_nb_video]._aviheader->open(name); 			
			break;
      
    case Nuppel_FileType:
	{ // look if the idx exists
	  char *tmpname = (char*)ADM_alloc(strlen(name)+strlen(".idx")+1);
		ADM_assert(tmpname);
		sprintf(tmpname,"%s.idx",name);
		if(addFile(tmpname))
		{
			return 1; // Memleak ?
		}
		ADM_dealloc(tmpname);
		// open .nuv file
		_videos[_nb_video]._aviheader=new nuvHeader;
		ret = _videos[_nb_video]._aviheader->open(name);
		// we store the native .nuv file in the edl
		// the next load of the edl will open .idx instead
		break;
	}
      OPEN_AS (BMP_FileType, picHeader);
      OPEN_AS (Matroska_FileType, mkvHeader);
      OPEN_AS (AvsProxy_FileType, avsHeader);
      OPEN_AS (_3GPP_FileType, _3GPHeader);
       OPEN_AS (Ogg_FileType, oggHeader);

    case Mpeg_FileType:
    	// look if the idx exists
	char tmpname[256];
	ADM_assert(strlen(name)+5<256);;
	strcpy(tmpname,name);
	strcat(tmpname,".idx");
        if(ADM_fileExist(tmpname))
        {
	       return addFile(tmpname);
        }
	/* check for "Read-only file system" */
	{
                int fd = open(tmpname,O_CREAT|O_EXCL|O_WRONLY,S_IRUSR|S_IWUSR);
                if( fd >= 0 )
                {
                    close(fd);
                    unlink(tmpname);
                    printf("Filesystem is writable\n");
		}else if( errno == EROFS ){
		  char *tmpdir = getenv("TMPDIR");
#ifdef CYG_MANGLING
                        printf("Filesystem is not writable, looking for somewhere else\n");
			if( !tmpdir )
				tmpdir = "c:";
			snprintf(tmpname,256,"%s%s.idx",tmpdir,strrchr(name,'\\'));
#else
			if( !tmpdir )
				tmpdir = "/tmp";
			snprintf(tmpname,256,"%s%s.idx",tmpdir,strrchr(name,'/'));
#endif
			tmpname[255] = 0;
                        printf("Storing index in %s\n",tmpname);
                    if(ADM_fileExist(tmpname))
                    {
                        printf("Index present, loading it\n");
                        return addFile(tmpname);
                    }
                }
        }
        if(tryIndexing(name,tmpname))
        {
                return addFile (tmpname);
        }
        return 0;
      break;
	case WorkBench_FileType:

  		return loadWorbench(name);
#if 0
        case Script_FileType:
                return parseScript(name);
#endif
	case ECMAScript_FileType:
                printf("****** This is an ecmascript, run it with avidemux2 --run yourscript *******\n");
                printf("****** This is an ecmascript, run it with avidemux2 --run yourscript *******\n");
                printf("****** This is an ecmascript, run it with avidemux2 --run yourscript *******\n");
                return 0;
		
                
    default:
      if (type == Unknown_FileType)
	{
	  printf ("\n not identified ...\n");
	}
      else
        GUI_Error_HIG(_("File type identified but no loader support detected..."),
                      _("May be related to an old index file."));
      return 0;
    }

   // check opening was successful
   if (ret == 0) {
     char str[512+1];
     snprintf(str,512,_("Attempt to open %s failed!"), name);
      str[512] = '\0';
      GUI_Error_HIG(str,NULL);
      delete _videos[_nb_video]._aviheader;;
      return 0;
   }

   /* check for resolution */
   if( _nb_video ){
      /* append operation */
      aviInfo info0, infox;
      _videos[   0     ]._aviheader->getVideoInfo (&info0);
      _videos[_nb_video]._aviheader->getVideoInfo (&infox);
      if( info0.width != infox.width || info0.height != infox.height ){
        char str[512+1];
         str[0] = '\0';
         if( info0.width != infox.width )
            strcpy(str,"width");
         if( info0.height != infox.height )
            snprintf(str+strlen(str),512-strlen(str),
              "%sheight%sdifferent between first and this video stream",
                 (strlen(str)?" and ":""),
                 (strlen(str)?" are ":" is ") );
         str[512] = '\0';
         GUI_Error_HIG(str,_("You cannot mix different video dimensions yet. Using the partial video filter later, will not work around this problem. The workaround is:\n1.) \"resize\" / \"add border\" / \"crop\" each stream to the same resolution\n2.) concatinate them together"));
         delete _videos[_nb_video]._aviheader;;
         return 0;
      }
   }
 
  // else update info
  _videos[_nb_video]._aviheader->getVideoInfo (&info);
  _videos[_nb_video]._aviheader->setMyName (name);
  // 1st if it is our first video we update postproc
 if(!_nb_video)
 {
        uint32_t type,value;

        if(!prefs->get(DEFAULT_POSTPROC_TYPE,&type)) type=3;
        if(!prefs->get(DEFAULT_POSTPROC_VALUE,&value)) value=3; 	

	deletePostProc(&_pp );
 	initPostProc(&_pp,info.width,info.height);
	_pp.postProcType=type;
	_pp.postProcStrength=value;
	_pp.forcedQuant=0;
	updatePostProc(&_pp);

	if(_imageBuffer) delete _imageBuffer;
	_imageBuffer=new ADMImage(info.width,info.height);
 	_imageBuffer->_qSize= ((info.width+15)>>4)*((info.height+15)>>4);
	_imageBuffer->quant=new uint8_t[_imageBuffer->_qSize];
	_imageBuffer->_qStride=(info.width+15)>>4;
 }
Example #12
0
/**
    \fn DIA_ocrGen
    \brief Dialog to select input & output files before calling the actual ocr engine
*/
uint8_t DIA_ocrGen(void)
{

  vobSubParam subparam={NULL,0,0};
  char *srtFileName=NULL;
  char *glyphFileName=NULL;
  admGlyph head(16,16);
  char *globalGlyph=NULL;
  uint32_t globalGlyphOn=0;
  ADM_OCR_SOURCE source;
  
  memset(&source,0,sizeof(source));
  
  source.type=ADM_OCR_TYPE_VOBSUB;
  source.subparam=&subparam;
  
  prefs->get(FEATURE_GLOBAL_GLYPH_ACTIVE,&globalGlyphOn);
  if(globalGlyphOn)
  {
     prefs->get(FEATURE_GLOBAL_GLYPH_NAME,&globalGlyph);
     if(!*globalGlyph)
     {
        ADM_dezalloc(globalGlyph);
        globalGlyph=NULL; 
     }
  }

  if(globalGlyph)
  {
    glyphFileName=globalGlyph;
  }
_again:  
  // Fist build a dialogFactory to get input and output files
  diaElemButton   selectIdx(QT_TR_NOOP("Select idx file:"), cb_idx,&subparam,NULL);
  diaElemFile     selectGlyph(1,&glyphFileName,QT_TR_NOOP("Use GlyphSet (optional):"), NULL, QT_TR_NOOP("Select GlyphSet file"));
  diaElemFile     selectSrt(1,&srtFileName,QT_TR_NOOP("Output SRT file"), NULL, QT_TR_NOOP("Save SRT file"));
  
  diaElem *elems[]={&selectIdx,&selectSrt,&selectGlyph};
  
   uint32_t n=3;
   if(globalGlyph)
   {
     n--; // Remove glyph from dialog
   }
  
    if(!diaFactoryRun(QT_TR_NOOP("Select input and ouput files"),n,elems))
        {
          cleanupSub(&source);
          if(srtFileName )ADM_dezalloc(srtFileName);
          srtFileName=NULL;
          destroyGlyphTree(&head);
          return 0;
        }
        if(!ADM_fileExist(subparam.subname))
        {
          GUI_Error_HIG(QT_TR_NOOP("File error"),QT_TR_NOOP("The idx/sub file does not exist."));
          goto _again; 
        }
        if(!srtFileName || !*srtFileName)
        {
          GUI_Error_HIG(QT_TR_NOOP("File error"),QT_TR_NOOP("Please Select a valid output SRT file."));
          goto _again; 
        }
         if(glyphFileName && *glyphFileName)
         {
           if(!ADM_fileExist(glyphFileName))
            {
              GUI_Error_HIG(QT_TR_NOOP("File error"),QT_TR_NOOP("The idx/sub file does not exist."));
              goto _again; 
            }
            // Purge previous glyph set if any
            destroyGlyphTree(&head);
            uint32_t nb;
            printf("[OCR] Loading glyphset :<%s>\n",glyphFileName);
            if(!loadGlyph(glyphFileName,&head,&nb))
            {
              GUI_Error_HIG(QT_TR_NOOP("File error"),QT_TR_NOOP("Cannot load the glyphset file."));
              goto _again;               
            }
            printf("[GLYPH] Found %u glyph\n");
         }
        // We have our SRT and our idx/sub files : Go go go
         
    if(ADM_ocr_engine(source,srtFileName,&head))
    {
        // Save glyph set 
        if(globalGlyph)
        {
          uint32_t nb=1;
           saveGlyph(globalGlyph,&head,nb);
        }
        else
        {
            char *save=NULL;
            uint32_t nb=1;
              diaElemFile     selectSave(1,&save,QT_TR_NOOP("GlyphSet filename"), NULL, QT_TR_NOOP("Save GlyphSet file"));
              diaElem *elems2[]={&selectSave};
            if(diaFactoryRun(QT_TR_NOOP("Save Glyph"),1,elems2))
            {
              saveGlyph(save,&head,nb);
            }
            if(save) ADM_dezalloc(save);
        }
    }

  cleanupSub(&source);
  if(srtFileName )ADM_dezalloc(srtFileName);
  srtFileName=NULL;
  destroyGlyphTree(&head);
  return 1;  
}
Example #13
0
/**
    \fn DIA_ocrDvb
    \brief Dialog to select input & output files before calling the actual ocr engine
*/
uint8_t DIA_ocrDvb(void)
{

  vobSubParam subparam={NULL,0,0};
  char *srtFileName=NULL;
  char *glyphFileName=NULL;
  char *tsFileName=NULL;
  admGlyph head(16,16);
  char *globalGlyph=NULL;
  uint32_t globalGlyphOn=0;
  uint32_t pid=0x96;
  ADM_OCR_SOURCE source;
  
  memset(&source,0,sizeof(source));
  source.type=ADM_OCR_TYPE_TS;
  
  prefs->get(FEATURE_GLOBAL_GLYPH_ACTIVE,&globalGlyphOn);
  if(globalGlyphOn)
  {
     prefs->get(FEATURE_GLOBAL_GLYPH_NAME,&globalGlyph);
     if(!*globalGlyph)
     {
        ADM_dezalloc(globalGlyph);
        globalGlyph=NULL; 
     }
  }

  if(globalGlyph)
  {
    glyphFileName=globalGlyph;
  }
_againX:  
  // Fist build a dialogFactory to get input and output files
  diaElemFile     selectTs(1,&tsFileName,QT_TR_NOOP("Input TS:"), NULL, QT_TR_NOOP("Select TS file"));
  diaElemUInteger selectPid(&pid,QT_TR_NOOP("Subtitle PID:"),0,255);
  diaElemFile     selectGlyph(1,&glyphFileName,QT_TR_NOOP("Use glyphset (optional):"), NULL, QT_TR_NOOP("Select GlyphSet file"));  
  diaElemFile     selectSrt(1,&srtFileName,QT_TR_NOOP("Output SRT file"), NULL, QT_TR_NOOP("Save SRT file"));
  
  diaElem *elems[]={&selectTs,&selectPid,&selectSrt,&selectGlyph};
  
  
   uint32_t n=4;
   if(globalGlyph)
   {
     n--; // Remove glyph from dialog
   }
  
        if( !diaFactoryRun(QT_TR_NOOP("Select input and ouput files"),n,elems))
        {
          cleanupSub(&source);
          if(srtFileName )ADM_dezalloc(srtFileName);
          srtFileName=NULL;
          destroyGlyphTree(&head);
          return 0;
        }
        // TS file exists ?
        if(!ADM_fileExist(tsFileName))
        {
        	  GUI_Error_HIG(QT_TR_NOOP("File error"),QT_TR_NOOP("Please Select a valid TS file."));
        	  goto _againX;
        }
       
        if(!srtFileName || !*srtFileName)
        {
          GUI_Error_HIG(QT_TR_NOOP("File error"),QT_TR_NOOP("Please Select a valid output SRT file."));
          goto _againX; 
        }
         if(glyphFileName && *glyphFileName)
         {
           if(!ADM_fileExist(glyphFileName))
            {
              GUI_Error_HIG(QT_TR_NOOP("File error"),QT_TR_NOOP("The idx/sub file does not exist."));
              goto _againX; 
            }
            // Purge previous glyph set if any
            destroyGlyphTree(&head);
            uint32_t nb;
            printf("[OCR] Loading glyphset :<%s>\n",glyphFileName);
            if(!loadGlyph(glyphFileName,&head,&nb))
            {
              GUI_Error_HIG(QT_TR_NOOP("File error"),QT_TR_NOOP("Cannot load the glyphset file."));
              goto _againX;               
            }
            printf("[GLYPH] Found %u glyph\n");
         }
        // We have our SRT and our TS file
        // Call the OCR engine...
         source.TsFile=ADM_strdup(tsFileName);
         source.TsPid=pid;
         ADM_ocr_engine(source,srtFileName,&head);
        
        // Save glyph set 

        if(globalGlyph)
        {
          uint32_t nb=1;
           saveGlyph(globalGlyph,&head,nb);
        }else
        {
            char *save=NULL;
            uint32_t nb=1;
              diaElemFile     selectSave(1,&save,QT_TR_NOOP("GlyphSet filename"), NULL, QT_TR_NOOP("Save GlyphSet file"));
              diaElem *elems2[]={&selectSave};
            if( diaFactoryRun(QT_TR_NOOP("Save GlyphSet"),1,elems2))
            {
              saveGlyph(save,&head,nb);
            }
            if(save) ADM_dezalloc(save);
        }

  cleanupSub(&source);
  if(srtFileName )ADM_dezalloc(srtFileName);
  srtFileName=NULL;
  
  if(tsFileName )ADM_dezalloc(tsFileName);
  tsFileName=NULL;
  
  destroyGlyphTree(&head);
  return 1;  
}