0

每个编解码器的类型或编解码器的类型在列表中我最后有大约 500 个编解码器我希望例如在开头的列表中它会显示例如:

音频 mpeha mpegv ..... 视频 xvid divx

等等。

获取编解码器列表的前两个函数在 C 中:

const char* Encoder_GetNextCodecName()
{
    current_codec = av_codec_next(current_codec);
    while (current_codec != NULL)
    {       
        return current_codec->name;
    }
    return "";
}

const char* Encoder_GetFirstCodecName()
{
    current_codec = NULL;
    return Encoder_GetNextCodecName();
}

然后我有头文件:

const char* Encoder_GetNextCodecName();
const char* Encoder_GetFirstCodecName();

然后是我创建列表的另一个 C++ 头文件:

List<String^> ^GetCodecs()
    {
        List<String^> ^l = gcnew List<String^>;

        String ^s = gcnew String(Encoder_GetFirstCodecName());
        while (!String::IsNullOrEmpty(s))
        {
            l->Add(s);
            s = gcnew String(Encoder_GetNextCodecName());
        }

        return l;
     }

然后,当我在 CSHARP 中执行此操作时:

List<string> l = new List<string>(f.GetCodecs());

我看到变量 l 包含 506 个编解码器的 . 编解码器是 ffmpeg 的!

现在在 C 文件中也有类似的内容:

current_codec->type

其中有很多属性。C文件中也有这样的东西:

AVMediaType::

这给了我 7 种类型的编解码器。

问题是当我创建列表时如何在 C++ 头文件中制作列表,该列表将包含每个编解码器或每组编解码器的类型,例如:音频、视频、数据....?

编辑

这是我在 C 函数和 CLI 之间连接的另一个头文件:

我有另一个头文件,我首先从 C 调用函数:

ifdef __cplusplus
extern "C"
{
#endif

#include <stdint.h>

bool Encoder_MoveToNextCodec();
bool Encoder_MoveToFirstCodec();
const char* Encoder_GetCurrentCodecName();
int Encoder_GetCurrentCodecType();

#ifdef __cplusplus
}    // extern "C"
#endif

这是我的 CLI 代码:

#pragma once



// FFMPEG_WRAPPER.cpp : Defines the exported functions for the DLL application.
//
#include "ENCODER.h"

#include <stdlib.h>
#include <string.h>
#include <msclr\marshal.h>
#include <vcclr.h>
#include <cstdlib>
#include <Windows.h>

using namespace System;
using namespace System::Drawing;
using namespace System::Collections::Generic;
using namespace System::Runtime::InteropServices;
using namespace System::Drawing::Imaging;

using namespace msclr::interop;

namespace MyVideo
{

public ref class FFMPEGWrapper
{
public:
    FFMPEGWrapper(void)
    {

        Encoder_init();

    }

ref class CodecInfo
{
public:
    String^ CodecName;
    int CodecType;
};

List<CodecInfo^> ^GetCodecs()
{
    List<CodecInfo^> ^l = gcnew List<CodecInfo^>;

    bool KeepLooping = Encoder_MoveToFirstCodec();
    while (KeepLooping)
    {
        CodecInfo ^codec = gcnew CodecInfo();

        codec->CodecName = gcnew String(Encoder_GetCurrentCodecName());
        codec->CodecType = Encoder_GetCurrentCodecType();


        l->Add(codec);
        KeepLooping = Encoder_MoveToNextCodec();
    }

    return l;
 }

然后在 CSHARP 我做了:

List<f.CodecInfo> l = f.GetCodecs();

但是 CodecInfo 不存在,我在 GetCodecs() 上遇到错误

错误 1 ​​无法将类型“System.Collections.Generic.List”隐式转换为“System.Collections.Generic.List”

错误 2“ScreenVideoRecorder.Form1.f”是一个“字段”,但用作“类型”

错误的问题在于 CSHARP。

4

1 回答 1

1

您需要扩展您的 C 代码以公开您想要的额外细节,例如:

__declspec(thread) AVCodec* current_codec = NULL;

bool Encoder_MoveToNextCodec()
{
    current_codec = av_codec_next(current_codec);
    return (current_codec != NULL);
}

bool Encoder_MoveToFirstCodec()
{
    current_codec = NULL;
    return Encoder_MoveToNextCodec();
}

const char* Encoder_GetCurrentCodecName()
{
    if (current_codec != NULL)
        return current_codec->name;
    return "";
}

int Encoder_GetCurrentCodecType()
{
    if (current_codec != NULL)
        return (int) current_codec->type;
    return AVMEDIA_TYPE_UNKNOWN;
}

然后扩展您的 CLI 代码以存储该信息:

ref class CodecInfo
{
public:
    String^ CodecName;
    int CodecType;
    ...
};

List<CodecInfo^> ^GetCodecs()
{
    List<CodecInfo^> ^l = gcnew List<CodecInfo^>;

    bool KeepLooping = Encoder_MoveToFirstCodec();
    while (KeepLooping)
    {
        CodecInfo ^codec = gcnew CodecInfo();

        codec->CodecName = gcnew String(Encoder_GetCurrentCodecName());
        codec->CodecType = Encoder_GetCurrentCodecType();
        ...

        l->Add(codec);
        KeepLooping = Encoder_MoveToNextCodec();
    }

    return l;
 }

最后,根据需要使用新信息:

List<CodecInfo> l = f.GetCodecs();
foreach(CodecInfo codec in l)
{
    // use codec.CodecName, codec.CodecType, ... as needed
}
于 2013-05-05T10:06:57.480 回答