Пример #1
0
void probe_ffmpeg(info_t *ipipe)
{
    /* to be completed */
    AVFormatContext *lavf_dmx_context = NULL;
    int ret = 0;

    close(ipipe->fd_in);

    TC_INIT_LIBAVCODEC;

    ret = av_open_input_file(&lavf_dmx_context, ipipe->name,
                             NULL, 0, NULL);
    if (ret != 0) {
        tc_log_error(__FILE__, "unable to open '%s'"
                               " (libavformat failure)",
                     ipipe->name);
        ipipe->error = 1;
        return;
    }

    ret = av_find_stream_info(lavf_dmx_context);
    if (ret < 0) {
        tc_log_error(__FILE__, "unable to fetch informations from '%s'"
                               " (libavformat failure)",
                     ipipe->name);
        ipipe->error = 1;
        return;
    }

    translate_info(lavf_dmx_context, ipipe->probe_info);

    av_close_input_file(lavf_dmx_context);
    return;
}
Пример #2
0
float fps(const char *filename)
{
        float result = 0;
	AVFormatContext *pFormatCtx;
	
	// Open video file
	if (av_open_input_file(&pFormatCtx, filename, NULL, 0, NULL))
	  return -1 ; // Couldn't open file
				 
	// Retrieve stream information
	if(av_find_stream_info(pFormatCtx)<0)
	  return -1; // Couldn't find stream information
			
	// Find the first video stream
	int videoStream=-1;
	for(unsigned int i=0; i<pFormatCtx->nb_streams; i++)
	{
		     if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO) 
		     {
			    videoStream=i;
			    break;
		     }
	}
        if(videoStream==-1)
	    return -1; // Didn't find a video stream
	
	int num = (pFormatCtx->streams[videoStream]->r_frame_rate).num;
	int den = (pFormatCtx->streams[videoStream]->r_frame_rate).den;
	result = num/den;

	av_close_input_file(pFormatCtx);
	
	return result;

}
Пример #3
0
int	 av_vid_init(char *file)
{
	int i;

	if (av_open_input_file(&pFormatCtx, file, NULL, 0, NULL)!=0)
		return -1;

	if (av_find_stream_info(pFormatCtx)<0)
		return -1;

	dump_format(pFormatCtx, 0, file, 0);
	videoStream=-1;
	for (i=0; i<pFormatCtx->nb_streams; i++) {
		if (pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO) {
			videoStream=i;
			break;
		}
	}
	if (videoStream==-1)
		return -1;

	pCodecCtx=pFormatCtx->streams[videoStream]->codec;

	pCodec=avcodec_find_decoder(pCodecCtx->codec_id);
	if (pCodec==NULL)
		return -1;

	if (avcodec_open(pCodecCtx, pCodec)<0)
		return -1;

	pFrame=avcodec_alloc_frame();

	return 0;
}
Пример #4
0
EmErrorCode WmaDecoder::Open(const std::string& url)
{
    m_FormatCtx = nullptr;
    int err = av_open_input_file(&m_FormatCtx, url.c_str(), nullptr, 0, nullptr);
    if (err < 0)
        return ErrorCode::DecoderFailedToOpen;

    for (int i = 0; i < m_FormatCtx->nb_streams; ++i) {
        m_CodecCtx = &m_FormatCtx->streams[i]->codec;
        if (m_CodecCtx->codec_type == CODEC_TYPE_AUDIO)
            break;
    }

    av_find_stream_info(m_FormatCtx);
    AVCodec* codec = avcodec_find_decoder(m_CodecCtx->codec_id);
    
    // open it
    if (codec == nullptr || avcodec_open(m_CodecCtx, codec))
        return ErrorCode::DecoderFailedToInit;

    // read info
    m_Channels = m_CodecCtx->channels;
    m_SampleRate = m_CodecCtx->sample_rate;
    m_BitsPerSample = m_CodecCtx->bits_per_sample;
    m_Duration = m_FormatCtx->duration;

    m_UnitIndex = 0;
    m_UnitCount = m_Duration;

    return ErrorCode::Ok;
}
Пример #5
0
/*
    Used to reopen a video if the slower fallback function for seeking is used.
*/
bool CvCapture_FFMPEG::reopen()
{
    if ( filename==NULL ) return false;

#if LIBAVFORMAT_BUILD > 4628
    avcodec_close( video_st->codec );
#else
    avcodec_close( &video_st->codec );
#endif
    av_close_input_file(ic);

    // reopen video
    av_open_input_file(&ic, filename, NULL, 0, NULL);
    av_find_stream_info(ic);
#if LIBAVFORMAT_BUILD > 4628
    AVCodecContext *enc = ic->streams[video_stream]->codec;
#else
    AVCodecContext *enc = &ic->streams[video_stream]->codec;
#endif
    AVCodec *codec = avcodec_find_decoder(enc->codec_id);
    avcodec_open(enc, codec);
    video_st = ic->streams[video_stream];

    // reset framenumber to zero
    picture_pts=0;

    return true;
}
Пример #6
0
jboolean Java_sysu_ss_xu_FFmpeg_avFindStreamInfo( JNIEnv* env, jobject thiz )
{
	if( av_find_stream_info(pFormatCtx) < 0)
		return 0;
	else
		return 1;
}
Пример #7
0
bool Movie::open(const string& filename) {

  av_register_all();

  if (av_open_input_file(&ctx, filename.c_str(), NULL, 0, NULL) != 0) {
    fprintf(stderr, "ERROR: Cannot open file: '%s'.\n", filename.c_str());
    return false;
  }

  if (av_find_stream_info(ctx) < 0) {
    fprintf(stderr, "ERROR: Cannot find stream info.\n");
    return false;
  }
  
  AVCodecContext* codecCtx = ctx->streams[0]->codec;
  AVCodec* codec = avcodec_find_decoder(codecCtx->codec_id);
  if (!codec) {
    fprintf(stderr, "ERROR: Cannot find codec.");
    return false;
  }
  
  if (avcodec_open(codecCtx, codec) < 0) {
    fprintf(stderr, "ERROR: Cannot open codec.");
    return false;
  }

  return true;
}
Пример #8
0
bool FFmpegImportFileHandle::Init()
{
   //FFmpegLibsInst->LoadLibs(NULL,false); //Loaded at startup or from Prefs now

   if (!FFmpegLibsInst->ValidLibsLoaded()) return false;

   av_log_set_callback(av_log_wx_callback);

   int err = ufile_fopen_input(&mFormatContext, mName);
   if (err < 0)
   {
      wxLogError(wxT("FFmpeg : av_open_input_file() failed for file %s"),mName.c_str());
      return false;
   }

   err = av_find_stream_info(mFormatContext);
   if (err < 0)
   {
      wxLogError(wxT("FFmpeg : av_find_stream_info() failed for file %s"),mName.c_str());
      return false;
   }

   InitCodecs();
   return true;
}
Пример #9
0
int FfmpegCamera::PrimeCapture()
{
    Info( "Priming capture from %s", mPath.c_str() );

    // Open the input, not necessarily a file
    if ( av_open_input_file( &mFormatContext, mPath.c_str(), NULL, 0, NULL ) !=0 )
        Fatal( "Unable to open input %s due to: %s", mPath.c_str(), strerror(errno) );

    // Locate stream info from input
    if ( av_find_stream_info( mFormatContext ) < 0 )
        Fatal( "Unable to find stream info from %s due to: %s", mPath.c_str(), strerror(errno) );

    // Find first video stream present
    mVideoStreamId = -1;
    for ( int i=0; i < mFormatContext->nb_streams; i++ )
    {
#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51,2,1)
        if ( mFormatContext->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO )
#else
        if ( mFormatContext->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO )
#endif
        {
            mVideoStreamId = i;
            break;
        }
    }
    if ( mVideoStreamId == -1 )
        Fatal( "Unable to locate video stream in %s", mPath.c_str() );

    mCodecContext = mFormatContext->streams[mVideoStreamId]->codec;

    // Try and get the codec from the codec context
    if ( (mCodec = avcodec_find_decoder( mCodecContext->codec_id )) == NULL )
        Fatal( "Can't find codec for video stream from %s", mPath.c_str() );

    // Open the codec
    if ( avcodec_open( mCodecContext, mCodec ) < 0 )
        Fatal( "Unable to open codec for video stream from %s", mPath.c_str() );

    // Allocate space for the native video frame
    mRawFrame = avcodec_alloc_frame();

    // Allocate space for the converted video frame
    mFrame = avcodec_alloc_frame();

    // Determine required buffer size and allocate buffer
    int pictureSize = avpicture_get_size( PIX_FMT_RGB24, mCodecContext->width, mCodecContext->height );
    mBuffer.size( pictureSize );

    avpicture_fill( (AVPicture *)mFrame, (unsigned char *)mBuffer, PIX_FMT_RGB24, mCodecContext->width, mCodecContext->height);

#if HAVE_LIBSWSCALE
    if ( (mConvertContext = sws_getCachedContext( mConvertContext, mCodecContext->width, mCodecContext->height, mCodecContext->pix_fmt, width, height, PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL )) == NULL )
        Fatal( "Unable to create conversion context for %s", mPath.c_str() );
#else // HAVE_LIBSWSCALE
    Fatal( "You must compile ffmpeg with the --enable-swscale option to use ffmpeg cameras" );
#endif // HAVE_LIBSWSCALE

    return( 0 );
}
Пример #10
0
// sprawdz, czy plik to MP3 i dodaj, je¶li tak
static void checkAddFile(const char *fullname)
{
	AVFormatContext *pFormatCtx = NULL;
	int i = av_open_input_file( &pFormatCtx, fullname, NULL, 0, NULL);
	// Cannot open file
	if ( i != 0 )
		return;
	i = av_find_stream_info( pFormatCtx );
	// No info about opened file
	if ( i < 0 )
	{
		av_close_input_file( pFormatCtx );
		return;
	}
	// wyszukaj strumien audio
	for (i=0; i<pFormatCtx->nb_streams; i++)
	{
		if (pFormatCtx->streams[i]->codec->codec_type == CODEC_TYPE_AUDIO )
		{
			doAction(ACTION_PLAYLIST_ADDFILE, fullname);
			av_close_input_file( pFormatCtx );
			return;
		}
	}
	av_close_input_file( pFormatCtx );
	return;
}
Пример #11
0
/* Fill info structure with data from ffmpeg comments */
static void ffmpeg_info (const char *file_name,
		struct file_tags *info,
		const int tags_sel)
{
	AVFormatParameters ap;
	AVFormatContext *ic;
	int err;
	
	memset (&ap, 0, sizeof(ap));

	if ((err = av_open_input_file(&ic, file_name, NULL, 0, &ap)) < 0) {
		logit ("av_open_input_file() failed (%d)", err);
		return;
	}
	if ((err = av_find_stream_info(ic)) < 0) {
		logit ("av_find_stream_info() failed (%d)", err);
		return;
	}

	if (tags_sel & TAGS_COMMENTS) {
		if (ic->track != 0)
			info->track = ic->track;
		if (ic->title[0] != 0)
			info->title = xstrdup (ic->title);
		if (ic->author[0] != 0)
			info->artist = xstrdup (ic->author);
		if (ic->album[0] != 0)
			info->album = xstrdup (ic->album);
	}

	if (tags_sel & TAGS_TIME)
		info->time = ic->duration >= 0 ? ic->duration / AV_TIME_BASE
			: -1;
}
Пример #12
0
static int startread(sox_format_t * ft)
{
  priv_t * ffmpeg = (priv_t *)ft->priv;
  AVFormatParameters params;
  int ret;
  int i;

  ffmpeg->audio_buf_raw = lsx_calloc(1, (size_t)AVCODEC_MAX_AUDIO_FRAME_SIZE + 32);
  ffmpeg->audio_buf_aligned = ALIGN16(ffmpeg->audio_buf_raw);

  /* Signal audio stream not found */
  ffmpeg->audio_index = -1;

  /* register all CODECs, demux and protocols */
  av_register_all();

  /* Open file and get format */
  memset(&params, 0, sizeof(params));
  if ((ret = av_open_input_file(&ffmpeg->ctxt, ft->filename, NULL, 0, &params)) < 0) {
    lsx_fail("ffmpeg cannot open file for reading: %s (code %d)", ft->filename, ret);
    return SOX_EOF;
  }

  /* Get CODEC parameters */
  if ((ret = av_find_stream_info(ffmpeg->ctxt)) < 0) {
    lsx_fail("ffmpeg could not find CODEC parameters for %s", ft->filename);
    return SOX_EOF;
  }

  /* Now we can begin to play (RTSP stream only) */
  av_read_play(ffmpeg->ctxt);

  /* Find audio stream (FIXME: allow different stream to be selected) */
  for (i = 0; (unsigned)i < ffmpeg->ctxt->nb_streams; i++) {
    AVCodecContext *enc = ffmpeg->ctxt->streams[i]->codec;
    if (enc->codec_type == CODEC_TYPE_AUDIO && ffmpeg->audio_index < 0) {
      ffmpeg->audio_index = i;
      break;
    }
  }

  /* Open the stream */
  if (ffmpeg->audio_index < 0 ||
      stream_component_open(ffmpeg, ffmpeg->audio_index) < 0 ||
      ffmpeg->audio_stream < 0) {
    lsx_fail("ffmpeg could not open CODECs for %s", ft->filename);
    return SOX_EOF;
  }

  /* Copy format info */
  ft->signal.rate = ffmpeg->audio_st->codec->sample_rate;
  ft->encoding.bits_per_sample = 16;
  ft->encoding.encoding = SOX_ENCODING_SIGN2;
  ft->signal.channels = ffmpeg->audio_st->codec->channels;
  ft->signal.length = 0; /* Currently we can't seek; no idea how to get this
		     info from ffmpeg anyway (in time, yes, but not in
		     samples); but ffmpeg *can* seek */

  return SOX_SUCCESS;
}
Пример #13
0
long int getDuration(AVFormatContext *fmt_ctx) {
	int i = 0;
	int audioStream = -1;

	if (av_find_stream_info(fmt_ctx) >= 0) {
		// Find the first audio stream
		for (i = 0; i < fmt_ctx->nb_streams; i++) {
			if (fmt_ctx->streams[i]->codec->codec_type==CODEC_TYPE_AUDIO) {
				audioStream = i;
				break;
			}
		}

		if (audioStream != -1) {
			double divideFactor = (double) 1 / (fmt_ctx->streams[audioStream]->time_base.num / (double) fmt_ctx->streams[audioStream]->time_base.den);
		    long int dur = (long int) (((double) fmt_ctx->streams[audioStream]->duration / divideFactor) * 1000);

		    if (dur == 2147483648) {
		    	return 0;
		    } else {
		        return dur;
		    }
		}
	}

	return duration;
}
Пример #14
0
JNIEXPORT jint JNICALL Java_com_example_restreaming_StreamingHeadlessCamcorder_nativeOpenFromFile(JNIEnv* env, jobject thiz, jstring mediafile)
    {
    __android_log_print(ANDROID_LOG_INFO, "com.example.ffmpegav", "nativeOpenFromFile()");

    avcodec_register_all();
    av_register_all();

    const char* mfileName = (*env)->GetStringUTFChars(env, mediafile, 0);
    if (mfileName == 0)
        {
        __android_log_print(ANDROID_LOG_ERROR, "com.example.ffmpegav", "failed to retrieve media file name");
        return -1;
        }

    __android_log_print(ANDROID_LOG_INFO, "com.example.ffmpegav", "opening %s", mfileName);

    int result = av_open_input_file(&gFormatCtx, mfileName, NULL, 0, NULL);
    (*env)->ReleaseStringUTFChars(env, mediafile, mfileName); //always release the java string reference
    if (result != 0)
        {
        __android_log_print(ANDROID_LOG_ERROR, "com.example.ffmpegav", "av_open_input_file() failed");
        return -2;
        }

    if (av_find_stream_info(gFormatCtx) < 0)
        {
        __android_log_print(ANDROID_LOG_ERROR, "com.example.ffmpegav", "av_find_stream_info() failed");
        return -3;
        }

    return 0;
    }
Пример #15
0
AVFormatContext *
fa_libav_open_format(AVIOContext *avio, const char *url, 
		     char *errbuf, size_t errlen)
{
  AVInputFormat *fmt = NULL;
  AVFormatContext *fctx;
  int err;

  avio_seek(avio, 0, SEEK_SET);

  if((err = av_probe_input_buffer(avio, &fmt, url, NULL, 0, 0)) != 0)
    return fa_libav_open_error(errbuf, errlen,
			       "Unable to probe file", err);

  if(fmt == NULL) {
    snprintf(errbuf, errlen, "Unknown file format");
    return NULL;
  }

  if((err = av_open_input_stream(&fctx, avio, url, fmt, NULL)) != 0)
    return fa_libav_open_error(errbuf, errlen,
			       "Unable to open file as input format", err);

  if(av_find_stream_info(fctx) < 0) {
    av_close_input_stream(fctx);
    return fa_libav_open_error(errbuf, errlen,
			       "Unable to handle file contents", err);
  }

  return fctx;
}
Пример #16
0
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;
}
Пример #17
0
bool K3bFFMpegFile::open()
{
  close();

  // open the file
  int err = av_open_input_file( &d->formatContext, m_filename.local8Bit(), 0, 0, 0 );
  if( err < 0 ) {
    kdDebug() << "(K3bFFMpegFile) unable to open " << m_filename << " with error " << err << endl;
    return false;
  }

  // analyze the streams
  av_find_stream_info( d->formatContext );

  // we only handle files containing one audio stream
  if( d->formatContext->nb_streams != 1 ) {
    kdDebug() << "(K3bFFMpegFile) more than one stream in " << m_filename << endl;
    return false;
  }

  // urgh... ugly
#ifdef FFMPEG_BUILD_PRE_4629
  AVCodecContext* codecContext =  &d->formatContext->streams[0]->codec;
#else
  AVCodecContext* codecContext =  d->formatContext->streams[0]->codec;
#endif
  if( codecContext->codec_type != CODEC_TYPE_AUDIO ) {
    kdDebug() << "(K3bFFMpegFile) not a simple audio stream: " << m_filename << endl;
    return false;
  }

  // get the codec
  d->codec = avcodec_find_decoder(codecContext->codec_id);
  if( !d->codec ) {
    kdDebug() << "(K3bFFMpegFile) no codec found for " << m_filename << endl;
    return false;
  }

  // open the codec on our context
  kdDebug() << "(K3bFFMpegFile) found codec for " << m_filename << endl;
  if( avcodec_open( codecContext, d->codec ) < 0 ) {
    kdDebug() << "(K3bFFMpegDecoderFactory) could not open codec." << endl;
    return false;
  }

  // determine the length of the stream
  d->length = K3b::Msf::fromSeconds( (double)d->formatContext->duration / (double)AV_TIME_BASE );

  if( d->length == 0 ) {
    kdDebug() << "(K3bFFMpegDecoderFactory) invalid length." << endl;
    return false;
  }

  // dump some debugging info
  dump_format( d->formatContext, 0, m_filename.local8Bit(), 0 );

  return true;
}
Пример #18
0
int Libav::findStreamInfo(void)
{
	
#if LIBAVFORMAT_VERSION_MAJOR  < 53
	return av_find_stream_info(pFormatCtx); 
#else
	return avformat_find_stream_info(pFormatCtx,NULL);
#endif
}
Пример #19
0
//return value
//true : success
//false : fail
bool VideoIO::openInputCodec(void)
{
	//open video file
	///TODO : 20byte lost
	if(av_open_input_file(&pFormatCtx, inputFilename, NULL, 0, NULL) != 0)
	{
		fprintf(stderr, "couldn't open file : %s\n", inputFilename);
		return false;	//couldn't open file
	}

	//retrieve stream information
	if(av_find_stream_info(pFormatCtx) < 0)
	{
		fprintf(stderr, "couldn't find stream information\n");
		return false;
	}

	//dump information about file onto standard error
	dump_format(pFormatCtx, 0, inputFilename, 0);

	//find the first video stream
	videoStream = -1;
	for(unsigned int i = 0 ; i < pFormatCtx->nb_streams ; i++)
	{
		if(pFormatCtx->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO)
		{
			videoStream = i;
			break;
		}
	}
	if(videoStream == -1)
	{
		fprintf(stderr, "didn't find a video stream");
		return false;
	}

	//get a pointer to the reading codec context for the video stream
	pInputCodecCtx = pFormatCtx->streams[videoStream]->codec;

	//find the decoder for the video stream(reaing video)
	pInputCodec = avcodec_find_decoder(pInputCodecCtx->codec_id);
	if(pInputCodec == NULL)
	{
		fprintf(stderr, "Unsupported coded!\n");
		return false;	//codec not found
	}

	//open codec
	if(avcodec_open(pInputCodecCtx, pInputCodec) < 0)
	{
		fprintf(stderr, "could not open codec\n");
		return false;
	}

	//success
	return true;
}
Пример #20
0
int get_file_info(FileState *file)
{
    if(av_open_input_file(&file->pFormatCtx, file->fileName, NULL, 0, NULL) != 0)
	return -1;
    if(av_find_stream_info(file->pFormatCtx) < 0)
	return -1;
    dump_format(file->pFormatCtx, 0, file->fileName, 0);
    return 0;
}
int firstVideoStream(AVFormatContext *pFormatCtx) {
  if(av_find_stream_info(pFormatCtx)<0) {
    mexErrMsgTxt("error: Can't get video stream information");
  }
  for(int i=0; i < pFormatCtx->nb_streams; i++)
    if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO)
      return i;
  mexErrMsgTxt("error: Can't find first video stream");
  exit(-1);
}
	int
decoder_init( Decoder *pDecoder ) {
	
	if( av_open_input_file( &pDecoder->pFmtCtx, FILENAME, NULL, 0, NULL ) < 0 )
		return ERROR;

	if( av_find_stream_info( pDecoder->pFmtCtx ) < 0 )
		return ERROR;
	return SUCCESS;
}
Пример #23
0
AVFormatContext *
fa_libav_open_format(AVIOContext *avio, const char *url, 
		     char *errbuf, size_t errlen, const char *mimetype)
{
  AVInputFormat *fmt = NULL;
  AVFormatContext *fctx;
  int err;

  avio_seek(avio, 0, SEEK_SET);
  if(mimetype != NULL) {
    int i;

    for(i = 0; i < sizeof(mimetype2fmt) / sizeof(mimetype2fmt[0]); i++) {
      if(!strcmp(mimetype, mimetype2fmt[i].mimetype)) {
	fmt = av_find_input_format(mimetype2fmt[i].fmt);
	break;
      }
    }
    if(fmt == NULL)
      TRACE(TRACE_DEBUG, "probe", "Don't know mimetype %s, probing instead",
	    mimetype);
  }

  if(fmt == NULL) {

    if((err = av_probe_input_buffer(avio, &fmt, url, NULL, 0, 0)) != 0)
      return fa_libav_open_error(errbuf, errlen,
				 "Unable to probe file", err);

    if(fmt == NULL) {
      snprintf(errbuf, errlen, "Unknown file format");
      return NULL;
    }
  }

  fctx = avformat_alloc_context();
  fctx->pb = avio;

  if((err = avformat_open_input(&fctx, url, fmt, NULL)) != 0) {
    if(mimetype != NULL)
      return fa_libav_open_format(avio, url, errbuf, errlen, NULL);
    return fa_libav_open_error(errbuf, errlen,
			       "Unable to open file as input format", err);
  }

  if(av_find_stream_info(fctx) < 0) {
    av_close_input_stream(fctx);
    if(mimetype != NULL)
      return fa_libav_open_format(avio, url, errbuf, errlen, NULL);
    return fa_libav_open_error(errbuf, errlen,
			       "Unable to handle file contents", err);
  }

  return fctx;
}
Пример #24
0
//#define DUMP_INDEX
int thumbnail_find_stream_info(void *handle, const char* filename)
{
    struct video_frame *frame = (struct video_frame *)handle;
    struct stream *stream = &frame->stream;
    int i;
    if (av_open_input_file(&stream->pFormatCtx, filename, NULL, 0, NULL) != 0) {
        log_print("Coundn't open file %s !\n", filename);
        goto err;
    }
    for (i = 0; i < stream->pFormatCtx->nb_streams; i++) {        
        if (stream->pFormatCtx->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO) {
                      stream->videoStream = i;
            break;
        }
    }
    //thumbnail just need the info of stream, so do not need fast_switch
    stream->pFormatCtx->pb->local_playback = 1;
    
    if (av_find_stream_info(stream->pFormatCtx) < 0) {
        log_print("Coundn't find stream information !\n");
        goto err1;
    }
#ifdef DUMP_INDEX
    int i, j;
    AVStream *pStream;
    log_print("*********************************************\n");
    for (i = 0; i < stream->pFormatCtx->nb_streams; i ++) {
        pStream = stream->pFormatCtx->streams[i];
        if (pStream) {
            for (j = 0; j < pStream->nb_index_entries; j++) {
                log_print("stream[%d]:idx[%d] pos:%llx time:%llx\n", i, j, pStream->index_entries[j].pos, pStream->index_entries[j].timestamp);
            }
        }
    }
    log_print("*********************************************\n");
#endif
    if(stream->videoStream>=0){
        stream->pCodecCtx = stream->pFormatCtx->streams[stream->videoStream]->codec;
        if (stream->pCodecCtx == NULL) {
            log_print("pCodecCtx is NULL !\n");
        }
        
        frame->width = stream->pCodecCtx->width;
        frame->height = stream->pCodecCtx->height;
    }
    return 0;

err1:
    av_close_input_file(stream->pFormatCtx);
err:
    memset(&frame->stream, 0, sizeof(struct stream));

    return -1;
}
Пример #25
0
int
gst_ffmpeg_av_find_stream_info (AVFormatContext * ic)
{
  int ret;

  g_static_mutex_lock (&gst_avcodec_mutex);
  ret = av_find_stream_info (ic);
  g_static_mutex_unlock (&gst_avcodec_mutex);

  return ret;
}
Пример #26
0
int ffmpeg_parse_file(play_para_t *am_p)
{
    AVFormatContext *pFCtx = am_p->pFormatCtx;
    int ret = -1;
    // Open video file
    ret = av_find_stream_info(pFCtx);
    if (ret < 0) {
        log_print("ERROR:Couldn't find stream information, ret=====%d\n", ret);
        return FFMPEG_PARSE_FAILED; // Couldn't find stream information
    }
    return FFMPEG_SUCCESS;
}
Пример #27
0
HRESULT CTMReceiverSrc::Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE *pmt)
{
	//TODO: Open the file using ffmpeg;
	USES_CONVERSION;
	AVCodecContext *pVideoCodecCtx = NULL;
	AVCodec *pVideoCodec = NULL;
	avcodec_register_all();
	av_register_all();
	avformat_network_init();

	int cch = lstrlenW(pszFileName) + 1;
	m_pFileName = new WCHAR[cch];
	if(m_pFileName != NULL)
	{
		CopyMemory(m_pFileName, pszFileName, cch*sizeof(WCHAR));
	}

	m_pFormatContext = avformat_alloc_context();
	int err = avformat_open_input(&m_pFormatContext, W2A(m_pFileName), NULL, NULL);
	if(err != 0)
	{
		return E_FAIL;
	}
	m_pFormatContext->flags |= AVFMT_FLAG_GENPTS;
	m_pFormatContext->flags |= AVFMT_GENERIC_INDEX;
	m_pFormatContext->max_index_size = 99;
	m_pFormatContext->probesize /= 3;
	m_pFormatContext->max_analyze_duration /= 3;

	if(av_find_stream_info(m_pFormatContext) < 0)
	{
		return E_FAIL;
	}

	av_dump_format(m_pFormatContext, 0, W2A(m_pFileName), false);

	for(int i=0; i<m_pFormatContext->nb_streams; i++)
	{
		if(m_pFormatContext->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
		{
			m_videoStreamIndex = i;
			pVideoCodecCtx = m_pFormatContext->streams[i]->codec;
			m_resolution.width = pVideoCodecCtx->width;
			m_resolution.height = pVideoCodecCtx->height;
		}
	}

	//TODO: Start a thread to read the packet.
	m_bReadStream = TRUE;
	DWORD dwThreadId = 0;
	m_readerThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ReaderProc, (LPVOID*)this, 0, &dwThreadId);
	return S_OK;
}
Пример #28
0
int openMovie(const char filePath[])
{
	int i;
	if(gFormatCtx != NULL){
		return -1;
	}
	if(av_open_input_file(&gFormatCtx,filePath,NULL,0,NULL)!=0){
		return -2;
	}
	if(av_find_stream_info(gFormatCtx)<0){
		return -3;
	}

	for(i=0; i< gFormatCtx->nb_streams; i++){
		if(gFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO){
			gVideoStreamIdx = i;
			break;
		}
	}

	if(gVideoStreamIdx == -1){
		return -4;
	}

	gVideoCodecCtx = gFormatCtx->streams[gVideoStreamIdx]->codec;

	gVideoCodec = avcodec_find_decoder(gVideoCodecCtx->codec_id);
	if(gVideoCodec == NULL){
		return -5;
	}

	if(avcodec_open(gVideoCodecCtx, gVideoCodec) <0 ){
		return -6;
	}

	gFrame = avcodec_alloc_frame();
	if(gFrame == NULL){
		return -7;
	}

	gFrameRGB = avcodec_alloc_frame();
	if(gFrameRGB == NULL){
		return -8;
	}

	gPictureSize = avpicture_get_size(PIX_FMT_RGB565LE, gVideoCodecCtx->width, gVideoCodecCtx->height);

	gVideoBuffer = (uint8_t*)(malloc(sizeof(uint8_t)* gPictureSize));
	avpicture_fill ((AVPicture*)gFrameRGB, gVideoBuffer, PIX_FMT_RGB565LE, gVideoCodecCtx->width, gVideoCodecCtx->height);

	return 0;
}
Пример #29
0
int sc_open(struct stream_context *self, const char *filename) {
	int err;

	sc_init(self);
	err = avformat_open_input(&self->format_ctx, filename, NULL, NULL);
	if (err < 0) { return err; }
	err = av_find_stream_info(self->format_ctx);
	if (err < 0) { return err; }

	self->state = STATE_OPEN;

	return 0;
}
Пример #30
0
int Encoder::retrieveStreamInformation(void) {
  int returnCode;

  if (! avFormatContext) {
    systemLog->sysLog(ERROR, "avcodec context format is NULL. call openVideoFile first !");
    return -1;
  }
  returnCode = av_find_stream_info(avFormatContext);
  if (returnCode < 0)
    systemLog->sysLog(ERROR, "cannot retrieve stream information: %s", strerror(errno));

  return returnCode;
}