From 31bacb9c5d7e66ddc2403520ee60f76205f64937 Mon Sep 17 00:00:00 2001 From: Denis Loh Date: Tue, 27 Oct 2009 21:24:59 +0100 Subject: I forgot two files :) --- misc/avdetector.cpp | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 misc/avdetector.cpp (limited to 'misc/avdetector.cpp') diff --git a/misc/avdetector.cpp b/misc/avdetector.cpp new file mode 100644 index 0000000..d66988e --- /dev/null +++ b/misc/avdetector.cpp @@ -0,0 +1,66 @@ +/* + * File: avdetector.cpp + * Author: savop + * + * Created on 26. Oktober 2009, 13:01 + */ + +#include "avdetector.h" +extern "C" { +#include +#include +} + +using namespace std; + +int cAudioVideoDetector::detectVideoProperties(cUPnPResource* Resource, const char* Filename){ +// // Register avformat + av_register_all(); + + AVFormatContext *FormatCtx = NULL; + if(av_open_input_file(&FormatCtx, Filename, NULL, 0, NULL)){ + ERROR("AVDetector: Error while opening file %s", Filename); + return -1; + } + + if(av_find_stream_info(FormatCtx)<0){ + ERROR("AVDetector: Cannot find the stream information"); + return -1; + } + +#ifdef DEBUG + dump_format(FormatCtx, 0, Filename, 0); +#endif + + unsigned int i; int videoStream = -1; + + AVCodecContext *CodecCtx = NULL; + for(i = 0; i < FormatCtx->nb_streams; i++){ + if(FormatCtx->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO){ + videoStream = i; + break; + } + } + if(videoStream == -1){ + ERROR("AVDetector: No video stream found"); + return -1; + } + + CodecCtx = FormatCtx->streams[videoStream]->codec; + + AVCodec* Codec = avcodec_find_decoder(CodecCtx->codec_id); + + unsigned int width = CodecCtx->width; + unsigned int height = CodecCtx->height; + unsigned int bitrate = CodecCtx->bit_rate; + const char* codecName = (Codec)?Codec->name:"unknown"; + + MESSAGE("AVDetector: %s-stream %dx%d at %d bit/s", codecName, width, height, bitrate); + + Resource->mBitrate = bitrate; + Resource->mSampleFrequency = CodecCtx->sample_rate; + Resource->mResolution = cString::sprintf("%dx%d", width, height); + + return 0; + +} -- cgit v1.2.3