'WebRTC MediaDevices with Golang and Pion on a Windows 10 "pkg-config error"

I try to follow this documentation https://github.com/pion/mediadevices. But somehow i constantly run into errors. First i had to install MinGW (gcc). Then i had the problem that i have to install the 64_84 version of it. That done i had the problem that i won't work without pkg-config. So i also installed that. But not finished. Now i had this error:

pkg-config --cflags -- x264</br>
pkg-config --cflags -- x264</br>
pkg-config: exit status 0xc0000135</br>

After a while of trying different non working solutions i found this https://tousu.in/qa/?qa=419107/.

After this it kinda worked. In cmd I could enter pkg-config --help and got an help sheet.

In the MediaDevice Golang project i tried to run the command go run main.go. Sadly now i get this error and now i don't know what to do.

pkg-config --cflags  -- x264 <br />
Package x264 was not found in the pkg-config search path. <br />
Perhaps you should add the directory containing `x264.pc' <br />
to the PKG_CONFIG_PATH environment variable <br />
No package 'x264' found <br />
pkg-config: exit status 1 <br />
PS C:\Projects\go-webrtc_pion> <br />

My main.go looks like this:

package main

import (
    "fmt"
    "image/jpeg"
    "os"

    "github.com/pion/mediadevices"
    "github.com/pion/mediadevices/pkg/codec/x264"
    // "github.com/pion/mediadevices/pkg/driver/camera"
    // "github.com/pion/mediadevices/pkg/prop"

    // This is required to register camera adapter
    _ "github.com/pion/mediadevices/pkg/driver/camera"
    // Note: If you don't have a camera or your adapters are not supported,
    //       you can always swap your adapters with our dummy adapters below.
    // _ "github.com/pion/mediadevices/pkg/driver/videotest"
)

func main() {

    // configure codec specific parameters
    x264Params, _ := x264.NewParams()
    x264Params.Preset = x264.PresetMedium
    x264Params.BitRate = 1_000_000 // 1mbps

    codecSelector := mediadevices.NewCodecSelector(
        mediadevices.WithVideoEncoders(&x264Params),
    )

    
    stream, _ := mediadevices.GetUserMedia(mediadevices.MediaStreamConstraints{
        Video: func(constraint *mediadevices.MediaTrackConstraints) {},
        Codec: codecSelector,
    })
    fmt.Println(stream)

    // Since track can represent audio as well, we need to cast it to 
    // *mediadevices.VideoTrack to get video specific functionalities
    track := stream.GetVideoTracks()[0]
    videoTrack := track.(*mediadevices.VideoTrack)
    defer videoTrack.Close()


    // Create a new video reader to get the decoded frames. Release is used 
    // to return the buffer to hold frame back to the source so that the buffer 
    // can be reused for the next frames.
    videoReader := videoTrack.NewReader(false)
    frame, release, _ := videoReader.Read()
    defer release()

    // Since frame is the standard image.Image, it's compatible with Go standard 
    // library. For example, capturing the first frame and store it as a jpeg image.
    output, _ := os.Create("frame.jpg")
    jpeg.Encode(output, frame, nil)
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source