用于webm视频转换的API

Kla*_*sen 10 c# api webm

有没有人知道任何(原型)c#API用于将视频转换为谷歌的新WebM视频格式?

dtb*_*dtb 8

快速谷歌搜索说:没有.但是示例编码器看起来应该可以使用P/Invoke轻松转换为C#.该编码算法接口看起来完全可以应付.如果其他一切都失败了,总会有C++/CLI.谁启动了codeplex项目?:-)

更新:截至目前,有一个hackish,rudimentary工作原型.NET API.干得好:

#include "vpx_codec.h"

#define VPX_CODEC_DISABLE_COMPAT 1
#include "vpx_encoder.h"
#include "vp8cx.h"

#define vp8iface (&vpx_codec_vp8_cx_algo)

using namespace System;

namespace WebM
{
    namespace VP8 
    {
        namespace Native
        {
            public ref class VP8Codec
            {
            private:
                vpx_codec_ctx_t* ctx;

                VP8Codec(vpx_codec_ctx_t* ctx)
                {
                    this->ctx = ctx;
                }

            public:
                ~VP8Codec()
                {
                    vpx_codec_destroy(ctx);
                    delete ctx;
                }

                property String^ LastError
                {
                    String^ get()
                    {
                        return gcnew String(vpx_codec_error(ctx));
                    }
                }

                property String^ LastErrorDetail
                {
                    String^ get()
                    {
                        return gcnew String(vpx_codec_error_detail(ctx));
                    }
                }

                int Encode()
                {
                    // TODO: do actual encoding
                    return
                        vpx_codec_encode(ctx, NULL, 0, 1, 0, VPX_DL_REALTIME); 
                }

                static VP8Codec^ CreateEncoder() // TODO: add 'config' argument
                {
                    vpx_codec_ctx_t* ctx;
                    vpx_codec_enc_cfg_t cfg;

                    if(vpx_codec_enc_config_default(vp8iface, &cfg, 0))
                    {
                        return nullptr; // TODO: throw exception
                    }

                    ctx = new vpx_codec_ctx_t;

                    if (vpx_codec_enc_init(ctx, vp8iface, &cfg, 0))
                    {
                        delete ctx;
                        return nullptr; // TODO: throw exception
                    }

                    return gcnew VP8Codec(ctx);
                }

                static property int Version
                {
                    int get()
                    {
                        return vpx_codec_version();
                    }
                }

                static property String^ VersionString
                {
                    String^ get()
                    {
                        return gcnew String(vpx_codec_version_str());
                    }
                }

                static property String^ BuildConfig
                {
                    String^ get()
                    {
                        return gcnew String(vpx_codec_build_config());
                    }
                }

                static String^ GetErrorDescription(int errorCode)
                {
                    return gcnew String(
                        vpx_codec_err_to_string((vpx_codec_err_t)errorCode));
                }

                static property String^ IfaceName
                {
                    String^ get()
                    {
                        return gcnew String(vpx_codec_iface_name(vp8iface));
                    }
                }
            };
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

您应该能够从libvpx Windows版本链接到vpxmtd.lib.我无法摆脱一个警告,但到目前为止似乎有效.但是,我的C++/CLI有点生疏,因此代码中可能存在一些内存泄漏.

测试程序:

namespace WebM.VP8
{
    using System;

    using WebM.VP8.Native;

    public class Program
    {
        public static void Main()
        {
            using (var encoder = VP8Codec.CreateEncoder())
            {
                Console.WriteLine(encoder.Encode());
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

  • @Faizan Kazi:如何向Visual C++项目添加.lib引用 - 这听起来像是一个很好的问题,请在stackoverflow.com上查询 (2认同)