Win32 API 日本語リファレンス
ホームMedia.MediaFoundation › MFCreateTranscodeProfile

MFCreateTranscodeProfile

関数
トランスコードの設定を保持するプロファイルを生成する。
DLLMF.dll呼出規約winapi対応OSWindows 7 以降

シグネチャ

// MF.dll
#include <windows.h>

HRESULT MFCreateTranscodeProfile(
    IMFTranscodeProfile** ppTranscodeProfile
);

パラメーター

名前方向説明
ppTranscodeProfileIMFTranscodeProfile**outトランスコードプロファイルオブジェクトの IMFTranscodeProfile インターフェイスへのポインターを受け取ります。呼び出し側はこのインターフェイスを解放する必要があります。

戻り値の型: HRESULT

公式ドキュメント

空のトランスコードプロファイルオブジェクトを作成します。

戻り値

この関数が成功した場合は S_OK を返します。それ以外の場合は HRESULT エラーコードを返します。

解説(Remarks)

MFCreateTranscodeProfile 関数は空のトランスコードプロファイルを作成します。メディアタイプおよびコンテナーのプロパティを定義するトランスコードプロファイル設定属性を構成する必要があります。プロファイルを構成するには、次のメソッドを使用します。

この関数を使用するサンプルコードについては、次のトピックを参照してください。

次の例では、Windows Media Audio (WMA) 用のトランスコードプロファイルを作成します。

template <class Q>
HRESULT GetCollectionObject(IMFCollection *pCollection, DWORD index, Q **ppObj)
{
    IUnknown *pUnk;
    HRESULT hr = pCollection->GetElement(index, &pUnk);
    if (SUCCEEDED(hr))
    {
        hr = pUnk->QueryInterface(IID_PPV_ARGS(ppObj));
        pUnk->Release();
    }
    return hr;
}

HRESULT CreateTranscodeProfile(IMFTranscodeProfile **ppProfile)
{
    IMFTranscodeProfile *pProfile = NULL;     // Transcode profile.
    IMFCollection   *pAvailableTypes = NULL;  // List of audio media types.
    IMFMediaType    *pAudioType = NULL;       // Audio media type.
    IMFAttributes   *pAudioAttrs = NULL;      // Copy of the audio media type.
    IMFAttributes   *pContainer = NULL;       // Container attributes.

    DWORD dwMTCount = 0;
    
    // Create an empty transcode profile.
    HRESULT hr = MFCreateTranscodeProfile(&pProfile);
    if (FAILED(hr))
    {
        goto done;
    }

    // Get output media types for the Windows Media audio encoder.

    // Enumerate all codecs except for codecs with field-of-use restrictions.
    // Sort the results.

    DWORD dwFlags = 
        (MFT_ENUM_FLAG_ALL & (~MFT_ENUM_FLAG_FIELDOFUSE)) | 
        MFT_ENUM_FLAG_SORTANDFILTER;

    hr = MFTranscodeGetAudioOutputAvailableTypes(MFAudioFormat_WMAudioV9, 
        dwFlags, NULL, &pAvailableTypes);
    if (FAILED(hr))
    {
        goto done;
    }

    hr = pAvailableTypes->GetElementCount(&dwMTCount);
    if (FAILED(hr))
    {
        goto done;
    }
    if (dwMTCount == 0)
    {
        hr = E_FAIL;
        goto done;
    }

    // Get the first audio type in the collection and make a copy.
    hr = GetCollectionObject(pAvailableTypes, 0, &pAudioType);
    if (FAILED(hr))
    {
        goto done;
    }

    hr = MFCreateAttributes(&pAudioAttrs, 0);       
    if (FAILED(hr))
    {
        goto done;
    }

    hr = pAudioType->CopyAllItems(pAudioAttrs);
    if (FAILED(hr))
    {
        goto done;
    }

    // Set the audio attributes on the profile.
    hr = pProfile->SetAudioAttributes(pAudioAttrs);
    if (FAILED(hr))
    {
        goto done;
    }

    // Set the container attributes.
    hr = MFCreateAttributes(&pContainer, 1);
    if (FAILED(hr))
    {
        goto done;
    }

    hr = pContainer->SetGUID(MF_TRANSCODE_CONTAINERTYPE, MFTranscodeContainerType_ASF);
    if (FAILED(hr))
    {
        goto done;
    }

    hr = pProfile->SetContainerAttributes(pContainer);
    if (FAILED(hr))
    {
        goto done;
    }

    *ppProfile = pProfile;
    (*ppProfile)->AddRef();

done:
    SafeRelease(&pProfile);
    SafeRelease(&pAvailableTypes);
    SafeRelease(&pAudioType);
    SafeRelease(&pAudioAttrs);
    SafeRelease(&pContainer);
    return hr;
}
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// MF.dll
#include <windows.h>

HRESULT MFCreateTranscodeProfile(
    IMFTranscodeProfile** ppTranscodeProfile
);
[DllImport("MF.dll", ExactSpelling = true)]
static extern int MFCreateTranscodeProfile(
    IntPtr ppTranscodeProfile   // IMFTranscodeProfile** out
);
<DllImport("MF.dll", ExactSpelling:=True)>
Public Shared Function MFCreateTranscodeProfile(
    ppTranscodeProfile As IntPtr   ' IMFTranscodeProfile** out
) As Integer
End Function
' ppTranscodeProfile : IMFTranscodeProfile** out
Declare PtrSafe Function MFCreateTranscodeProfile Lib "mf" ( _
    ByVal ppTranscodeProfile As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

MFCreateTranscodeProfile = ctypes.windll.mf.MFCreateTranscodeProfile
MFCreateTranscodeProfile.restype = ctypes.c_int
MFCreateTranscodeProfile.argtypes = [
    ctypes.c_void_p,  # ppTranscodeProfile : IMFTranscodeProfile** out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('MF.dll')
MFCreateTranscodeProfile = Fiddle::Function.new(
  lib['MFCreateTranscodeProfile'],
  [
    Fiddle::TYPE_VOIDP,  # ppTranscodeProfile : IMFTranscodeProfile** out
  ],
  Fiddle::TYPE_INT)
#[link(name = "mf")]
extern "system" {
    fn MFCreateTranscodeProfile(
        ppTranscodeProfile: *mut *mut core::ffi::c_void  // IMFTranscodeProfile** out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("MF.dll")]
public static extern int MFCreateTranscodeProfile(IntPtr ppTranscodeProfile);
"@
$api = Add-Type -MemberDefinition $sig -Name 'MF_MFCreateTranscodeProfile' -Namespace Win32 -PassThru
# $api::MFCreateTranscodeProfile(ppTranscodeProfile)
#uselib "MF.dll"
#func global MFCreateTranscodeProfile "MFCreateTranscodeProfile" sptr
; MFCreateTranscodeProfile ppTranscodeProfile   ; 戻り値は stat
; ppTranscodeProfile : IMFTranscodeProfile** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "MF.dll"
#cfunc global MFCreateTranscodeProfile "MFCreateTranscodeProfile" sptr
; res = MFCreateTranscodeProfile(ppTranscodeProfile)
; ppTranscodeProfile : IMFTranscodeProfile** out -> "sptr"
; HRESULT MFCreateTranscodeProfile(IMFTranscodeProfile** ppTranscodeProfile)
#uselib "MF.dll"
#cfunc global MFCreateTranscodeProfile "MFCreateTranscodeProfile" intptr
; res = MFCreateTranscodeProfile(ppTranscodeProfile)
; ppTranscodeProfile : IMFTranscodeProfile** out -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	mf = windows.NewLazySystemDLL("MF.dll")
	procMFCreateTranscodeProfile = mf.NewProc("MFCreateTranscodeProfile")
)

// ppTranscodeProfile (IMFTranscodeProfile** out)
r1, _, err := procMFCreateTranscodeProfile.Call(
	uintptr(ppTranscodeProfile),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function MFCreateTranscodeProfile(
  ppTranscodeProfile: Pointer   // IMFTranscodeProfile** out
): Integer; stdcall;
  external 'MF.dll' name 'MFCreateTranscodeProfile';
result := DllCall("MF\MFCreateTranscodeProfile"
    , "Ptr", ppTranscodeProfile   ; IMFTranscodeProfile** out
    , "Int")   ; return: HRESULT
●MFCreateTranscodeProfile(ppTranscodeProfile) = DLL("MF.dll", "int MFCreateTranscodeProfile(void*)")
# 呼び出し: MFCreateTranscodeProfile(ppTranscodeProfile)
# ppTranscodeProfile : IMFTranscodeProfile** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "mf" fn MFCreateTranscodeProfile(
    ppTranscodeProfile: ?*anyopaque // IMFTranscodeProfile** out
) callconv(std.os.windows.WINAPI) i32;
proc MFCreateTranscodeProfile(
    ppTranscodeProfile: pointer  # IMFTranscodeProfile** out
): int32 {.importc: "MFCreateTranscodeProfile", stdcall, dynlib: "MF.dll".}
pragma(lib, "mf");
extern(Windows)
int MFCreateTranscodeProfile(
    void* ppTranscodeProfile   // IMFTranscodeProfile** out
);
ccall((:MFCreateTranscodeProfile, "MF.dll"), stdcall, Int32,
      (Ptr{Cvoid},),
      ppTranscodeProfile)
# ppTranscodeProfile : IMFTranscodeProfile** out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t MFCreateTranscodeProfile(
    void* ppTranscodeProfile);
]]
local mf = ffi.load("mf")
-- mf.MFCreateTranscodeProfile(ppTranscodeProfile)
-- ppTranscodeProfile : IMFTranscodeProfile** out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('MF.dll');
const MFCreateTranscodeProfile = lib.func('__stdcall', 'MFCreateTranscodeProfile', 'int32_t', ['void *']);
// MFCreateTranscodeProfile(ppTranscodeProfile)
// ppTranscodeProfile : IMFTranscodeProfile** out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("MF.dll", {
  MFCreateTranscodeProfile: { parameters: ["pointer"], result: "i32" },
});
// lib.symbols.MFCreateTranscodeProfile(ppTranscodeProfile)
// ppTranscodeProfile : IMFTranscodeProfile** out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t MFCreateTranscodeProfile(
    void* ppTranscodeProfile);
C, "MF.dll");
// $ffi->MFCreateTranscodeProfile(ppTranscodeProfile);
// ppTranscodeProfile : IMFTranscodeProfile** out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Mf extends StdCallLibrary {
    Mf INSTANCE = Native.load("mf", Mf.class);
    int MFCreateTranscodeProfile(
        Pointer ppTranscodeProfile   // IMFTranscodeProfile** out
    );
}
@[Link("mf")]
lib LibMF
  fun MFCreateTranscodeProfile = MFCreateTranscodeProfile(
    ppTranscodeProfile : Void*   # IMFTranscodeProfile** out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef MFCreateTranscodeProfileNative = Int32 Function(Pointer<Void>);
typedef MFCreateTranscodeProfileDart = int Function(Pointer<Void>);
final MFCreateTranscodeProfile = DynamicLibrary.open('MF.dll')
    .lookupFunction<MFCreateTranscodeProfileNative, MFCreateTranscodeProfileDart>('MFCreateTranscodeProfile');
// ppTranscodeProfile : IMFTranscodeProfile** out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function MFCreateTranscodeProfile(
  ppTranscodeProfile: Pointer   // IMFTranscodeProfile** out
): Integer; stdcall;
  external 'MF.dll' name 'MFCreateTranscodeProfile';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "MFCreateTranscodeProfile"
  c_MFCreateTranscodeProfile :: Ptr () -> IO Int32
-- ppTranscodeProfile : IMFTranscodeProfile** out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let mfcreatetranscodeprofile =
  foreign "MFCreateTranscodeProfile"
    ((ptr void) @-> returning int32_t)
(* ppTranscodeProfile : IMFTranscodeProfile** out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library mf (t "MF.dll"))
(cffi:use-foreign-library mf)

(cffi:defcfun ("MFCreateTranscodeProfile" mfcreate-transcode-profile :convention :stdcall) :int32
  (pp-transcode-profile :pointer))   ; IMFTranscodeProfile** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $MFCreateTranscodeProfile = Win32::API::More->new('MF',
    'int MFCreateTranscodeProfile(LPVOID ppTranscodeProfile)');
# my $ret = $MFCreateTranscodeProfile->Call($ppTranscodeProfile);
# ppTranscodeProfile : IMFTranscodeProfile** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目
使用する型