Example #1
0
extern "C" jstring Java_com_juwan_juplayer_jni_Ffmpeg_init(JNIEnv *env,
                                                    jobject obj) {

    char ffmpeg_version[20] = "";
    sprintf(ffmpeg_version, "%d", avcodec_version());
    LOGE("%d", avcodec_version());
    return env->NewStringUTF(ffmpeg_version);
}
Example #2
0
File: av_log.c Project: kax4/mpv
void print_libav_versions(void)
{
    print_version("libavutil", LIBAVUTIL_VERSION_INT, avutil_version());
    print_version("libavcodec", LIBAVCODEC_VERSION_INT, avcodec_version());
    print_version("libavformat", LIBAVFORMAT_VERSION_INT, avformat_version());
    print_version("libswscale", LIBSWSCALE_VERSION_INT, swscale_version());
}
JNIEXPORT void JNICALL android_media_player_native_init
        (JNIEnv *env, jclass mClazz) {

    jclass clazz;
    clazz = env->FindClass(JNIREG_CLASS);
    if (clazz == NULL) {
        return;
    }

    fields.context = env->GetFieldID(clazz, "mNativeContext", "I");
    if (fields.context == NULL) {
        return;
    }

    fields.post_event = env->GetStaticMethodID(clazz, "postEventFromNative",
                                               "(Ljava/lang/Object;IIILjava/lang/Object;)V");


    if (fields.post_event == NULL) {
        return;
    }

    fields.surface_texture = env->GetFieldID(clazz, "mNativeSurfaceTexture", "I");
    if (fields.surface_texture == NULL) {
        return;
    }

    ALOGI("avcodec_version=%d;avcodec_configuration=%s", avcodec_version(),
          avcodec_configuration());
}
Example #4
0
static int ffmpeglib_load_library(ffmpeglib_t *lib)
{
    avcodec_version_t avcodec_version;

    if (!avcodec_dll) {
        avcodec_dll = LoadLibrary(AVCODEC_DLL_NAME);

        if (!avcodec_dll) {
            log_debug("LoadLibrary " AVCODEC_DLL_NAME " failed!");
            return -1;
        }

        GET_PROC_ADDRESS_AND_TEST_AVCODEC(avcodec_open);
        GET_PROC_ADDRESS_AND_TEST_AVCODEC(avcodec_close);
        GET_PROC_ADDRESS_AND_TEST_AVCODEC(avcodec_find_encoder);
        GET_PROC_ADDRESS_AND_TEST_AVCODEC(avcodec_encode_audio);
        GET_PROC_ADDRESS_AND_TEST_AVCODEC(avcodec_encode_video);
        GET_PROC_ADDRESS_AND_TEST_AVCODEC(avpicture_fill);
        GET_PROC_ADDRESS_AND_TEST_AVCODEC(avpicture_get_size);
        GET_PROC_ADDRESS_AND_TEST_AVCODEC(img_convert);
    }

    if (!avformat_dll) {
        avformat_dll = LoadLibrary(AVFORMAT_DLL_NAME);

        if (!avformat_dll) {
            log_debug("LoadLibrary " AVFORMAT_DLL_NAME " failed!");
            return -1;
        }

        GET_PROC_ADDRESS_AND_TEST_AVFORMAT(av_register_all);
        GET_PROC_ADDRESS_AND_TEST_AVFORMAT(av_new_stream);
        GET_PROC_ADDRESS_AND_TEST_AVFORMAT(av_set_parameters);
        GET_PROC_ADDRESS_AND_TEST_AVFORMAT(av_write_header);
        GET_PROC_ADDRESS_AND_TEST_AVFORMAT(av_write_frame);
        GET_PROC_ADDRESS_AND_TEST_AVFORMAT(av_write_trailer);
        GET_PROC_ADDRESS_AND_TEST_AVFORMAT(url_fopen);
        GET_PROC_ADDRESS_AND_TEST_AVFORMAT(url_fclose);
        GET_PROC_ADDRESS_AND_TEST_AVFORMAT(dump_format);
        GET_PROC_ADDRESS_AND_TEST_AVFORMAT(guess_format);
    }

    if (!avutil_dll) {
        avutil_dll = LoadLibrary(AVUTIL_DLL_NAME);

        if (!avformat_dll) {
            log_debug("LoadLibrary " AVUTIL_DLL_NAME " failed!");
            return -1;
        }

        GET_PROC_ADDRESS_AND_TEST_AVUTIL(av_free);
    }
    avcodec_version = (avcodec_version_t)GetProcAddress(avcodec_dll, "avcodec_version");

    if (avcodec_version() != LIBAVCODEC_VERSION_INT) {
        ui_error(translate_text(IDS_FFMPEG_DLL_MISMATCH));
        return -1;
    }
    return 0;
}
Example #5
0
// LibAvW_Init
DLL_EXPORT int LibAvW_Init(avwCallbackPrint *printfunction)
{
	if (libav_initialized)
		return LIBAVW_ERROR_NONE;

	libav_codec_version  = avcodec_version();
	libav_format_version = avformat_version();
	libav_util_version   = avutil_version();
	libav_swscale_version  = swscale_version();

	// only can use version we were linked against
	if (libav_codec_version != LIBAVCODEC_VERSION_INT)
		return LIBAVW_ERROR_DLL_VERSION_AVCODEC;
	if (libav_format_version != LIBAVFORMAT_VERSION_INT)
		return LIBAVW_ERROR_DLL_VERSION_AVFORMAT;
	if (libav_util_version != LIBAVUTIL_VERSION_INT)
		return LIBAVW_ERROR_DLL_VERSION_AVUTIL;
	if (libav_swscale_version != LIBSWSCALE_VERSION_INT)
		return LIBAVW_ERROR_DLL_VERSION_SWSCALE;

	// allright, init libavcodec
	avcodec_register_all();
	av_register_all();
	av_log_set_callback(LibAvW_ErrorCallback);
	libav_initialized = true;
	libav_print = printfunction;
	return LIBAVW_ERROR_NONE;
}
Example #6
0
File: av_log.c Project: wiiaboo/mpv
bool print_libav_versions(struct mp_log *log, int v)
{
    const struct lib libs[] = {
        {"libavutil",     LIBAVUTIL_VERSION_INT,     avutil_version()},
        {"libavcodec",    LIBAVCODEC_VERSION_INT,    avcodec_version()},
        {"libavformat",   LIBAVFORMAT_VERSION_INT,   avformat_version()},
        {"libswscale",    LIBSWSCALE_VERSION_INT,    swscale_version()},
        {"libavfilter",   LIBAVFILTER_VERSION_INT,   avfilter_version()},
#if HAVE_LIBAV
        {"libavresample", LIBAVRESAMPLE_VERSION_INT, avresample_version()},
#else
        {"libswresample", LIBSWRESAMPLE_VERSION_INT, swresample_version()},
#endif
    };

    mp_msg(log, v, "%s library versions:\n", LIB_PREFIX);

    bool mismatch = false;
    for (int n = 0; n < MP_ARRAY_SIZE(libs); n++) {
        const struct lib *l = &libs[n];
        mp_msg(log, v, "   %-15s %d.%d.%d", l->name, V(l->buildv));
        if (l->buildv != l->runv) {
            mp_msg(log, v, " (runtime %d.%d.%d)", V(l->runv));
            mismatch = true;
        }
        mp_msg(log, v, "\n");
    }

    mp_msg(log, v, "%s version: %s\n", LIB_PREFIX, av_version_info());

    return !mismatch;
}
Example #7
0
JNIEXPORT jstring JNICALL Java_com_qiniu_ffmpeg_MainActivity_getFfmpegVersionFromNative
  (JNIEnv * env , jobject obj)
  {
        char wd[512];
        sprintf(wd, "AVCODEC VERSION %u\n", avcodec_version());
        return (*env)->NewStringUTF(env, wd);
  }
Example #8
0
/* This is a trivial JNI example where we use a native method  
 * to return a new VM String. See the corresponding Java source  
 * file located at:  
 *  
 *   apps/samples/hello-jni/project/src/com/example/HelloJni/HelloJni.java  
 */  
JNIEXPORT jstring Java_com_lijia_ffmpeg4android_HelloJni_stringFromJNI(JNIEnv* env,
        jobject thiz) {
    char str[25];  
    sprintf(str, "%d", avcodec_version());  
    jstring verStr = (*env)->NewStringUTF(env, str);
    (*env)->DeleteLocalRef(verStr);    
    return verStr;
    // return (*env)->NewStringUTF(env, "Hello from JNI !");0  
}  
Example #9
0
/*
 * Class:     com_example_testffmpeg_CFFmpegJni
 * Method:    IGetVersion
 * Signature: ()I
 */
jint Java_com_example_testffmpeg_CFFmpegJni_IGetVersion(JNIEnv *env, jobject thiz)
{
	/// 设置FFmpeg日志信息回调
	av_log_set_callback(e_PrintFFmpeg);
	LOGD("Set FFMpeg Log Call Back Success. ");
	/// 获取版本信息测试使用
	int nRet = avcodec_version();
	return nRet;
}
void ArchHooks_Unix::DumpDebugInfo()
{
	RString sys;
	int vers;
	GetKernel( sys, vers );
	LOG->Info( "OS: %s ver %06i", sys.c_str(), vers );

#if defined(CRASH_HANDLER)
	LOG->Info( "Crash backtrace component: %s", BACKTRACE_METHOD_TEXT );
	LOG->Info( "Crash lookup component: %s", BACKTRACE_LOOKUP_METHOD_TEXT );
#if defined(BACKTRACE_DEMANGLE_METHOD_TEXT)
	LOG->Info( "Crash demangle component: %s", BACKTRACE_DEMANGLE_METHOD_TEXT );
#endif
#endif

	LOG->Info( "Runtime library: %s", LibcVersion().c_str() );
	LOG->Info( "Threads library: %s", ThreadsVersion().c_str() );
#if defined(HAVE_FFMPEG)
	LOG->Info( "libavcodec: %#x (%u)", avcodec_version(), avcodec_version() );
#endif
}
Example #11
0
File: av_log.c Project: Bl4Cc4t/mpv
void print_libav_versions(struct mp_log *log, int v)
{
    const struct lib libs[] = {
        {"libavutil",     LIBAVUTIL_VERSION_INT,     avutil_version()},
        {"libavcodec",    LIBAVCODEC_VERSION_INT,    avcodec_version()},
        {"libavformat",   LIBAVFORMAT_VERSION_INT,   avformat_version()},
        {"libswscale",    LIBSWSCALE_VERSION_INT,    swscale_version()},
#if HAVE_LIBAVFILTER
        {"libavfilter",   LIBAVFILTER_VERSION_INT,   avfilter_version()},
#endif
#if HAVE_LIBAVRESAMPLE
        {"libavresample", LIBAVRESAMPLE_VERSION_INT, avresample_version()},
#endif
#if HAVE_LIBSWRESAMPLE
        {"libswresample", LIBSWRESAMPLE_VERSION_INT, swresample_version()},
#endif
    };

    mp_msg(log, v, "%s library versions:\n", LIB_PREFIX);

    bool mismatch = false;
    bool broken = false;
    for (int n = 0; n < MP_ARRAY_SIZE(libs); n++) {
        const struct lib *l = &libs[n];
        mp_msg(log, v, "   %-15s %d.%d.%d", l->name, V(l->buildv));
        if (l->buildv != l->runv) {
            mp_msg(log, v, " (runtime %d.%d.%d)", V(l->runv));
            mismatch = true;
            broken |= ((l->buildv & 255) >= 100) != ((l->runv & 255) >= 100);
        }
        mp_msg(log, v, "\n");
    }
    // This just won't work. It's 100% broken.
    if (broken) {
        mp_fatal(log, "mpv was compiled and linked against a mixture of Libav "
                 "and FFmpeg versions. This won't work and will most likely "
                 "crash at some point. Exiting.\n");
        exit(42);
    }
    // We don't "really" support mismatched libraries, but if you like to
    // suffer, you're free to enjoy the terrible aspects of dynamic linking.
    // In particular, we don't use all these crazy accessors ffmpeg wants us
    // to use in order to be ABI compatible after Libav merges - because that
    // would make our code incompatible to Libav. It's madness.
    if (mismatch) {
        mp_warn(log, "Warning: mpv was compiled against a different version of "
                "%s than the shared\nlibrary it is linked against. This can "
                "expose subtle ABI compatibility issues\nand can lead to "
                "misbehavior and crashes.\n", LIB_PREFIX);
    }
}
Example #12
0
/*
static void dump_stream_format(AVFormatContext *ic, int i, int index, int is_output)
{
	char buf[256];
	int flags = (is_output ? ic->oformat->flags : ic->iformat->flags);
	AVStream *st = ic->streams[i];
	int g = av_gcd(st->time_base.num, st->time_base.den);
	AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL, 0);
	avcodec_string(buf, sizeof(buf), st->codec, is_output);
	av_log(NULL, AV_LOG_INFO, "    Stream #%d.%d", index, i);
	// the pid is an important information, so we display it
	// XXX: add a generic system
	if (flags & AVFMT_SHOW_IDS)
		av_log(NULL, AV_LOG_INFO, "[0x%x]", st->id);
	if (lang)
		av_log(NULL, AV_LOG_INFO, "(%s)", lang->value);
	av_log(NULL, AV_LOG_DEBUG, ", %d, %d/%d", st->codec_info_nb_frames, st->time_base.num/g, st->time_base.den/g);
	av_log(NULL, AV_LOG_INFO, ": %s", buf);
	if (st->sample_aspect_ratio.num && // default
		av_cmp_q(st->sample_aspect_ratio, st->codec->sample_aspect_ratio)) {
		AVRational display_aspect_ratio;
		av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
				  st->codec->width*st->sample_aspect_ratio.num,
				  st->codec->height*st->sample_aspect_ratio.den,
				  1024*1024);
		av_log(NULL, AV_LOG_INFO, ", PAR %d:%d DAR %d:%d",
				 st->sample_aspect_ratio.num, st->sample_aspect_ratio.den,
				 display_aspect_ratio.num, display_aspect_ratio.den);
	}
	if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO){
		if(st->avg_frame_rate.den && st->avg_frame_rate.num)
			print_fps(av_q2d(st->avg_frame_rate), "fps");
		if(st->r_frame_rate.den && st->r_frame_rate.num)
			print_fps(av_q2d(st->r_frame_rate), "tbr");
		if(st->time_base.den && st->time_base.num)
			print_fps(1/av_q2d(st->time_base), "tbn");
		if(st->codec->time_base.den && st->codec->time_base.num)
			print_fps(1/av_q2d(st->codec->time_base), "tbc");
	}
	if (st->disposition & AV_DISPOSITION_DEFAULT)
		av_log(NULL, AV_LOG_INFO, " (default)");
	if (st->disposition & AV_DISPOSITION_DUB)
		av_log(NULL, AV_LOG_INFO, " (dub)");
	if (st->disposition & AV_DISPOSITION_ORIGINAL)
		av_log(NULL, AV_LOG_INFO, " (original)");
	if (st->disposition & AV_DISPOSITION_COMMENT)
		av_log(NULL, AV_LOG_INFO, " (comment)");
	if (st->disposition & AV_DISPOSITION_LYRICS)
		av_log(NULL, AV_LOG_INFO, " (lyrics)");
	if (st->disposition & AV_DISPOSITION_KARAOKE)
		av_log(NULL, AV_LOG_INFO, " (karaoke)");
	if (st->disposition & AV_DISPOSITION_FORCED)
		av_log(NULL, AV_LOG_INFO, " (forced)");
	if (st->disposition & AV_DISPOSITION_HEARING_IMPAIRED)
		av_log(NULL, AV_LOG_INFO, " (hearing impaired)");
	if (st->disposition & AV_DISPOSITION_VISUAL_IMPAIRED)
		av_log(NULL, AV_LOG_INFO, " (visual impaired)");
	if (st->disposition & AV_DISPOSITION_CLEAN_EFFECTS)
		av_log(NULL, AV_LOG_INFO, " (clean effects)");
	av_log(NULL, AV_LOG_INFO, "\n");
	dump_metadata(NULL, st->metadata, "    ");
}*/
void AVInfo::dump()
{
	qDebug("Version\n"
		   "libavcodec: %#x\n"
		   "libavformat: %#x\n"
//	       "libavdevice: %#x\n"
		   "libavutil: %#x"
		   ,avcodec_version()
		   ,avformat_version()
//	       ,avdevice_version()
		   ,avutil_version());
	av_dump_format(_format_context, 0, qPrintable(_file_name), false);
	qDebug("video format: %s [%s]", qPrintable(videoFormatName()), qPrintable(videoFormatLongName()));
	qDebug("Audio: %s [%s]", qPrintable(audioCodecName()), qPrintable(audioCodecLongName()));
	qDebug("sample rate: %d, channels: %d", a_codec_context->sample_rate, a_codec_context->channels);
}
Example #13
0
FFMS_Index::FFMS_Index(const char *IndexFile)
: RefCount(1)
{
	ZipFile zf(IndexFile, "rb");

	// Read the index file header
	if (zf.Read<uint32_t>() != INDEXID)
		throw FFMS_Exception(FFMS_ERROR_PARSER, FFMS_ERROR_FILE_READ,
			std::string("'") + IndexFile + "' is not a valid index file");

	if (zf.Read<uint32_t>() != FFMS_VERSION)
		throw FFMS_Exception(FFMS_ERROR_PARSER, FFMS_ERROR_FILE_READ,
			std::string("'") + IndexFile + "' is not the expected index version");

	uint32_t Tracks = zf.Read<uint32_t>();
	Decoder = zf.Read<uint32_t>();
	ErrorHandling = zf.Read<uint32_t>();

	if (!(Decoder & FFMS_GetEnabledSources()))
		throw FFMS_Exception(FFMS_ERROR_INDEX, FFMS_ERROR_NOT_AVAILABLE,
			"The source which this index was created with is not available");

	if (zf.Read<uint32_t>() != avutil_version() ||
		zf.Read<uint32_t>() != avformat_version() ||
		zf.Read<uint32_t>() != avcodec_version() ||
		zf.Read<uint32_t>() != swscale_version())
		throw FFMS_Exception(FFMS_ERROR_PARSER, FFMS_ERROR_FILE_READ,
			std::string("A different FFmpeg build was used to create '") + IndexFile + "'");

	Filesize = zf.Read<int64_t>();
	zf.Read(Digest, sizeof(Digest));

	reserve(Tracks);
	try {
		for (size_t i = 0; i < Tracks; ++i)
			push_back(FFMS_Track(zf));
	}
	catch (FFMS_Exception const&) {
		throw;
	}
	catch (...) {
		throw FFMS_Exception(FFMS_ERROR_PARSER, FFMS_ERROR_FILE_READ,
			std::string("Unknown error while reading index information in '") + IndexFile + "'");
	}
}
Example #14
0
void ffmpeg_version_print()
{
    struct _component {
        const char* lib;
        unsigned build_version;
        unsigned rt_version;
    } components[] = {
        { "avcodec", LIBAVCODEC_VERSION_INT, avcodec_version()},
        { "avformat", LIBAVFORMAT_VERSION_INT, avformat_version()},
        { "avutil", LIBAVUTIL_VERSION_INT, avutil_version()},
        { "swscale", LIBSWSCALE_VERSION_INT, swscale_version()},
#if QTAV_HAVE(SWRESAMPLE)
        { "swresample", LIBSWRESAMPLE_VERSION_INT, swresample_version()}, //swresample_version not declared in 0.9
#endif //QTAV_HAVE(SWRESAMPLE)
#if QTAV_HAVE(AVRESAMPLE)
        { "avresample", LIBAVRESAMPLE_VERSION_INT, avresample_version()},
#endif //QTAV_HAVE(AVRESAMPLE)
#if QTAV_HAVE(AVFILTER)
        { "avfilter", LIBAVFILTER_VERSION_INT, avfilter_version() },
#endif //QTAV_HAVE(AVFILTER)
        { 0, 0, 0}
    };
    for (int i = 0; components[i].lib != 0; ++i) {
        printf("Build with lib%s-%u.%u.%u\n"
               , components[i].lib
               , QTAV_VERSION_MAJOR(components[i].build_version)
               , QTAV_VERSION_MINOR(components[i].build_version)
               , QTAV_VERSION_PATCH(components[i].build_version)
               );
        unsigned rt_version = components[i].rt_version;
        if (components[i].build_version != rt_version) {
            fprintf(stderr, "Warning: %s runtime version %u.%u.%u mismatch!\n"
                    , components[i].lib
                    , QTAV_VERSION_MAJOR(rt_version)
                    , QTAV_VERSION_MINOR(rt_version)
                    , QTAV_VERSION_PATCH(rt_version)
                    );
        }
    }
    fflush(0);
}
Example #15
0
void FFMS_Index::WriteIndex(const char *IndexFile) {
	ZipFile zf(IndexFile, "wb");

	// Write the index file header
	zf.Write<uint32_t>(INDEXID);
	zf.Write<uint32_t>(FFMS_VERSION);
	zf.Write<uint32_t>(size());
	zf.Write<uint32_t>(Decoder);
	zf.Write<uint32_t>(ErrorHandling);
	zf.Write<uint32_t>(avutil_version());
	zf.Write<uint32_t>(avformat_version());
	zf.Write<uint32_t>(avcodec_version());
	zf.Write<uint32_t>(swscale_version());
	zf.Write<int64_t>(Filesize);
	zf.Write(Digest);

	for (size_t i = 0; i < size(); ++i)
		at(i).Write(zf);

	zf.Finish();
}
Example #16
0
bool FFDecVDPAU::open(StreamInfo *streamInfo, Writer *writer)
{
	/*
	 * AV_PIX_FMT_YUVJ420P doesn't work on FFmpeg/VDPAU, but works on VAAPI over VDPAU.
	 * I tested FFmpeg 2.7 and it works, but crashes (assertion failed) in FFmpeg >= 2.8.
	*/
	const bool canUseYUVJ420P = avcodec_version() < 0x383C64;
	if (streamInfo->img_fmt == AV_PIX_FMT_YUV420P || (canUseYUVJ420P && streamInfo->img_fmt == AV_PIX_FMT_YUVJ420P))
	{
		AVCodec *codec = init(streamInfo);
		if (codec && hasHWAccel("vdpau"))
		{
			if (writer && writer->name() != VDPAUWriterName)
				writer = NULL;
			hwAccelWriter = writer ? (VideoWriter *)writer : new VDPAUWriter(getModule());
			if ((writer || hwAccelWriter->open()) && hwAccelWriter->HWAccellInit(codec_ctx->width, codec_ctx->height, avcodec_get_name(codec_ctx->codec_id)))
			{
				codec_ctx->hwaccel_context = av_mallocz(sizeof(AVVDPAUContext));
				((AVVDPAUContext *)codec_ctx->hwaccel_context)->decoder = ((VDPAUWriter *)hwAccelWriter)->getVdpDecoder();
				((AVVDPAUContext *)codec_ctx->hwaccel_context)->render  = ((VDPAUWriter *)hwAccelWriter)->getVdpDecoderRender();
				codec_ctx->thread_count   = 1;
				codec_ctx->get_buffer2    = HWAccelHelper::get_buffer;
				codec_ctx->get_format     = get_format;
				codec_ctx->slice_flags    = SLICE_FLAG_CODED_ORDER | SLICE_FLAG_ALLOW_FIELD;
				codec_ctx->opaque         = dynamic_cast< HWAccelHelper * >(hwAccelWriter);
				if (openCodec(codec))
					return true;
			}
			else
			{
				if (!writer)
					delete hwAccelWriter;
				hwAccelWriter = NULL;
			}
		}
	}
	return false;
}
Example #17
0
void TheoraVideoClip_FFmpeg::load(TheoraDataSource* source)
{
	mVideoStreamIndex = -1;
	mFrameNumber = 0;
	AVDictionary* optionsDict = NULL;
	
	if (!ffmpegInitialised)
	{
#ifdef _FFMPEG_DEBUG
		th_writelog("Initializing ffmpeg");
#endif
		th_writelog("avcodec version: " + str(avcodec_version()));
		av_register_all();
		av_log_set_level(AV_LOG_DEBUG);
		av_log_set_callback(avlog_theoraplayer);
		ffmpegInitialised = 1;
		//show_codecs(0, 0, 0);
	}
	
	mInputBuffer = (unsigned char*) av_malloc(READ_BUFFER_SIZE);
	mAvioContext = avio_alloc_context(mInputBuffer, READ_BUFFER_SIZE, 0, source, &readFunction, NULL, &seekFunction);
	
#ifdef _FFMPEG_DEBUG
	th_writelog(mName + ": avio context created");
#endif

	mFormatContext = avformat_alloc_context();
#ifdef _FFMPEG_DEBUG
	th_writelog(mName + ": avformat context created");
#endif
	mFormatContext->pb = mAvioContext;
	
	int err;
	if ((err = avformat_open_input(&mFormatContext, "", NULL, NULL)) != 0)
	{
		th_writelog(mName + ": avformat input opening failed!");
		th_writelog(mName + ": error_code: " + str(err));
		return;
	}
	
#ifdef _FFMPEG_DEBUG
	th_writelog(mName + ": avformat input opened");
#endif
	
	// Retrieve stream information
	if (avformat_find_stream_info(mFormatContext, NULL) < 0)
		return; // Couldn't find stream information
	
#ifdef _FFMPEG_DEBUG
	th_writelog(mName + ": got stream info");
#endif
	
	// Dump information about file onto standard error
	//	av_dump_format(mFormatContext, 0, "", 0);
	
	// Find the first video stream
	for (int i = 0; i < mFormatContext->nb_streams; ++i)
	{
		if(mFormatContext->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
		{
			mVideoStreamIndex = i;
			break;
		}
	}
	if (mVideoStreamIndex == -1)
		return; // Didn't find a video stream

#ifdef _FFMPEG_DEBUG
	th_writelog(mName + ": Found video stream at index " + str(mVideoStreamIndex));
#endif

	// Get a pointer to the codec context for the video stream
	mCodecContext = mFormatContext->streams[mVideoStreamIndex]->codec;
	
	// Find the decoder for the video stream
	mCodec = avcodec_find_decoder(mCodecContext->codec_id);
	if (mCodec == NULL)
	{
		th_writelog("Unsupported codec!");
		return; // Codec not found
	}
	// Open codec
	if(avcodec_open2(mCodecContext, mCodec, &optionsDict) < 0)
		return; // Could not open codec
	
#ifdef _FFMPEG_DEBUG
	th_writelog(mName + ": Codec opened");
#endif

	
	mFrame = avcodec_alloc_frame();
	
#ifdef _FFMPEG_DEBUG
	th_writelog(mName + ": Frame allocated");
#endif
		
	//AVRational rational = mCodecContext->time_base;

	mFPS = 25; //TODOOOOOO!!!
	
	mWidth = mStride = mCodecContext->width;
	mHeight = mCodecContext->height;
	mFrameDuration = 1.0f / mFPS;
	mDuration = mFormatContext->duration / AV_TIME_BASE;
	
	if (mFrameQueue == NULL) // todo - why is this set in the backend class? it should be set in the base class, check other backends as well
	{
		mFrameQueue = new TheoraFrameQueue(this);
		mFrameQueue->setSize(mNumPrecachedFrames);
	}
}
Example #18
0
QString AVDecoder::description() const
{
    return QString("FFmpeg/Libav avcodec %1.%2.%3").arg(QTAV_VERSION_MAJOR(avcodec_version())).arg(QTAV_VERSION_MINOR(avcodec_version())).arg(QTAV_VERSION_PATCH(avcodec_version()));
}