
Recherche avancée
Médias (91)
-
Chuck D with Fine Arts Militia - No Meaning No
15 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
Paul Westerberg - Looking Up in Heaven
15 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
Le Tigre - Fake French
15 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
Thievery Corporation - DC 3000
15 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
Dan the Automator - Relaxation Spa Treatment
15 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
Gilberto Gil - Oslodum
15 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
Autres articles (60)
-
HTML5 audio and video support
13 avril 2011, parMediaSPIP 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 2011MediaSPIP 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, parLes 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 nevernewI'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

/*
 #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(&f.data))))
}
func Linesize(f *Frame) int {
 return int(*(*C.int)(unsafe.Pointer(&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.Create(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 < 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 correctly write
 // this to a file, the file is created, but when I open it in GIMP
 // the image is mostly black with glitchy fuzz - so it's not being
 // written properly; the header seems to be ok, it knows the height
 // and width at least.

 data := make([]byte, l*3)

 ptr := unsafe.Pointer(d)
 for i := 0; i < l; i++ {
 datum := (*uint8)(unsafe.Pointer(uintptr(ptr) + (uintptr(i)+(uintptr(y)*uintptr(l)))*unsafe.Sizeof(*d)))
 data = append(data, *datum)
 //fmt.Println(*datum)
 }

 n, err := file.Write(data)
 if err != nil {
 log.Println("Error Writing:", szFilename, "-", n)
 }
 }

 file.Close()
}




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 ?



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



Update : My fix using a C function to save :



package avutil

/*
 #cgo pkg-config: libavutil
 #include <libavutil></libavutil>frame.h>
 #include 
 #include 

 void SaveFrame(const char* location, AVFrame *pFrame, int width, int height) {
 FILE *pFile;
 int y;

 // Open file
 pFile=fopen(location, "wb");
 if(pFile==NULL)
 return;

 // Write header
 fprintf(pFile, "P6\n%d %d\n255\n", width, height);

 // Write pixel data
 for(y=0; ydata[0]+y*pFrame->linesize[0], 1, width*3, pFile);

 // Close file
 fclose(pFile);
 }
 uint8_t* GetData(AVFrame *pFrame) {
 return pFrame->data[0];
 }
*/
import "C"




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



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



-
CGO : How do I write to a file in Golang using a pointer to the C data ?
24 avril 2018, par nevernewI’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 < 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(&f.data))))
}
func Linesize(f *Frame) int {
return int(*(*C.int)(unsafe.Pointer(&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 < 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 < 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 nevernewI’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 := &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.