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;
}
Example #2
0
// virtual
SimpleVideo::~SimpleVideo()
{
	delete[] m_aBuffer;
	av_free( m_pFrame );
	avcodec_close( m_pCodecContext );
	av_close_input_file( m_pFormatContext );
}
FfmpegCamera::~FfmpegCamera()
{
    av_freep( &mFrame );
    av_freep( &mRawFrame );
    
#if HAVE_LIBSWSCALE
    if ( mConvertContext )
    {
        sws_freeContext( mConvertContext );
        mConvertContext = NULL;
    }
#endif

    if ( mCodecContext )
    {
       avcodec_close( mCodecContext );
       mCodecContext = NULL; // Freed by av_close_input_file
    }
    if ( mFormatContext )
    {
#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(53, 4, 0)
        av_close_input_file( mFormatContext );
#else
        avformat_close_input( &mFormatContext );
#endif
        mFormatContext = NULL;
    }

	if ( capture )
	{
		Terminate();
	}
}
FFmpegMeta::~FFmpegMeta()
{
    if (_pFormatContext) {
        if (_useAvOpenInputStream) {
            LOG(ffmpeg, trace, "ffmpeg::av_close_input_stream() ...");
            // free AVFormatContext
            av_close_input_stream(_pFormatContext);
        }
        else {
            LOG(ffmpeg, trace, "ffmpeg::av_close_input_file() ...");
            av_close_input_file(_pFormatContext);
        }
    }
    if (_pInputFormat) {
//         LOG(ffmpeg, trace, "ffmpeg::av_freep(AVInputFormat*) ...");
//         av_freep(_pInputFormat);
    }
    if (_pIoContext) {
//         LOG(ffmpeg, trace, "ffmpeg::av_freep(ByteIOContext*) ...");
//         av_freep(_pIoContext);
    }
    if (_pIoBuffer) {
        delete _pIoBuffer;
        _pIoBuffer = 0;
    }
}
Example #5
0
  void close()
  {
    if (m_scale_buf)
      {
        delete[] m_scale_buf;
        m_scale_buf = 0;
      }

    if (m_frame != 0)
      {
        av_free(m_frame);
        m_frame = 0;
      }

    if ( video_stream_index != -1 )
      {
        close_stream(av_fc, video_stream_index);
        video_stream_index = -1;
      }

    if ( av_fc != 0 )
      {
        av_close_input_file(av_fc);
        av_fc = 0;
      }

    file_name           = "";
    m_width = m_height  = m_num_frames = 0;
    m_scale_buf_size    = 0;
    m_current_timestamp = 0;
    m_start_time        = 0;
  }
Example #6
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;
}
Example #7
0
FilePtr openAVCustom(const char *name, void *user_data,
                     int (*read_packet)(void *user_data, uint8_t *buf, int buf_size),
                     int (*write_packet)(void *user_data, uint8_t *buf, int buf_size),
                     int64_t (*seek)(void *user_data, int64_t offset, int whence))
{
    FilePtr file;

    if(!done_init) {av_register_all();
    av_log_set_level(AV_LOG_ERROR);
    done_init = 1;}

    if(!name)
        name = "";

    file = (FilePtr)calloc(1, sizeof(*file));
    if(file && (file->FmtCtx=avformat_alloc_context()) != NULL)
    {
        file->FmtCtx->pb = avio_alloc_context(NULL, 0, 0, user_data,
                                              read_packet, write_packet, seek);
        if(file->FmtCtx->pb && avformat_open_input(&file->FmtCtx, name, NULL, NULL) == 0)
        {
            if(avformat_find_stream_info(file->FmtCtx, NULL) >= 0)
                return file;
        }
        av_close_input_file(file->FmtCtx);
    }

    free(file); 
    return NULL;
}
Example #8
0
static void avhelper_close_input_file( AVFormatContext *s ) {
#if LIBAVCODEC_BUILD > 5400
	avformat_close_input(&s);
#else
	av_close_input_file(s);
#endif
}
static void icvCloseAVI_FFMPEG( CvCaptureAVI_FFMPEG* capture )
{
    //cvFree( (void**)&(capture->entries) );
        
    if( capture->picture )
    av_free(capture->picture);

    if( capture->video_st )
    {
#if LIBAVFORMAT_BUILD > 4628
        avcodec_close( capture->video_st->codec );
#else
        avcodec_close( &capture->video_st->codec );
#endif
        capture->video_st = NULL;
    }

    if( capture->ic )
    {
        av_close_input_file(capture->ic);
        capture->ic = NULL;
    }

    if( capture->rgb_picture.data[0] )
        cvFree( &capture->rgb_picture.data[0] );

    memset( &capture->frame, 0, sizeof(capture->frame));
}
FFmpegVideo::~FFmpegVideo()
{
	// Free the RGB image
	av_free(buffer);
	av_free(pFrameBGR);
	av_free(pFrameRGB);

	// Free the YUV frame
	av_free(pFrameOri);

	// Close the codec
	
	if(pCodecCtx)
		avcodec_close(pCodecCtx);
	

	// Close the video file
	//for(i = 0; i < pFormatCtx->nb_streams; i++) 
	//{            
	//	av_freep(&pFormatCtx->streams[i]->codec);                       
	//	av_freep(&pFormatCtx->streams[i]);                           
	//}
	if(pFormatCtx)\
		av_close_input_file(pFormatCtx); 

	if(imageFrame)
		delete imageFrame;


}
Example #11
0
static GF_Err FFD_CloseService(GF_InputService *plug)
{
	FFDemux *ffd = (FFDemux*)plug->priv;

	ffd->is_running = 0;

#if FF_API_CLOSE_INPUT_FILE
	if (ffd->ctx) av_close_input_file(ffd->ctx);
#else
	if (ffd->ctx) avformat_close_input(&ffd->ctx);
#endif

	ffd->ctx = NULL;
	ffd->audio_ch = ffd->video_ch = NULL;
	ffd->audio_run = ffd->video_run = GF_FALSE;

	if (ffd->dnload) {
		if (ffd->is_running) {
			while (!ffd->is_running) gf_sleep(1);
			ffd->is_running = 0;
		}
		gf_service_download_del(ffd->dnload);
		ffd->dnload = NULL;
	}
	if (ffd->buffer) gf_free(ffd->buffer);
	ffd->buffer = NULL;

	gf_service_disconnect_ack(ffd->service, NULL, GF_OK);
#ifdef FFMPEG_DUMP_REMOTE
	if (ffd->outdbg) gf_fclose(ffd->outdbg);
#endif
	return GF_OK;
}
Example #12
0
void QVideoDecoder::close()
{
    if(!ok)
        return;

    // Free the RGB image
    if(buffer)
        delete [] buffer;

    // Free the YUV frame
    if(pFrame)
        av_free(pFrame);

    // Free the RGB frame
    if(pFrameRGB)
        av_free(pFrameRGB);

    // Close the codec
    if(pCodecCtx)
        avcodec_close(pCodecCtx);

    // Close the video file
    if(pFormatCtx)
        av_close_input_file(pFormatCtx);

    InitVars();
}
	void
decoder_release( Decoder *pDecoder )
{
	avcodec_close( pDecoder->pCdcCtx );
	av_close_input_file( pDecoder->pFmtCtx );
	free( pDecoder );
}
Example #14
0
int av_deinit(void)
{
	av_free(pFrame);

	// Close the codec
	avcodec_close(pCodecCtx);
	avcodec_close(pACodecCtx);

	audio_resample_close(resampler);

	// Close the video file
	av_close_input_file(pFormatCtx);
	av_close_input_file(pAFormatCtx);

	return 0;
}
Example #15
0
/* FIXME: probably some more stuff to free here */
static void
ff_cleanup (GeglChantO *o)
{
    Priv *p = (Priv*)o->chant_data;
    if (p)
    {
        if (p->codec_name)
            g_free (p->codec_name);
        if (p->loadedfilename)
            g_free (p->loadedfilename);

        if (p->enc)
            avcodec_close (p->enc);
        if (p->ic)
            av_close_input_file (p->ic);
        if (p->lavc_frame)
            av_free (p->lavc_frame);

        p->enc = NULL;
        p->ic = NULL;
        p->lavc_frame = NULL;
        p->codec_name = NULL;
        p->loadedfilename = NULL;
    }
}
Example #16
0
FFmpegImportFileHandle::~FFmpegImportFileHandle()
{
#ifdef EXPERIMENTAL_OD_FFMPEG
   //ODDecodeFFmpegTask takes ownership and deltes it there.
   if(!mUsingOD)
   {
#endif
   if (FFmpegLibsInst->ValidLibsLoaded())
   {
      if (mFormatContext) av_close_input_file(mFormatContext);
      av_log_set_callback(av_log_default_callback);
   }

   for (int i = 0; i < mNumStreams; i++)
   {
      if (mScs[i]->m_decodedAudioSamples != NULL)
         av_free(mScs[i]->m_decodedAudioSamples);

      delete mScs[i];
   }
   free(mScs);
#ifdef EXPERIMENTAL_OD_FFMPEG
   }//mUsingOD
#endif


   delete mStreamInfo;

   DropFFmpegLibs();
}
Example #17
0
void CvCapture_FFMPEG::close()
{
    if( picture )
    av_free(picture);

    if( video_st )
    {
#if LIBAVFORMAT_BUILD > 4628
        avcodec_close( video_st->codec );
#else
        avcodec_close( &video_st->codec );
#endif
        video_st = NULL;
    }

    if( ic )
    {
        av_close_input_file(ic);
        ic = NULL;
    }

    if( rgb_picture.data[0] )
        cvFree( &rgb_picture.data[0] );

    // free last packet if exist
    if (packet.data) {
        av_free_packet (&packet);
    }


    init();
}
Example #18
0
static void andzop_finish() {
    int l_i;
    int l_mbH;
    LOGI(10, "andzop_finish is called");
    for (l_i = 0; l_i < gNumOfVideoFiles; ++l_i) {
	l_mbH = (gVideoCodecCtxList[l_i]->height + 15) / 16;
	/*close the video codec*/
	avcodec_close(gVideoCodecCtxList[l_i]);
	/*close the video file*/
	av_close_input_file(gFormatCtxList[l_i]);
#ifdef SELECTIVE_DECODING
	free_selected_decoding_fields(l_i, l_mbH);
#endif 
#if defined(SELECTIVE_DECODING) || defined(NORM_DECODE_DEBUG)
	/*close all dependency files*/
	fclose(gVideoCodecCtxList[l_i]->g_gopF);
#endif
    }
    free(gFormatCtxList);
    free(gFormatCtxDepList);
    free(gVideoStreamIndexList);
    free(gVideoCodecCtxDepList);
    free(gVideoCodecCtxList);
    free(gVideoPacketQueueList);
    LOGI(10, "clean up done");
}
Example #19
0
FilePtr openAVData(const char *name, char *buffer, size_t buffer_len)
{
    FilePtr file;

    if(!done_init) {av_register_all();
    av_log_set_level(AV_LOG_ERROR);
    done_init = 1;}

    if(!name)
        name = "";

    file = (FilePtr)calloc(1, sizeof(*file));
    if(file && (file->FmtCtx=avformat_alloc_context()) != NULL)
    {
        file->membuf.buffer = buffer;
        file->membuf.length = buffer_len;
        file->membuf.pos = 0;

        file->FmtCtx->pb = avio_alloc_context(NULL, 0, 0, &file->membuf,
                                              MemData_read, MemData_write,
                                              MemData_seek);
        if(file->FmtCtx->pb && avformat_open_input(&file->FmtCtx, name, NULL, NULL) == 0)
        {
            if(avformat_find_stream_info(file->FmtCtx, NULL) >= 0)
                return file;
        }
        av_close_input_file(file->FmtCtx);
    }

    free(file);
    return NULL;
}
Example #20
0
static void destructor(void *arg)
{
	struct vidsrc_st *st = arg;

	if (st->run) {
		st->run = false;
		pthread_join(st->thread, NULL);
	}

	if (st->sws)
		sws_freeContext(st->sws);

	if (st->ctx && st->ctx->codec)
		avcodec_close(st->ctx);

	if (st->ic) {
#if LIBAVFORMAT_VERSION_INT >= ((53<<16) + (21<<8) + 0)
		avformat_close_input(&st->ic);
#else
		av_close_input_file(st->ic);
#endif
	}

	mem_deref(st->vs);
}
Example #21
0
void closeAVFile(FilePtr file)
{
    size_t i;

    if(!file) return;

    for(i = 0;i < file->StreamsSize;i++)
    {
        StreamPtr stream = file->Streams[i];

        while(stream->Packets)
        {
            struct PacketList *self;

            self = stream->Packets;
            stream->Packets = self->next;

            av_free_packet(&self->pkt);
            av_free(self);
        }

        avcodec_close(stream->CodecCtx);
        av_free(stream->DecodedData);
        free(stream);
    }
    free(file->Streams);

    av_close_input_file(file->FmtCtx);
    free(file);
}
Example #22
0
int CFfmpeg::Close(void)
{
	if(acodec1)
	{
		avcodec_close(acodec1);
		avcodec_close(ast1->codec);
		ring_buffer_free(&adecrbuffer1);
	}
	if(acodec2)
	{
		avcodec_close(acodec2);
		avcodec_close(ast2->codec);
		ring_buffer_free(&adecrbuffer2);
	}
	if(infmt_ctx)
	{
		av_close_input_file(infmt_ctx);
		infmt_ctx = NULL;
	}
	if(oc)
	{
		av_write_trailer(oc);
		avformat_free_context(oc);
		oc = NULL;
	}
	if(bsfc)
	{
		av_bitstream_filter_close(bsfc);
	}
	
	return 0;
}
FfmpegCamera::~FfmpegCamera()
{
    av_freep( &mFrame );
    av_freep( &mRawFrame );
    
    if ( mConvertContext )
    {
        sws_freeContext( mConvertContext );
        mConvertContext = NULL;
    }
    if ( mCodecContext )
    {
       avcodec_close( mCodecContext );
       mCodecContext = NULL; // Freed by av_close_input_file
    }
    if ( mFormatContext )
    {
        av_close_input_file( mFormatContext );
        mFormatContext = NULL;
    }

	if ( capture )
	{
		Terminate();
	}
}
Example #24
0
void
eiio_video_close(eiio_video_t **video)
{
	if ((*video)->format) {
		av_close_input_file((*video)->format);
		(*video)->format = NULL;
	}
	if ((*video)->codec) {
		avcodec_close((*video)->codec);
		(*video)->codec = NULL;
	}
	if ((*video)->frame) {
		av_free((*video)->frame);
		(*video)->frame = NULL;
	}
	if ((*video)->frame_rgb24) {
		av_free((*video)->frame_rgb24);
		(*video)->frame_rgb24 = NULL;
	}
	if ((*video)->frame_buffer) {
		av_free((*video)->frame_buffer);
		(*video)->frame_buffer = NULL;
	}
	if ((*video)->sws) {
		sws_freeContext((*video)->sws);
		(*video)->sws = NULL;
	}
	free(*video);
	*video = NULL;
}
Example #25
0
static GF_Err FFD_CloseService(GF_InputService *plug)
{
	FFDemux *ffd = plug->priv;

	ffd->is_running = 0;

	if (ffd->ctx) av_close_input_file(ffd->ctx);
	ffd->ctx = NULL;
	ffd->audio_ch = ffd->video_ch = NULL;
	ffd->audio_run = ffd->video_run = 0;

	if (ffd->dnload) {
		if (ffd->is_running) {
			while (!ffd->is_running) gf_sleep(1);
			ffd->is_running = 0;
		}
		gf_term_download_del(ffd->dnload);
		ffd->dnload = NULL;
	}
	if (ffd->buffer) gf_free(ffd->buffer);
	ffd->buffer = NULL;

	gf_term_on_disconnect(ffd->service, NULL, GF_OK);
#ifdef FFMPEG_DUMP_REMOTE
	if (ffd->outdbg) fclose(ffd->outdbg);
#endif
	return GF_OK;
}
// Close a previously opened decoder job.
void DLL CloseDecoderJob(DecoderJob &jobSpec) {
	if (!jobSpec.IsValid) return;

	av_free(jobSpec.pFrame);// Free the YUV frame
	avcodec_close(jobSpec.pCodecCtx); // Close the codec
	av_close_input_file(jobSpec.pFormatCtx);// Close the video file
}
Example #27
0
void CFFMPEGLoader::Delete() {
    for(UINT i=0; i<FFMPEG_PACKET_MAX_SIZE; i++) {
        if(pktLastAudio[i].data)
            av_free_packet(&pktLastAudio[i]);
        if(pktLastVideo[i].data)
            av_free_packet(&pktLastVideo[i]);
    }
    if (pVideoStream)
        avcodec_close(pVideoStream->codec);
    if (pAudioStream)
        avcodec_close(pAudioStream->codec);
    if(pFrameRGB!=NULL)
        av_free(pFrameRGB);
    if(pFrame!=NULL)
        av_free(pFrame);
    if(pVCodecCon!=NULL)
        avcodec_close(pVCodecCon);
    if(pFormatCon!=NULL) {
        if(!bOutput)
            av_close_input_file(pFormatCon);
        else {
            if (!(pFormatCon->oformat->flags & AVFMT_NOFILE)) {
                /* close the output file */
#ifndef WIN32
                url_fclose(pFormatCon->pb);
#else
                url_fclose(&pFormatCon->pb);
#endif
            }
            av_free(pFormatCon);
        }
    }
}
Example #28
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;

}
Example #29
0
void FFMpegDecoder::close()
{
  m_audio_stream = 0;
  m_file_size = 0;

  if (m_buffer) {
    av_free(m_buffer);
    m_buffer = 0 ;
  }
  
  if (m_frame) {
    av_free(m_frame);
    m_frame = 0;
  }

  if (m_codec_ctx) {
    avcodec_close(m_codec_ctx);
    m_codec_ctx = 0;
  }

  if (m_format) {
    av_close_input_file(m_format);
    m_format = 0;
  }
}
Example #30
0
void VideoLayer::close() {
  if(frame_number!=0) {
	func("free packet");
    av_free_packet(&pkt);
  }

  if(video_codec_ctx)
    if(video_codec_ctx->codec) {
	func("close video codec");
      avcodec_close(video_codec_ctx);
  }
  
  if(audio_codec_ctx) 
    if(audio_codec_ctx->codec) {
	func("close audio codec");
      avcodec_close(audio_codec_ctx);
    if(audio_buf) {
	func("free audio buffer");
	 free(audio_buf);
	}
  }

#ifdef HAVE_LIB_SWSCALE
  sws_freeContext(img_convert_ctx);
#endif
  
  if(avformat_context) {
    av_close_input_file(avformat_context);
  }
//  free_fifo();
  if(rgba_picture) free_picture(rgba_picture);
  if(deinterlace_buffer) free(deinterlace_buffer);
}