Recherche avancée

Médias (91)

Autres articles (60)

  • HTML5 audio and video support

    13 avril 2011, par

    MediaSPIP uses HTML5 video and audio tags to play multimedia files, taking advantage of the latest W3C innovations supported by modern browsers.
    The MediaSPIP player used has been created specifically for MediaSPIP and can be easily adapted to fit in with a specific theme.
    For older browsers the Flowplayer flash fallback is used.
    MediaSPIP allows for media playback on major mobile platforms with the above (...)

  • Support audio et vidéo HTML5

    10 avril 2011

    MediaSPIP utilise les balises HTML5 video et audio pour la lecture de documents multimedia en profitant des dernières innovations du W3C supportées par les navigateurs modernes.
    Pour les navigateurs plus anciens, le lecteur flash Flowplayer est utilisé.
    Le lecteur HTML5 utilisé a été spécifiquement créé pour MediaSPIP : il est complètement modifiable graphiquement pour correspondre à un thème choisi.
    Ces technologies permettent de distribuer vidéo et son à la fois sur des ordinateurs conventionnels (...)

  • Librairies et binaires spécifiques au traitement vidéo et sonore

    31 janvier 2010, par

    Les logiciels et librairies suivantes sont utilisées par SPIPmotion d’une manière ou d’une autre.
    Binaires obligatoires FFMpeg : encodeur principal, permet de transcoder presque tous les types de fichiers vidéo et sonores dans les formats lisibles sur Internet. CF ce tutoriel pour son installation ; Oggz-tools : outils d’inspection de fichiers ogg ; Mediainfo : récupération d’informations depuis la plupart des formats vidéos et sonores ;
    Binaires complémentaires et facultatifs flvtool2 : (...)

Sur d’autres sites (6882)

  • How do I write to a file in Golang using a pointer to the C data ?

    20 juillet 2020, par nevernew

    I'm writing an app for the windows platform using FFmpeg and it's golang wrapper goav, but I'm having trouble understanding how to use the C pointers to gain access to an array.

    



    I'm trying to write the frame data, pointed to by a uint8 pointer from C, to a .ppm file in golang.

    



    Once I have this done, for proof of concept that FFmpeg is doing what I expect it to, I want to set the frames to a texture in OpenGl to make a video player with cool transitions ; any pointers to do that nice and efficiently would be so very helpful ! I'm guessing I need to write some shader code to draw the ppm as a texture...

    



    The PPM file structure looks pretty simple just the header and then a byte of data for each red, green and blue value of each pixel in the frame from top left to bottom right

    



    I'm starting to understanding how to cast the pointers between C and Go types, but how can I access the data and write it in Go with the same result as C ? In C I just have to set the pointer offset for the data and state how much of it to write :

    



    for (y = 0; y < height; y++) {
    fwrite(pFrame->data[0]+y*pFrame->linesize[0], 1, width*3, pFile);
}


    



    I've stripped out all the relevant parts of the C code, the wrapper and my code, shown below :

    



    C code - libavutil/frame.h

    



    #include 

typedef struct AVFrame {
#define AV_NUM_DATA_POINTERS 8
    uint8_t *data[AV_NUM_DATA_POINTERS];
    int linesize[AV_NUM_DATA_POINTERS];
}


    



    Golang goav wrapper

    



    package avutil&#xA;&#xA;/*&#xA;    #cgo pkg-config: libavutil&#xA;    #include <libavutil></libavutil>frame.h>&#xA;    #include &#xA;*/&#xA;import "C"&#xA;import (&#xA;    "unsafe"&#xA;)&#xA;&#xA;type Frame C.struct_AVFrame&#xA;&#xA;func Data(f *Frame) *uint8 {&#xA;    return (*uint8)(unsafe.Pointer((*C.uint8_t)(unsafe.Pointer(&amp;f.data))))&#xA;}&#xA;func Linesize(f *Frame) int {&#xA;    return int(*(*C.int)(unsafe.Pointer(&amp;f.linesize)))&#xA;}&#xA;

    &#xA;&#xA;

    My Golang code

    &#xA;&#xA;

    package main&#xA;&#xA;import "github.com/giorgisio/goav/avutil"&#xA;&#xA;func saveFrame(videoFrame *avutil.Frame, width int, height int, iFrame int) {&#xA;    var szFilename string&#xA;    var y int&#xA;    var file *os.File&#xA;    var err error&#xA;&#xA;    szFilename = ""&#xA;&#xA;    // Open file&#xA;    szFilename = fmt.Sprintf("frame%d.ppm", iFrame)&#xA;&#xA;    if file, err = os.Create(szFilename); err != nil {&#xA;        log.Println("Error Reading")&#xA;    }&#xA;&#xA;    // Write header&#xA;    fh := []byte(fmt.Sprintf("P6\n%d %d\n255\n", width, height))&#xA;    file.Write(fh)&#xA;    var b byte = 0&#xA;    // Write pixel data&#xA;    for y = 0; y &lt; height; y&#x2B;&#x2B; {&#xA;        d := avutil.Data(videoFrame) // d should be a pointer to the first byte of data&#xA;        l := avutil.Linesize(videoFrame)&#xA;&#xA;        // I&#x27;m basically lost trying to figure out how to correctly write&#xA;        // this to a file, the file is created, but when I open it in GIMP&#xA;        // the image is mostly black with glitchy fuzz - so it&#x27;s not being&#xA;        // written properly; the header seems to be ok, it knows the height&#xA;        // and width at least.&#xA;&#xA;        data := make([]byte, l*3)&#xA;&#xA;        ptr := unsafe.Pointer(d)&#xA;        for i := 0; i &lt; l; i&#x2B;&#x2B; {&#xA;            datum := (*uint8)(unsafe.Pointer(uintptr(ptr) &#x2B; (uintptr(i)&#x2B;(uintptr(y)*uintptr(l)))*unsafe.Sizeof(*d)))&#xA;            data = append(data, *datum)&#xA;            //fmt.Println(*datum)&#xA;        }&#xA;&#xA;        n, err := file.Write(data)&#xA;        if err != nil {&#xA;            log.Println("Error Writing:", szFilename, "-", n)&#xA;        }&#xA;    }&#xA;&#xA;    file.Close()&#xA;}&#xA;

    &#xA;&#xA;

    So, how can I write to a file using a pointer to the data, like you can do in C, and get the same result ?

    &#xA;&#xA;

    The first frame should be black so all 0's but I'm getting a glitchy fuzz, so it must be accessing some random data

    &#xA;&#xA;

    Update : My fix using a C function to save :

    &#xA;&#xA;

    package avutil&#xA;&#xA;/*&#xA;    #cgo pkg-config: libavutil&#xA;    #include <libavutil></libavutil>frame.h>&#xA;    #include &#xA;    #include &#xA;&#xA;    void SaveFrame(const char* location, AVFrame *pFrame, int width, int height) {&#xA;        FILE *pFile;&#xA;        int  y;&#xA;&#xA;        // Open file&#xA;        pFile=fopen(location, "wb");&#xA;        if(pFile==NULL)&#xA;            return;&#xA;&#xA;        // Write header&#xA;        fprintf(pFile, "P6\n%d %d\n255\n", width, height);&#xA;&#xA;        // Write pixel data&#xA;        for(y=0; ydata[0]&#x2B;y*pFrame->linesize[0], 1, width*3, pFile);&#xA;&#xA;        // Close file&#xA;        fclose(pFile);&#xA;    }&#xA;    uint8_t* GetData(AVFrame *pFrame) {&#xA;        return pFrame->data[0];&#xA;    }&#xA;*/&#xA;import "C"&#xA;

    &#xA;&#xA;

    I updated the avutil file, in the goav wrapper package, with this save function at the top, then pass it the frame context so it can get the data pointer from it. I also added this Go function to that avutil file to call the C function

    &#xA;&#xA;

    func SaveFrame(location string, f *Frame, width int, height int) {&#xA;    csLoc := C.CString(location)&#xA;    C.SaveFrame(csLoc, (*C.struct_AVFrame)(unsafe.Pointer(f)), C.int(width), C.int(height))&#xA;    C.free(unsafe.Pointer(csLoc))&#xA;}&#xA;

    &#xA;

  • CGO : How do I write to a file in Golang using a pointer to the C data ?

    24 avril 2018, par nevernew

    I’m writing an app for the windows platform using FFmpeg and it’s golang wrapper goav, but I’m having trouble understanding how to use the C pointers to gain access to an array.

    I’m trying to write the frame data, pointed to by a uint8 pointer from C, to a .ppm file in golang.

    Once I have this done, for proof of concept that FFmpeg is doing what I expect it to, I want to set the frames to a texture in OpenGl to make a video player with cool transitions ; any pointers to do that nice and efficiently would be so very helpful ! I’m guessing I need to write some shader code to draw the ppm as a texture...

    I’m starting to understanding how to cast the pointers between C and Go types, but how can I access the data and write it in Go with the same result as C ? In C I just have to set the pointer offset for the data and state how much of it to write :

    for (y = 0; y &lt; height; y++) {
       fwrite(pFrame->data[0]+y*pFrame->linesize[0], 1, width*3, pFile);
    }

    I’ve stripped out all the relevant parts of the C code, the wrapper and my code, shown below :

    C code - libavutil/frame.h

    #include

    typedef struct AVFrame {
    #define AV_NUM_DATA_POINTERS 8
       uint8_t *data[AV_NUM_DATA_POINTERS];
       int linesize[AV_NUM_DATA_POINTERS];
    }

    Golang goav wrapper

    package avutil

    /*
       #cgo pkg-config: libavutil
       #include <libavutil></libavutil>frame.h>
       #include
    */
    import "C"
    import (
       "unsafe"
    )

    type Frame C.struct_AVFrame

    func Data(f *Frame) *uint8 {
       return (*uint8)(unsafe.Pointer((*C.uint8_t)(unsafe.Pointer(&amp;f.data))))
    }
    func Linesize(f *Frame) int {
       return int(*(*C.int)(unsafe.Pointer(&amp;f.linesize)))
    }

    My Golang code

    package main

    import "github.com/giorgisio/goav/avutil"

    func saveFrame(videoFrame *avutil.Frame, width int, height int, iFrame int) {
       var szFilename string
       var y int
       var file *os.File
       var err error

       szFilename = ""

       // Open file
       szFilename = fmt.Sprintf("frame%d.ppm", iFrame)

       if file, err = os.Open(szFilename); err != nil {
           log.Println("Error Reading")
       }

       // Write header
       fh := []byte(fmt.Sprintf("P6\n%d %d\n255\n", width, height))
       file.Write(fh)
       var b byte = 0
       // Write pixel data
       for y = 0; y &lt; height; y++ {
           d := avutil.Data(videoFrame) // d should be a pointer to the first byte of data
           l := avutil.Linesize(videoFrame)

           // I'm basically lost trying to figure out how to write this to a file
           data := make([]byte, width*3)

           addr := int(*d) + y*l // figure out the address

           for i := 0; i &lt; l; i++ {
               // This is where I'm having the problem, I get an "invalid
               // memory address or nil pointer dereference" error
               byteArrayPtr := (*byte)(unsafe.Pointer(uintptr(addr) + uintptr(i)*unsafe.Sizeof(b)))
               data = append(data, *byteArrayPtr)
               fmt.Println(*byteArrayPtr)
           }
           file.Write(data)
       }

       file.Close()
    }

    So, how can I write to a file using a pointer to the data, like you can do in C ?

  • How to access a C pointer array from Golang

    24 avril 2018, par nevernew

    I’m writing an app for the windows platform using FFmpeg and it’s golang wrapper goav, but I’m having trouble understanding how to use the C pointers to gain access to an array.

    I’m trying to get the streams stored in the AVFormatContext class to use in go, and eventually add frames to a texture in OpenGl to make a video player with cool transitions.

    I think understanding how to cast and access the C data will make coding this a lot easier.

    I’ve stripped out all the relevant parts of the C code, the wrapper and my code, shown below :

    C code - libavformat/avformat.h

    typedef struct AVFormatContext {
       unsigned int nb_streams;
       AVStream **streams;
    }

    Golang goav wrapper

    package avutil

    //#cgo pkg-config: libavformat
    //#include <libavformat></libavformat>avformat.h>
    import "C"
    import (
       "unsafe"
    )

    type Context C.struct_AVFormatContext;

    func (ctxt *Context) StreamsGet(i uintptr) *Stream {
       streams := (**Stream)(unsafe.Pointer(ctxt.streams));
       // I think this is where it's going wrong, I'm brand new to this stuff
       return (*Stream)(unsafe.Pointer(uintptr(unsafe.Pointer(streams)) + i*unsafe.Sizeof(*streams)));
    }

    My Golang code

    package main

    import "github.com/giorgisio/goav/avformat"

    func main() {
       ctx := &amp;avformat.Context{} // the actual function to initiate this does an mallocz for the streams

       stream := ctx.StreamsGet(0)

       //do stuff with stream...
    }

    In C it looks like I just have to do just streams[i], but that wont work in go, so I added a function to the wrapper using the technique from my question here.
    However I’m not getting the data ; It looks like I’m getting a pointer to somewhere random in memory. So, how can I access these elements form golang ? Any resources would be helpful too ; I’m going to be investing a fair bit of time into this.