亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ffgrab.cpp

?? mmread funtion In MATLAB code format
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
/***************************************************
This is the main Grabber code.  It uses AVbin and ffmpeg
to capture video and audio from video and audio files.
Because of this, mmread and supporting code is now
distributed under the LGPL.  See

The code supports any number of audio or video streams and
is a cross platform solution to replace DDGrab.cpp.

This code was intended to be used inside of a matlab interface,
but can be used as a generic grabber class for anyone who needs
one.

Copyright 2008 Micah Richert

This file is part of mmread.

mmread is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 3 of
the License, or (at your option) any later version.

mmread is distributed WITHOUT ANY WARRANTY.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public
License along with mmread.  If not, see <http://www.gnu.org/licenses/>.
**************************************************/

#ifdef MATLAB_MEX_FILE
#include "mex.h"
#define FFprintf(...) mexPrintf(__VA_ARGS__)
#else
#define FFprintf(...) printf(__VA_ARGS__)
#endif

//#ifndef mwSize
//#define mwSize int
//#endif

#define DEBUG 0

extern "C" {
	#include <avbin.h>
	#include <libavformat/avformat.h>

	struct _AVbinFile {
	    AVFormatContext *context;
	    AVPacket *packet;
	};

	struct _AVbinStream {
		int type;
		AVFormatContext *format_context;
		AVCodecContext *codec_context;
		AVFrame *frame;
	};
}

#include <stdlib.h>
#include <string.h>
#include <vector>
#include <map>
using namespace std;

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

map<unsigned int,double> keyframes;
unsigned int startDecodingAt;

class Grabber
{
public:
	Grabber(bool isAudio, AVbinStream* stream, bool trySeeking, double rate, int bytesPerWORD, AVbinStreamInfo info, AVbinTimestamp start_time)
	{
		this->stream = stream;
		frameNr = 0;
		packetNr = 0;
		done = false;
		this->bytesPerWORD = bytesPerWORD;
		this->rate = rate;
		startTime = 0;
		stopTime = 0;
		this->isAudio = isAudio;
		this->info = info;
		this->trySeeking = trySeeking;
		this->start_time = start_time>0?start_time:0;
	};

	~Grabber()
	{
		// clean up any remaining memory...
		if (DEBUG) FFprintf("freeing frame data...\n");
		for (vector<uint8_t*>::iterator i=frames.begin();i != frames.end(); i++) free(*i);
	}

	AVbinStream* stream;
	AVbinStreamInfo info;
	AVbinTimestamp start_time;

	vector<uint8_t*> frames;
	vector<unsigned int> frameBytes;
	vector<double> frameTimes;

	vector<unsigned int> frameNrs;

	unsigned int frameNr;
	unsigned int packetNr;
	bool done;
	bool isAudio;
	bool trySeeking;

	int bytesPerWORD;
	double rate;
	double startTime, stopTime;

	int Grab(AVbinPacket* packet)
	{
		if (done) return 0;
		if (!packet->data) return 1;

		frameNr++;
		packetNr++;
		if (DEBUG) FFprintf("frameNr %d %d %d\n",frameNr,packetNr,packet->size);
		int offset=0, len=0;
		double timestamp = (packet->timestamp-start_time)/1000.0/1000.0;
		if (DEBUG) FFprintf("time %lld %lld %lf\n",packet->timestamp,start_time,timestamp);

		// either no frames are specified (capture all), or we have time specified
		if (stopTime)
		{
			if (isAudio)
			{
				// time is being used...
				if (timestamp >= startTime)
				{
					// if we've reached the start...
					offset = max(0,((int)((startTime-timestamp)*rate))*bytesPerWORD);
					len = ((int)((stopTime-timestamp)*rate))*bytesPerWORD;
					// if we have gone past our stop time...

					done = len < 0;
				}
			} else {
				done = stopTime <= timestamp;
				len = (startTime <= timestamp)?0x7FFFFFFF:0;
				if (DEBUG) FFprintf("startTime: %lf, stopTime: %lf, current: %lf, done: %d, len: %d\n",startTime,stopTime,timestamp,done,len);
			}
		} else {
			// capture everything... video or audio
			len = 0x7FFFFFFF;
		}

		if (isAudio)
		{
			if (trySeeking && (len<=0 || done)) return 0;

			uint8_t audiobuf[1024*1024];
			int uint8_tsleft = sizeof(audiobuf);
 			int uint8_tsout = uint8_tsleft;
			int uint8_tsread;
			uint8_t* audiodata = audiobuf;
			if (DEBUG) FFprintf("avbin_decode_audio\n");
			while ((uint8_tsread = avbin_decode_audio(stream, packet->data, packet->size, audiodata, &uint8_tsout)) > 0)
			{
				packet->data += uint8_tsread;
				packet->size -= uint8_tsread;
				audiodata += uint8_tsout;
				uint8_tsleft -= uint8_tsout;
				uint8_tsout = uint8_tsleft;
			}

			int nrBytes = audiodata-audiobuf;
			len = min(len,nrBytes);
			offset = min(offset,nrBytes);

			uint8_t* tmp = (uint8_t*)malloc(len);
			if (!tmp) return 2;

			memcpy(tmp,audiobuf+offset,len);

			frames.push_back(tmp);
			frameBytes.push_back(len);
			frameTimes.push_back(timestamp);

		} else {
			bool skip = false;
			if (frameNrs.size() > 0)
			{
				//frames are being specified
				// check to see if the frame is in our list
				bool foundNr = false;
				unsigned int lastFrameNr = 0;
				for (int i=0;i<frameNrs.size();i++)
				{
					if (frameNrs.at(i) == frameNr) foundNr = true;
					if (frameNrs.at(i) > lastFrameNr) lastFrameNr = frameNrs.at(i);
				}

				done = frameNr > lastFrameNr;
				if (!foundNr) {
					if (DEBUG) FFprintf("Skipping frame %d\n",frameNr);
					skip = true;
				}
			}
			if ((trySeeking && skip && packetNr < startDecodingAt && packetNr != 1) || done ) return 0;

			if (DEBUG) FFprintf("allocate frame %d\n",frames.size());
			uint8_t* videobuf = (uint8_t*)malloc(bytesPerWORD);
			if (!videobuf) return 2;
			if (DEBUG) FFprintf("avbin_decode_video\n");

			if (avbin_decode_video(stream, packet->data, packet->size,videobuf)<=0)
			{
				if (DEBUG) FFprintf("avbin_decode_video FAILED!!!\n");
				// silently ignore decode errors
				frameNr--;
				free(videobuf);
				return 3;
			}

			if (stream->frame->key_frame)
			{
				keyframes[packetNr] = timestamp;
			}

			if (skip || len==0)
			{
				free(videobuf);
				return 0;
			}
			frames.push_back(videobuf);
			frameBytes.push_back(min(len,bytesPerWORD));
			frameTimes.push_back(timestamp);
		}

		return 0;
	}
};

typedef map<int,Grabber*> streammap;

class FFGrabber
{
public:
	FFGrabber();

	int build(char* filename, bool disableVideo, bool disableAudio, bool tryseeking);
	int doCapture();

	int getVideoInfo(unsigned int id, int* width, int* height, double* rate, int* nrFramesCaptured, int* nrFramesTotal, double* totalDuration);
	int getAudioInfo(unsigned int id, int* nrChannels, double* rate, int* bits, int* nrFramesCaptured, int* nrFramesTotal, int* subtype, double* totalDuration);
	void getCaptureInfo(int* nrVideo, int* nrAudio);
	// data must be freed by caller
	int getVideoFrame(unsigned int id, unsigned int frameNr, uint8_t** data, unsigned int* nrBytes, double* time);
	// data must be freed by caller
	int getAudioFrame(unsigned int id, unsigned int frameNr, uint8_t** data, unsigned int* nrBytes, double* time);
	void setFrames(unsigned int* frameNrs, int nrFrames);
	void setTime(double startTime, double stopTime);
	void disableVideo();
	void disableAudio();
	void cleanUp(); // must be called at the end, in order to render anything afterward.

#ifdef MATLAB_MEX_FILE
	void setMatlabCommand(char * matlabCommand);
	void runMatlabCommand(Grabber* G);
#endif
private:
	streammap streams;
	vector<Grabber*> videos;
	vector<Grabber*> audios;

	AVbinFile* file;
	AVbinFileInfo fileinfo;

	bool stopForced;
	bool tryseeking;
	vector<unsigned int> frameNrs;
	double startTime, stopTime;

	char* filename;
	struct stat filestat;


#ifdef MATLAB_MEX_FILE
	char* matlabCommand;
	mxArray* prhs[5];
#endif
};


FFGrabber::FFGrabber()
{
	stopForced = false;
	tryseeking = true;
	file = NULL;
	filename = NULL;

	if (DEBUG) FFprintf("avbin_init\n");
 	if (avbin_init()) FFprintf("avbin_init init failed!!!\n");

	av_log_set_level(AV_LOG_QUIET);
}

void FFGrabber::cleanUp()
{
	if (!file) return; // nothing to cleanup.

	for (streammap::iterator i = streams.begin(); i != streams.end(); i++)
	{
		avbin_close_stream(i->second->stream);
		delete i->second;
	}

 	streams.clear();
 	videos.clear();
 	audios.clear();

 	avbin_close_file(file);
 	file = NULL;

#ifdef MATLAB_MEX_FILE
	if (matlabCommand) free(matlabCommand);
	matlabCommand = NULL;
#endif
}

int FFGrabber::getVideoInfo(unsigned int id, int* width, int* height, double* rate, int* nrFramesCaptured, int* nrFramesTotal, double* totalDuration)
{
	if (!width || !height || !nrFramesCaptured || !nrFramesTotal) return -1;

	if (id >= videos.size()) return -2;
	Grabber* CB = videos.at(id);

	if (!CB) return -1;

	*width  = CB->info.video.width;
	*height = CB->info.video.height;
	*rate = CB->rate;
	*nrFramesCaptured = CB->frames.size();
	*nrFramesTotal = CB->frameNr;

	*totalDuration = fileinfo.duration/1000.0/1000.0;
	if (stopForced) *nrFramesTotal = (int)(-(*rate)*(*totalDuration));

	return 0;
}

int FFGrabber::getAudioInfo(unsigned int id, int* nrChannels, double* rate, int* bits, int* nrFramesCaptured, int* nrFramesTotal, int* subtype, double* totalDuration)
{
	if (!nrChannels || !rate || !bits || !nrFramesCaptured || !nrFramesTotal) return -1;

	if (id >= audios.size()) return -2;
	Grabber* CB = audios.at(id);

	if (!CB) return -1;

	*nrChannels = CB->info.audio.channels;
	*rate = CB->info.audio.sample_rate;
	*bits = CB->info.audio.sample_bits;
	*subtype = CB->info.audio.sample_format;
	*nrFramesCaptured = CB->frames.size();
	*nrFramesTotal = CB->frameNr;

	*totalDuration = fileinfo.duration/1000.0/1000.0;

	return 0;
}

void FFGrabber::getCaptureInfo(int* nrVideo, int* nrAudio)
{
	if (!nrVideo || !nrAudio) return;

	*nrVideo = videos.size();
	*nrAudio = audios.size();
}

// data must be freed by caller
int FFGrabber::getVideoFrame(unsigned int id, unsigned int frameNr, uint8_t** data, unsigned int* nrBytes, double* time)
{
	if (DEBUG) FFprintf("getting Video frame %d\n",frameNr);

	if (!data || !nrBytes) return -1;

	if (id >= videos.size()) return -2;
	Grabber* CB = videos[id];
	if (!CB) return -1;
	if (CB->frameNr == 0) return -2;
	if (frameNr < 0 || frameNr >= CB->frames.size()) return -2;

	uint8_t* tmp = CB->frames[frameNr];
	if (!tmp) return -2;

	*nrBytes = CB->frameBytes[frameNr];
	*time = CB->frameTimes[frameNr];

	*data = tmp;
	CB->frames[frameNr] = NULL;

	return 0;
}

// data must be freed by caller
int FFGrabber::getAudioFrame(unsigned int id, unsigned int frameNr, uint8_t** data, unsigned int* nrBytes, double* time)
{
	if (!data || !nrBytes) return -1;

	if (id >= audios.size()) return -2;
	Grabber* CB = audios[id];
	if (!CB) return -1;
	if (CB->frameNr == 0) return -2;
	if (frameNr < 0 || frameNr >= CB->frames.size()) return -2;

	uint8_t* tmp = CB->frames[frameNr];
	if (!tmp) return -2;

	*nrBytes = CB->frameBytes[frameNr];
	*time = CB->frameTimes[frameNr];

	*data = tmp;
	CB->frames[frameNr] = NULL;

	return 0;
}

void FFGrabber::setFrames(unsigned int* frameNrs, int nrFrames)
{
	if (!frameNrs) return;

	unsigned int minFrame=nrFrames>0?frameNrs[0]:0;

	this->frameNrs.clear();
	for (int i=0; i<nrFrames; i++) this->frameNrs.push_back(frameNrs[i]);

	for (int j=0; j < videos.size(); j++)
	{
		Grabber* CB = videos.at(j);
		if (CB)
		{
			CB->frames.clear();
			CB->frameNrs.clear();
			for (int i=0; i<nrFrames; i++)
			{
				CB->frameNrs.push_back(frameNrs[i]);
				minFrame=frameNrs[i]<minFrame?frameNrs[i]:minFrame;
			}
			CB->frameNr = 0;
			CB->packetNr = 0;
		}
	}

	if (tryseeking && nrFrames > 0)
	{

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品无人区卡一卡二卡三乱码免费卡| 日韩一区欧美一区| 亚洲精品综合在线| 精品第一国产综合精品aⅴ| 色视频一区二区| 激情久久久久久久久久久久久久久久| 亚洲精品乱码久久久久久久久| 久久综合国产精品| 欧美精品v国产精品v日韩精品| 不卡在线观看av| 精品一区二区在线观看| 亚洲国产精品一区二区www在线 | 欧美一区永久视频免费观看| 成人在线视频一区二区| 久久国产免费看| 亚洲综合一二三区| 亚洲欧美偷拍另类a∨色屁股| 欧美成人艳星乳罩| 欧美日韩aaaaaa| 91亚洲精品乱码久久久久久蜜桃| 国产精品资源在线观看| 久久国产精品露脸对白| 亚洲国产日韩精品| 夜夜爽夜夜爽精品视频| 亚洲少妇30p| 国产精品青草久久| 久久久久国产精品免费免费搜索| 日韩午夜精品视频| 91精品国产综合久久精品性色| 日本高清不卡在线观看| 94-欧美-setu| 9l国产精品久久久久麻豆| 国产一区二区调教| 久久99精品久久久久久| 捆绑调教美女网站视频一区| 午夜精品一区二区三区电影天堂| 亚洲在线视频免费观看| 亚洲精品大片www| 亚洲精品国产第一综合99久久 | 久久激情五月激情| 免费观看一级欧美片| 日韩av电影免费观看高清完整版| 午夜激情一区二区三区| 午夜av区久久| 男女性色大片免费观看一区二区| 秋霞午夜av一区二区三区| 日韩二区三区四区| 日本不卡一二三| 看国产成人h片视频| 经典三级视频一区| 国产不卡在线一区| www.亚洲精品| 欧美在线不卡一区| 欧美精品亚洲一区二区在线播放| 欧美剧在线免费观看网站| 91精品国产色综合久久不卡电影| 欧美精品日韩一本| 精品伦理精品一区| 国产视频一区二区在线| 国产精品免费av| 亚洲激情男女视频| 手机精品视频在线观看| 国产主播一区二区| 成人av免费在线| 97精品超碰一区二区三区| 99久久免费精品高清特色大片| 成人性生交大合| 色综合视频一区二区三区高清| 色婷婷国产精品综合在线观看| 色综合亚洲欧洲| 91精品国产综合久久香蕉麻豆 | 欧美在线一区二区三区| 777a∨成人精品桃花网| 久久精品免费在线观看| 亚洲视频你懂的| 日产欧产美韩系列久久99| 国产一区二区女| 99久久综合精品| 欧美在线啊v一区| 精品国产乱码久久| 亚洲欧洲综合另类在线| 人人狠狠综合久久亚洲| 99久久久久久| 日韩美女视频在线| 亚洲欧美综合色| 奇米精品一区二区三区在线观看 | 日韩精品一区国产麻豆| 91精品国产色综合久久| 精品少妇一区二区三区在线播放| 久久久久久黄色| 亚洲人123区| 亚洲成人一区二区在线观看| 美女网站一区二区| 色噜噜狠狠色综合中国| 日本一区二区成人| 日韩国产欧美视频| 久久人人97超碰com| 久久综合av免费| 亚洲成人黄色小说| 成人久久视频在线观看| 欧美一区二区三区在线| 国产精品欧美一区二区三区| 日韩**一区毛片| 一本一道久久a久久精品| 欧美成人r级一区二区三区| 一区二区视频在线看| 国产精品911| 日韩欧美国产不卡| 亚洲国产精品久久人人爱蜜臀| 成人午夜av电影| 欧美精品一区二区三区蜜桃| 五月婷婷久久丁香| 色综合色狠狠综合色| 国产欧美一区在线| 韩国av一区二区| 日韩一区二区麻豆国产| 香蕉乱码成人久久天堂爱免费| 99久久综合色| 国产精品久久久久精k8 | 欧美大肚乱孕交hd孕妇| 亚洲午夜在线电影| 不卡电影一区二区三区| 国产日产欧美一区| 国产精品一区二区你懂的| 欧美电影免费观看完整版| 日本欧美肥老太交大片| 欧美精品日韩综合在线| 午夜精品成人在线视频| 欧美色倩网站大全免费| 亚洲激情综合网| 日本福利一区二区| 亚洲与欧洲av电影| 欧美亚州韩日在线看免费版国语版| 一区精品在线播放| av在线不卡免费看| 日韩理论片中文av| 色综合久久综合网欧美综合网| 中文字幕在线不卡一区| 日韩毛片视频在线看| 国产日韩欧美麻豆| 欧美日韩免费在线视频| 一区二区三区四区av| 欧美系列日韩一区| 五月天国产精品| 日韩精品最新网址| 国产一区日韩二区欧美三区| 久久免费精品国产久精品久久久久| 狠狠色2019综合网| 国产精品欧美久久久久一区二区 | 亚洲国产高清不卡| 成人丝袜18视频在线观看| 中文字幕中文字幕中文字幕亚洲无线| 97精品电影院| 亚洲成av人片| 日韩你懂的在线播放| 国产精品亚洲专一区二区三区 | 国产人成亚洲第一网站在线播放| 国产精品自拍av| 亚洲色图视频网| 欧美日韩精品欧美日韩精品| 麻豆91免费看| 久久久久久久精| 色综合久久久久久久久| 视频在线观看一区| 久久精品欧美一区二区三区麻豆| 成年人午夜久久久| 日韩精品成人一区二区在线| 久久久影院官网| 色婷婷久久综合| 麻豆视频观看网址久久| 亚洲国产精品精华液2区45| 色乱码一区二区三区88| 老司机精品视频一区二区三区| 欧美国产禁国产网站cc| 99re66热这里只有精品3直播 | 中文字幕一区二区三区在线观看| 亚洲午夜免费福利视频| 91精品国产综合久久福利软件| 国产一区二区不卡| 亚洲人成精品久久久久| 欧美大片一区二区| 91亚洲国产成人精品一区二三| 日欧美一区二区| 国产精品久久夜| 91精品国产综合久久久久久久久久 | 欧美96一区二区免费视频| 国产精品视频一二| 538在线一区二区精品国产| 国产经典欧美精品| 香蕉成人啪国产精品视频综合网| 久久亚洲二区三区| 欧美日韩免费一区二区三区| 国产精品一区二区在线播放| 一区二区三区 在线观看视频| 欧美精品一区二| 欧美午夜精品理论片a级按摩| 国产成人av福利| 免费视频最近日韩| 亚洲成人av一区| 中文字幕亚洲精品在线观看|