本文整理汇总了C++中dump_format函数的典型用法代码示例。如果您正苦于以下问题:C++ dump_format函数的具体用法?C++ dump_format怎么用?C++ dump_format使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dump_format函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: av_vid_init
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;
}
开发者ID:UIKit0,项目名称:openlase-1,代码行数:34,代码来源:playvid.c
示例2: dump_format
int Encoder::dumpStreamInformation(void) {
if (! avFormatContext || ! videoFileName) {
systemLog->sysLog(ERROR, "avcodec context format or videoFileName not initialized. call openVideoFile first !");
return -1;
}
dump_format(avFormatContext, 0, videoFileName, false);
return 0;
}
开发者ID:spebsd,项目名称:numb,代码行数:9,代码来源:encoder.cpp
示例3: fprintf
//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;
}
开发者ID:if1live,项目名称:gotoamc,代码行数:60,代码来源:videoIO.cpp
示例4: LOG
void
FFmpegMeta::print(bool isOutFormat)
{
LOG(ffmpeg, trace, "ffmpeg::dump_format() ...");
if (isOutFormat) {
dump_format(_pFormatContext, 0, _pFormatContext->filename, 1);
}
else {
dump_format(_pFormatContext, 0, _pFormatContext->filename, 0);
AVMetadataTag* tag = 0;
LOG(ffmpeg, trace, "ffmpeg::av_metadata_get() ...");
while ((tag = av_metadata_get(_pFormatContext->metadata, "", tag, AV_METADATA_IGNORE_SUFFIX))) {
std::clog << tag->key << ", " << tag->value << std::endl;
// addTag(tag->key, tag->value);
}
}
}
开发者ID:BackupTheBerlios,项目名称:openmm,代码行数:18,代码来源:AvStreamFFmpeg.cpp
示例5: get_file_info
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;
}
开发者ID:pkuembedded,项目名称:player,代码行数:9,代码来源:player4.c
示例6: TRACE
status_t
AVFormatReader::Sniff(int32* _streamCount)
{
TRACE("AVFormatReader::Sniff\n");
BPositionIO* source = dynamic_cast<BPositionIO*>(Source());
if (source == NULL) {
TRACE(" not a BPositionIO, but we need it to be one.\n");
return B_NOT_SUPPORTED;
}
Stream* stream = new(std::nothrow) Stream(source,
&fSourceLock);
if (stream == NULL) {
ERROR("AVFormatReader::Sniff() - failed to allocate Stream\n");
return B_NO_MEMORY;
}
ObjectDeleter<Stream> streamDeleter(stream);
status_t ret = stream->Open();
if (ret != B_OK) {
TRACE(" failed to detect stream: %s\n", strerror(ret));
return ret;
}
delete[] fStreams;
fStreams = NULL;
int32 streamCount = stream->CountStreams();
if (streamCount == 0) {
TRACE(" failed to detect any streams: %s\n", strerror(ret));
return B_ERROR;
}
fStreams = new(std::nothrow) Stream*[streamCount];
if (fStreams == NULL) {
ERROR("AVFormatReader::Sniff() - failed to allocate streams\n");
return B_NO_MEMORY;
}
memset(fStreams, 0, sizeof(Stream*) * streamCount);
fStreams[0] = stream;
streamDeleter.Detach();
#ifdef TRACE_AVFORMAT_READER
dump_format(const_cast<AVFormatContext*>(stream->Context()), 0, "", 0);
#endif
if (_streamCount != NULL)
*_streamCount = streamCount;
return B_OK;
}
开发者ID:RAZVOR,项目名称:haiku,代码行数:54,代码来源:AVFormatReader.cpp
示例7: main
int main(int argc, char *argv[])
{
av_register_all();
AVFormatContext *pFormatCtx;
AVCodecContext *pCodecCtx;
AVCodec *pCodec;
int audioStream = -1;
// Open file
if (av_open_input_file(&pFormatCtx, argv[1], NULL, 0, NULL) != 0)
return -1; // Couldn't open file
printf("opened %s\n", argv[1]);
// Get stream information
if (av_find_stream_info(pFormatCtx) < 0)
return -1; // No stream information found
// Debugging function
dump_format(pFormatCtx, 0, argv[1], 0);
// Find the first audio stream
for (int i = 0; i < pFormatCtx->nb_streams; i++)
{
if (pFormatCtx->streams[i]->codec->codec_type == CODEC_TYPE_AUDIO)
{
audioStream = i;
break;
}
}
if (audioStream == -1)
return -1; // No audio stream found
// Return a pointer to the codec context for the video stream
pCodecCtx = pFormatCtx->streams[audioStream]->codec;
// Find the correct decoder
pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
if (pCodec == NULL)
{
printf("Unsupported codec!\n");
return -1; // Codec not found
}
printf("found codec %d\n", pCodecCtx->codec_id);
// Open correct codec
if (avcodec_open(pCodecCtx, pCodec) < 0)
return -1; // Couldn't open codec
printf("opened codec %d\n", pCodecCtx->codec_id);
}
开发者ID:Bocom,项目名称:prismriver,代码行数:50,代码来源:main.cpp
示例8: av_register_all
int FFMpegEncoder::init(FFMpegEncodeProfile *myProfile)
{
av_register_all();
profile = *myProfile;
videoEncodeBufSize = 1024000;
videoEncodeBuf = (unsigned char*)malloc(videoEncodeBufSize);
if (videoEncodeBuf == NULL)
return ERR_ALLOC_VIDEO_BUF;
audioEncodeBufSize = 4*128*1024;
audioEncodeBuf = (unsigned char*)malloc(audioEncodeBufSize);
if (audioEncodeBuf == NULL)
return ERR_ALLOC_AUDIO_BUF;
pFormatCtx = avformat_alloc_context();
int ret = -1;
ret = configOutput();
if (ret)
{
printf("error configuring output!\n");
return ret;
}
videoStream = NULL;
ret = configVideoStream();
if (ret)
{
printf("error configuring video!\n");
return ret;
}
audioStream = NULL;
ret = configAudioStream();
if (ret)
{
printf("error configuring audio!\n");
return ret;
}
av_set_parameters(pFormatCtx, NULL);
dump_format(pFormatCtx, 0, (char*)profile.outputFilename, 1);
av_write_header(pFormatCtx);
audioClock = 0;
videoClock = 0;
return 0;
//
}
开发者ID:jdzyzh,项目名称:ffmpeg-wrapper,代码行数:50,代码来源:FFMpegEncoder.cpp
示例9: guess_format
bool CFFMPEGLoader::CreateMovie(const char *filename, const AVOutputFormat *format, const AVCodecContext *VideoCon, const AVCodecContext *AudioCon) {
if(!filename)
return false;
AVOutputFormat *fmt;
//*fmt=*format;
fmt = guess_format(NULL, filename, NULL);
pFormatCon = av_alloc_format_context();
if(!pFormatCon) {
cout<<"Error while allocating format context\n";
return false;
}
bOutput=true;
strcpy(pFormatCon->filename,filename);
pFormatCon->oformat=fmt;
pAudioStream=pVideoStream=NULL;
if (fmt->video_codec != CODEC_ID_NONE) {
pVideoStream = add_video_stream(pFormatCon, fmt->video_codec,VideoCon);
}
if (fmt->audio_codec != CODEC_ID_NONE) {
pAudioStream = add_audio_stream(pFormatCon, fmt->audio_codec,AudioCon);
}
if (av_set_parameters(pFormatCon, NULL) < 0) {
cout<<"Invalid output format parameters\n";
return false;
}
if (pVideoStream)
open_stream(pFormatCon, pVideoStream);
if (pAudioStream)
open_stream(pFormatCon, pAudioStream);
dump_format(pFormatCon, 0, filename, 1);
if (!(fmt->flags & AVFMT_NOFILE)) {
if (url_fopen(&pFormatCon->pb, filename, URL_WRONLY) < 0) {
cout<<"Could not open '%s'"<<filename<<endl;
return false;
}
}
/* write the stream header, if any */
av_write_header(pFormatCon);
return true;
}
开发者ID:arpu,项目名称:adscanner,代码行数:49,代码来源:ffmpeg_movie.cpp
示例10: open_file
static AVFormatContext *
open_file(const char *filename)
{
AVFormatContext *afc;
int err = av_open_input_file(&afc, filename, NULL, 0, NULL);
if (!err)
err = av_find_stream_info(afc);
if (err < 0) {
fprintf(stderr, "%s: lavf error %d\n", filename, err);
exit(1);
}
dump_format(afc, 0, filename, 0);
return afc;
}
开发者ID:robclark,项目名称:omapfbplay,代码行数:18,代码来源:omapfbplay.c
示例11: out
status_t
ProducerNode::PrepareToConnect(
const media_source & what,
const media_destination & where,
media_format * format,
media_source * out_source,
char * out_name)
{
out("ProducerNode::PrepareToConnect\n");
if (mOutput.source != what)
return B_MEDIA_BAD_SOURCE;
if (mOutput.destination != media_destination::null)
return B_MEDIA_ALREADY_CONNECTED;
if (format == NULL || out_source == NULL || out_name == NULL)
return B_BAD_VALUE;
#if 0
ASSERT(mOutputEnabled == false);
trace("old format:\n");
dump_format(format);
status_t status;
status = specialize_format_to_inputformat(format);
if (status != B_OK)
return status;
#endif
*out_source = mOutput.source;
strcpy(out_name,mOutput.name);
//mOutput.destination = where; //really now? fixme
return B_OK;
}
开发者ID:BackupTheBerlios,项目名称:nemo,代码行数:40,代码来源:ProducerNode.cpp
示例12: av_find_input_format
void SWDecoder::decodeStream()
{
int res = 0;
if(!res)
{
std::cout << "opening virtual file" << std::endl;
AVInputFormat *pFmt = av_find_input_format("mpegts");
res = av_open_input_file(&mState.pFormatCtx, boost::str(boost::format("dvrdecode://%p") % this).c_str(), pFmt, 0, 0);
if(res)
{
std::cerr << boost::format("Error opening pseudo decoder file:%s") % strerror(errno) << std::endl;
} else
{
std::cout << "finding virtual stream info" << std::endl;
res = av_find_stream_info(mState.pFormatCtx);
if(res)
{
std::cerr << boost::format("Error finding stream info:%s") % strerror(errno) << std::endl;
}
else
{
std::cout << "trying to dump format" << std::endl;
dump_format(mState.pFormatCtx, 0, boost::str(boost::format("dvrdecode://%p") % this).c_str(), false);
std::cout << "recognized format" << std::endl;
}
if(!res)
{
decodeFrames();
}
}
if(mState.pFormatCtx)
{
av_close_input_file(mState.pFormatCtx);
}
}
}
开发者ID:vitmod,项目名称:neutrino-hd-pc-experiments,代码行数:38,代码来源:decodethread.cpp
示例13: open_input_file
static int open_input_file(AVFormatContext **fmt_ctx_ptr, const char *filename)
{
int err, i;
AVFormatContext *fmt_ctx;
fmt_ctx = avformat_alloc_context();
set_context_opts(fmt_ctx, avformat_opts, AV_OPT_FLAG_DECODING_PARAM, NULL);
if ((err = av_open_input_file(&fmt_ctx, filename, iformat, 0, NULL)) < 0) {
print_error(filename, err);
return err;
}
/* fill the streams in the format context */
if ((err = av_find_stream_info(fmt_ctx)) < 0) {
print_error(filename, err);
return err;
}
dump_format(fmt_ctx, 0, filename, 0);
/* bind a decoder to each input stream */
for (i = 0; i < fmt_ctx->nb_streams; i++) {
AVStream *stream = fmt_ctx->streams[i];
AVCodec *codec;
if (!(codec = avcodec_find_decoder(stream->codec->codec_id))) {
fprintf(stderr, "Unsupported codec (id=%d) for input stream %d\n",
stream->codec->codec_id, stream->index);
} else if (avcodec_open(stream->codec, codec) < 0) {
fprintf(stderr, "Error while opening codec for input stream %d\n",
stream->index);
}
}
*fmt_ctx_ptr = fmt_ctx;
return 0;
}
开发者ID:Gemini88,项目名称:xbmc-1,代码行数:38,代码来源:ffprobe.c
示例14: scan_metadata_ffmpeg
int
scan_metadata_ffmpeg(char *file, struct media_file_info *mfi)
{
AVFormatContext *ctx;
const struct metadata_map *extra_md_map;
enum CodecID codec_id;
enum CodecID video_codec_id;
enum CodecID audio_codec_id;
AVStream *video_stream;
AVStream *audio_stream;
int mdcount;
int i;
int ret;
ctx = NULL;
#if LIBAVFORMAT_VERSION_MAJOR >= 53 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVCODEC_VERSION_MINOR >= 3)
ret = avformat_open_input(&ctx, file, NULL, NULL);
#else
ret = av_open_input_file(&ctx, file, NULL, 0, NULL);
#endif
if (ret != 0)
{
DPRINTF(E_WARN, L_SCAN, "Cannot open media file '%s': %s\n", file, strerror(AVUNERROR(ret)));
return -1;
}
ret = av_find_stream_info(ctx);
if (ret < 0)
{
DPRINTF(E_WARN, L_SCAN, "Cannot get stream info: %s\n", strerror(AVUNERROR(ret)));
av_close_input_file(ctx);
return -1;
}
#if 0
/* Dump input format as determined by ffmpeg */
# if LIBAVFORMAT_VERSION_MAJOR >= 52 || (LIBAVFORMAT_VERSION_MAJOR == 52 && LIBAVCODEC_VERSION_MINOR >= 101)
av_dump_format(ctx, 0, file, 0);
# else
dump_format(ctx, 0, file, FALSE);
# endif
#endif
DPRINTF(E_DBG, L_SCAN, "File has %d streams\n", ctx->nb_streams);
/* Extract codec IDs, check for video */
video_codec_id = CODEC_ID_NONE;
video_stream = NULL;
audio_codec_id = CODEC_ID_NONE;
audio_stream = NULL;
for (i = 0; i < ctx->nb_streams; i++)
{
switch (ctx->streams[i]->codec->codec_type)
{
#if LIBAVCODEC_VERSION_MAJOR >= 53 || (LIBAVCODEC_VERSION_MAJOR == 52 && LIBAVCODEC_VERSION_MINOR >= 64)
case AVMEDIA_TYPE_VIDEO:
#else
case CODEC_TYPE_VIDEO:
#endif
if (!video_stream)
{
DPRINTF(E_DBG, L_SCAN, "File has video (stream %d)\n", i);
mfi->has_video = 1;
video_stream = ctx->streams[i];
video_codec_id = video_stream->codec->codec_id;
}
break;
#if LIBAVCODEC_VERSION_MAJOR >= 53 || (LIBAVCODEC_VERSION_MAJOR == 52 && LIBAVCODEC_VERSION_MINOR >= 64)
case AVMEDIA_TYPE_AUDIO:
#else
case CODEC_TYPE_AUDIO:
#endif
if (!audio_stream)
{
audio_stream = ctx->streams[i];
audio_codec_id = audio_stream->codec->codec_id;
}
break;
default:
break;
}
}
if (audio_codec_id == CODEC_ID_NONE)
{
DPRINTF(E_DBG, L_SCAN, "File has no audio streams, discarding\n");
av_close_input_file(ctx);
return -1;
}
/* Common media information */
//.........这里部分代码省略.........
开发者ID:jjtheninth,项目名称:forked-daapd,代码行数:101,代码来源:filescanner_ffmpeg.c
示例15: avdevice_register_all
bool FFmpegDecoder::open(const std::string & filename, FFmpegParameters* parameters)
{
try
{
// Open video file
AVFormatContext * p_format_context = 0;
if (filename.compare(0, 5, "/dev/")==0)
{
avdevice_register_all();
OSG_NOTICE<<"Attempting to stream "<<filename<<std::endl;
AVFormatParameters formatParams;
memset(&formatParams, 0, sizeof(AVFormatParameters));
AVInputFormat *iformat;
formatParams.channel = 0;
formatParams.standard = 0;
#if 1
formatParams.width = 320;
formatParams.height = 240;
#else
formatParams.width = 640;
formatParams.height = 480;
#endif
formatParams.time_base.num = 1;
formatParams.time_base.den = 30;
std::string format = "video4linux2";
iformat = av_find_input_format(format.c_str());
if (iformat)
{
OSG_NOTICE<<"Found input format: "<<format<<std::endl;
}
else
{
OSG_NOTICE<<"Failed to find input format: "<<format<<std::endl;
}
int error = av_open_input_file(&p_format_context, filename.c_str(), iformat, 0, &formatParams);
if (error != 0)
{
std::string error_str;
switch (error)
{
//case AVERROR_UNKNOWN: error_str = "AVERROR_UNKNOWN"; break; // same value as AVERROR_INVALIDDATA
case AVERROR_IO: error_str = "AVERROR_IO"; break;
case AVERROR_NUMEXPECTED: error_str = "AVERROR_NUMEXPECTED"; break;
case AVERROR_INVALIDDATA: error_str = "AVERROR_INVALIDDATA"; break;
case AVERROR_NOMEM: error_str = "AVERROR_NOMEM"; break;
case AVERROR_NOFMT: error_str = "AVERROR_NOFMT"; break;
case AVERROR_NOTSUPP: error_str = "AVERROR_NOTSUPP"; break;
case AVERROR_NOENT: error_str = "AVERROR_NOENT"; break;
case AVERROR_PATCHWELCOME: error_str = "AVERROR_PATCHWELCOME"; break;
default: error_str = "Unknown error"; break;
}
throw std::runtime_error("av_open_input_file() failed : " + error_str);
}
}
else
{
AVInputFormat* av_format = (parameters ? parameters->getFormat() : 0);
AVFormatParameters* av_params = (parameters ? parameters->getFormatParameter() : 0);
if (av_open_input_file(&p_format_context, filename.c_str(), av_format, 0, av_params) !=0 )
throw std::runtime_error("av_open_input_file() failed");
}
m_format_context.reset(p_format_context);
// Retrieve stream info
if (av_find_stream_info(p_format_context) < 0)
throw std::runtime_error("av_find_stream_info() failed");
m_duration = double(m_format_context->duration) / AV_TIME_BASE;
m_start = double(m_format_context->start_time) / AV_TIME_BASE;
// TODO move this elsewhere
m_clocks.reset(m_start);
// Dump info to stderr
dump_format(p_format_context, 0, filename.c_str(), false);
// Find and open the first video and audio streams (note that audio stream is optional and only opened if possible)
findVideoStream();
findAudioStream();
m_video_decoder.open(m_video_stream);
try
{
m_audio_decoder.open(m_audio_stream);
}
catch (const std::runtime_error & error)
{
OSG_WARN << "FFmpegImageStream::open audio failed, audio stream will be disabled: " << error.what() << std::endl;
//.........这里部分代码省略.........
开发者ID:aalex,项目名称:osg,代码行数:101,代码来源:FFmpegDecoder.cpp
示例16: qPrintable
bool DataSource::open() {
if (av_open_input_file(&m_formatCtx,
qPrintable(m_filename),
NULL,
0,
NULL) != 0)
{
DPRINT("can not open file.");
return false;
}
if(av_find_stream_info(m_formatCtx) < 0) {
DPRINT("can not find stream info.");
return false;
}
dump_format(m_formatCtx, 0, 0, 0);
AVCodecContext *codecCtx = NULL;
for (uint i = 0; i < m_formatCtx->nb_streams; i++) {
codecCtx = m_formatCtx->streams[i]->codec;
if (codecCtx->codec_type == CODEC_TYPE_VIDEO) {
m_videoStream = i;
//DPRINT("video stream index: %d - %dx%d", m_videoStream, codecCtx->width, codecCtx->height);
if (!this->openCodec(codecCtx, &m_videoCodec)) {
closeInputFile();
DPRINT("can not open video codec.");
return false;
}
this->m_swsCtx = sws_getContext(codecCtx->width,
codecCtx->height,
codecCtx->pix_fmt,
codecCtx->width,
codecCtx->height,
PIX_FMT_RGB24,
SWS_BICUBIC,
NULL,
NULL,
NULL);
if (this->m_swsCtx == NULL) {
closeInputFile();
DPRINT("can not get swscale context");
return false;
}
m_timeBase = av_q2d(m_formatCtx->streams[m_videoStream]->time_base);
m_rawFrame = avcodec_alloc_frame();
}
else if (codecCtx->codec_type == CODEC_TYPE_AUDIO) {
m_audioStream = i;
if (!this->openCodec(codecCtx, &m_audioCodec)) {
closeInputFile();
DPRINT("can not open audio codec.");
return false;
}
}
}
return true;
}
开发者ID:chris-magic,项目名称:studycode,代码行数:66,代码来源:DataSource.cpp
示例17: decode_thread
int decode_thread(void *arg) {
VideoState *is = (VideoState *)arg;
AVFormatContext *pFormatCtx;
AVPacket pkt1, *packet = &pkt1;
int video_index = -1;
int audio_index = -1;
int i;
is->videoStream=-1;
is->audioStream=-1;
global_video_state = is;
// will interrupt blocking functions if we quit!
url_set_interrupt_cb(decode_interrupt_cb);
// Open video file
if(av_open_input_file(&pFormatCtx, is->filename, NULL, 0, NULL)!=0)
return -1; // Couldn't open file
is->pFormatCtx = pFormatCtx;
// Retrieve stream information
if(av_find_stream_info(pFormatCtx)<0)
return -1; // Couldn't find stream information
// Dump information about file onto standard error
dump_format(pFormatCtx, 0, is->filename, 0);
// Find the first video stream
for(i=0; i<pFormatCtx->nb_streams; i++) {
if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO &&
video_index < 0) {
video_index=i;
}
if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_AUDIO &&
audio_index < 0) {
audio_index=i;
}
}
if(audio_index >= 0) {
stream_component_open(is, audio_index);
}
if(video_index >= 0) {
stream_component_open(is, video_index);
}
if(is->videoStream < 0 || is->audioStream < 0) {
fprintf(stderr, "%s: could not open codecs\n", is->filename);
goto fail;
}
// main decode loop
for(;;) {
if(is->quit) {
break;
}
// seek stuff goes here
if(is->seek_req) {
int stream_index= -1;
int64_t seek_target = is->seek_pos;
if (is->videoStream >= 0) stream_index = is->videoStream;
else if(is->audioStream >= 0) stream_index = is->audioStream;
if(stream_index>=0){
seek_target= av_rescale_q(seek_target, AV_TIME_BASE_Q, pFormatCtx->streams[stream_index]->time_base);
}
if(!av_seek_frame(is->pFormatCtx, stream_index, seek_target, is->seek_flags)) {
fprintf(stderr, "%s: error while seeking\n", is->pFormatCtx->filename);
} else {
if(is->audioStream >= 0) {
packet_queue_flush(&is->audioq);
packet_queue_put(&is->audioq, &flush_pkt);
}
if(is->videoStream >= 0) {
packet_queue_flush(&is->videoq);
packet_queue_put(&is->videoq, &flush_pkt);
}
}
is->seek_req = 0;
}
if(is->audioq.size > MAX_AUDIOQ_SIZE ||
is->videoq.size > MAX_VIDEOQ_SIZE) {
SDL_Delay(10);
continue;
}
if(av_read_frame(is->pFormatCtx, packet) < 0) {
if(url_ferror(&pFormatCtx->pb) == 0) {
SDL_Delay(100); /* no error; wait for user input */
continue;
} else {
break;
}
}
// Is this a packet from the video stream?
if(packet->stream_index == is->videoStream) {
//.........这里部分代码省略.........
开发者ID:chenbk85,项目名称:ffmpeg_tutorial,代码行数:101,代码来源:tutorial07.c
示例18: ts_amux_new
GF_AbstractTSMuxer * ts_amux_new(GF_AVRedirect * avr, u32 videoBitrateInBitsPerSec, u32 width, u32 height, u32 audioBitRateInBitsPerSec) {
GF_AbstractTSMuxer * ts = gf_malloc( sizeof(GF_AbstractTSMuxer));
memset( ts, 0, sizeof( GF_AbstractTSMuxer));
ts->oc = avformat_alloc_context();
ts->destination = avr->destination;
av_register_all();
ts->oc->oformat = GUESS_FORMAT(NULL, avr->destination, NULL);
if (!ts->oc->oformat)
ts->oc->oformat = GUESS_FORMAT("mpegts", NULL, NULL);
assert( ts->oc->oformat);
#if REDIRECT_AV_AUDIO_ENABLED
ts->audio_st = av_new_stream(ts->oc, avr->audioCodec->id);
{
AVCodecContext * c = ts->audio_st->codec;
c->codec_id = avr->audioCodec->id;
c->codec_type = AVMEDIA_TYPE_AUDIO;
/* put sample parameters */
c->sample_fmt = SAMPLE_FMT_S16;
c->bit_rate = audioBitRateInBitsPerSec;
c->sample_rate = avr->audioSampleRate;
c->channels = 2;
c->time_base.num = 1;
c->time_base.den = 1000;
// some formats want stream headers to be separate
if (ts->oc->oformat->flags & AVFMT_GLOBALHEADER)
c->flags |= CODEC_FLAG_GLOBAL_HEADER;
}
#endif
ts->video_st = av_new_stream(ts->oc, avr->videoCodec->id);
{
AVCodecContext * c = ts->video_st->codec;
c->codec_id = avr->videoCodec->id;
c->codec_type = AVMEDIA_TYPE_VIDEO;
/* put sample parameters */
c->bit_rate = videoBitrateInBitsPerSec;
/* resolution must be a multiple of two */
c->width = width;
c->height = height;
/* time base: this is the fundamental unit of time (in seconds) in terms
of which frame timestamps are represented. for fixed-fps content,
timebase should be 1/framerate and timestamp increments should be
identically 1. */
c->time_base.den = STREAM_FRAME_RATE;
c->time_base.num = 1;
c->gop_size = 12; /* emit one intra frame every twelve frames at most */
c->pix_fmt = STREAM_PIX_FMT;
if (c->codec_id == CODEC_ID_MPEG2VIDEO) {
/* just for testing, we also add B frames */
c->max_b_frames = 2;
}
if (c->codec_id == CODEC_ID_MPEG1VIDEO) {
/* Needed to avoid using macroblocks in which some coeffs overflow.
This does not happen with normal video, it just happens here as
the motion of the chroma plane does not match the luma plane. */
c->mb_decision=2;
}
// some formats want stream headers to be separate
if (ts->oc->oformat->flags & AVFMT_GLOBALHEADER)
c->flags |= CODEC_FLAG_GLOBAL_HEADER;
}
//av_set_pts_info(ts->audio_st, 33, 1, audioBitRateInBitsPerSec);
#ifndef AVIO_FLAG_WRITE
/* set the output parameters (must be done even if no
parameters). */
if (av_set_parameters(ts->oc, NULL) < 0) {
fprintf(stderr, "Invalid output format parameters\n");
return NULL;
}
#endif
dump_format(ts->oc, 0, avr->destination, 1);
GF_LOG(GF_LOG_INFO, GF_LOG_MODULE, ("[AVRedirect] DUMPING to %s...\n", ts->destination));
#if (LIBAVCODEC_VERSION_MAJOR<55)
if (avcodec_open(ts->video_st->codec, avr->videoCodec) < 0) {
#else
if (avcodec_open2(ts->video_st->codec, avr->videoCodec, NULL) < 0) {
#endif
GF_LOG(GF_LOG_ERROR, GF_LOG_MODULE, ("[AVRedirect] failed to open video codec\n"));
return NULL;
}
#if REDIRECT_AV_AUDIO_ENABLED
#if (LIBAVCODEC_VERSION_MAJOR<55)
if (avcodec_open(ts->audio_st->codec, avr->audioCodec) < 0) {
#else
if (avcodec_open2(ts->audio_st->codec, avr->audioCodec, NULL) < 0) {
#endif
GF_LOG(GF_LOG_ERROR, GF_LOG_MODULE, ("[AVRedirect] failed to open audio codec\n"));
return NULL;
}
ts->audioMx = gf_mx_new("TS_AudioMx");
#endif
ts->videoMx = gf_mx_new("TS_VideoMx");
ts->tsEncodingThread = gf_th_new("ts_interleave_thread_run");
ts->encode = 1;
ts->audioPackets = NULL;
//.........这里部分代码省略.........
开发者ID:DmitrySigaev,项目名称:gpac-sf,代码行数:101,代码来源:ffmpeg_ts_muxer.c
示例19: switch
//.........这里部分代码省略.........
// One chunk is 10 ms (1/100 of fq)
c->frame_size=4;
c->codec_id = CODEC_ID_PCM_S16LE;break;
case WAV_AAC:
c->extradata=audioextraData;
c->extradata_size= audioextraSize;
c->codec_id = CODEC_ID_AAC;
break;
default:
if(_type==MUXER_MATROSKA)
{
if(ADM_WaveTag_to_lavcodec(audioheader->encoding, &(c->codec_id)))
{
if(audioextraData)
{
c->extradata=audioextraData;
c->extradata_size= audioextraSize;
}
// Put a dummy time increment
c->time_base= fps25;
break;
}
}
printf("Cant mux that ! audio\n");
printf("Cant mux that ! audio\n");
c->codec_id = CODEC_ID_MP2;
return 0;
break;
}
c->codec_type = CODEC_TYPE_AUDIO;
c->bit_rate = audioheader->byterate*8;
c->rc_buffer_size=(c->bit_rate/(2*8)); // 500 ms worth
c->channels = audioheader->channels;
_audioByterate=audioheader->byterate;
}
// /audio
//----------------------
switch(_type)
{
case MUXER_FLV:
case MUXER_PSP:
case MUXER_MP4:
case MUXER_MATROSKA:
oc->mux_rate=10080*1000; // Needed ?
break;
case MUXER_TS:
oc->mux_rate=10080*1000;
break;
case MUXER_DVD:
oc->packet_size=2048;
oc->mux_rate=10080*1000;
break;
case MUXER_VCD:
oc->packet_size=2324;
oc->mux_rate=2352 * 75 * 8;
break;
case MUXER_SVCD:
oc->packet_size=2324;
oc->mux_rate=2*2352 * 75 * 8; // ?
break;
default:
ADM_assert(0);
}
oc->preload=AV_TIME_BASE/10; // 100 ms preloading
oc->max_delay=200*1000; // 500 ms
if (av_set_parameters(oc, NULL) < 0)
{
printf("Lav: set param failed \n");
return 0;
}
if (url_fopen(&(oc->pb), filename, URL_WRONLY) < 0)
{
printf("Lav: Failed to open file :%s\n",filename);
return 0;
}
ADM_assert(av_write_header(oc)>=0);
dump_format(oc, 0, filename, 1);
printf("lavformat mpeg muxer initialized\n");
_running=1;
one=(1000*1000*1000)/_fps1000;
_curDTS=one;
return 1;
}
开发者ID:BackupTheBerlios,项目名称:avidemux-svn,代码行数:101,代码来源:ADM_lavformat.cpp
示例20: SoundSource
//TODO: handle error
SoundSourceFFmpeg::SoundSourceFFmpeg(QString qFilename) : SoundSource(qFilename)
{
AVFormatParameters param;
int i;
QByteArray fname;
packet.data = NULL;
bufferOffset = 0;
bufferSize = 0;
memset(buffer, 0, AVCODEC_MAX_AUDIO_FRAME_SIZE);
fname = qFilename.toLatin1();
FFmpegInit();
qDebug() << "New SoundSourceFFmpeg :" << fname;
/* initialize param to something so av_open_input_file works for raw */
memset(¶m, 0, sizeof(AVFormatParameters));
param.channels = 2;
param.sample_rate = 44100;
iformat = av_find_input_format(fname.constData());
// Open audio file
if(av_open_input_file(&pFormatCtx, fname.constData(), iformat, 0, ¶m)!=0) {
qDebug() << "av_open_input_file: cannot open" << fname;
return;
}
// Retrieve stream information
if(av_find_stream_info(pFormatCtx)<0) {
qDebug() << "av_find_stream_info: cannot open" << fname;
return;
}
//debug only
dump_format(pFormatCtx, 0, fname.constData(), false);
qDebug() << "ffmpeg: using the first audio stream available";
// Find the first video stream
audioStream=-1;
for(i=0; i<pFormatCtx->nb_streams; i++)
if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_AUDIO) {
audioStream=i;
break;
}
if(audioStream==-1) {
qDebug() << "cannot find an audio stream: cannot open" << fname;
return;
}
// Get a pointer to the codec context for the video stream
pCodecCtx=pFormatCtx->streams[audioStream]->codec;
// Find the decoder for the audio stream
if(!(pCodec=avcodec_find_decoder(pCodecCtx->codec_id))) {
qDebug() << "cannot find a decoder for" << fname;
return;
}
qDebug() << "ffmpeg: opening the audio codec";
//avcodec_open is not thread safe
lock();
if(avcodec_open(pCodecCtx, pCodec)<0) {
qDebug() << "avcodec: cannot open" << fname;
return;
}
unlock();
pFrame=avcodec_alloc_frame();
channels = pCodecCtx->channels;
SRATE = pCodecCtx->sample_rate;
qDebug() << "Samplerate: " << SRATE << ", Channels: " << channels << "\n";
if(channels > 2){
qDebug() << "ffmpeg: No support for more than 2 channels!";
return;
}
filelength = (long int) ((double)pFormatCtx->duration * 2 / AV_TIME_BASE * SRATE);
qDebug() << "ffmpeg: filelength: " << filelength << "d -|- duration: " << pFormatCtx->duration << "ld -- starttime: " << pFormatCtx->streams[audioStream]->start_time << "ld -- " << AV_TIME_BASE << " " << pFormatCtx->streams[audioStream]->codec_info_duration << "ld";
}
开发者ID:AlbanBedel,项目名称:mixxx,代码行数:80,代码来源:soundsourceffmpeg.cpp
注:本文中的dump_format函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论