
Recherche avancée
Médias (1)
-
Somos millones 1
21 juillet 2014, par
Mis à jour : Juin 2015
Langue : français
Type : Video
Autres articles (94)
-
Les notifications de la ferme
1er décembre 2010, parAfin d’assurer une gestion correcte de la ferme, il est nécessaire de notifier plusieurs choses lors d’actions spécifiques à la fois à l’utilisateur mais également à l’ensemble des administrateurs de la ferme.
Les notifications de changement de statut
Lors d’un changement de statut d’une instance, l’ensemble des administrateurs de la ferme doivent être notifiés de cette modification ainsi que l’utilisateur administrateur de l’instance.
À la demande d’un canal
Passage au statut "publie"
Passage au (...) -
D’autres logiciels intéressants
12 avril 2011, parOn ne revendique pas d’être les seuls à faire ce que l’on fait ... et on ne revendique surtout pas d’être les meilleurs non plus ... Ce que l’on fait, on essaie juste de le faire bien, et de mieux en mieux...
La liste suivante correspond à des logiciels qui tendent peu ou prou à faire comme MediaSPIP ou que MediaSPIP tente peu ou prou à faire pareil, peu importe ...
On ne les connais pas, on ne les a pas essayé, mais vous pouvez peut être y jeter un coup d’oeil.
Videopress
Site Internet : (...) -
Les formats acceptés
28 janvier 2010, parLes commandes suivantes permettent d’avoir des informations sur les formats et codecs gérés par l’installation local de ffmpeg :
ffmpeg -codecs ffmpeg -formats
Les format videos acceptés en entrée
Cette liste est non exhaustive, elle met en exergue les principaux formats utilisés : h264 : H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 m4v : raw MPEG-4 video format flv : Flash Video (FLV) / Sorenson Spark / Sorenson H.263 Theora wmv :
Les formats vidéos de sortie possibles
Dans un premier temps on (...)
Sur d’autres sites (12353)
-
How to implement live video streaming with ffmpeg without using WebRTC ?
8 août 2024, par ArtemFollowing up on my previous question, I'd like to inquire about alternative methods for live video streaming using ffmpeg (WebRTC is not an option due to certain constraints I prefer not to discuss here).


Context :


I have a Go application where a goroutine launches ffmpeg to process a video stream, which is then delivered to the main goroutine via a
chan []byte
. I tried using WebSocket, but encountered issues as described in the previous question. HLS also didn't work well due to significant latency and artifacts like green squares on the video.

Based on a comment in the previous question, I attempted to stream the video via a simple GET request. Here's the Go handler I implemented :


func stream(helperApp agent.Helper) func(rw http.ResponseWriter, rr *http.Request) {
 a := atomic.Bool{}
 return func(rw http.ResponseWriter, rr *http.Request) {
 if !a.CAS(false, true) {
 http.Error(rw, "already running", http.StatusInternalServerError)
 return
 }

 rw.Header().Set("Access-Control-Allow-Origin", "*")
 rw.Header().Set("Content-Type", "video/mp2t")

 out := make(chan []byte)

 // create StreamParam
 go ScreenCaptureForLiveStream(StreamParam, out) // ffmpeg process starts inside

 r, w := io.Pipe()
 go func() {
 for data := range out {
 w.Write(data)
 fmt.Println(len(data))
 }
 }()
 io.Copy(rw, r)
 }
}




On the client side (HTML) :


<video muted="muted" src="http://localhost:8080/stream" controls="controls"></video>



In the browser console, I can see data being received, but the video doesn't play.


FFmpeg is executed with these parameters :


-loglevel error -f avfoundation -framerate 5 -capture_cursor 1 -capture_mouse_clicks 1 -i 1 -c:v libx264 -pix_fmt yuv420p -vf pad='ceil(iw/2)*2:ceil(ih/2)*2' -threads 0 -preset veryfast -bf 2 -f mpegts pipe:1




For validation, I ran :


ffmpeg -i http://localhost:8080/stream -c copy out.mp4




The video was successfully saved and plays.


Question :
What alternative methods exist to implement live video streaming with ffmpeg, aside from WebRTC ? Why does the current approach of streaming video via HTTP GET request not function correctly in the browser, and how can this be resolved ?


-
How to stop FFMPEG without stop application in Golang ?
23 juillet 2022, par TammamI'm making a WEB-based screen record application (if the link is accessed then the record will run) using FFMPEG, but I still haven't found a way to stop the record without stopping the web application (Now still pressing Ctrl+C to stop the recording process and the application will stop too). How do I do that when I click a link (eg host/record/stop) the record will stop without stopping the application


here my code


//Handler to create room/start record
func RoomCreate(c *fiber.Ctx) error {
 fileName := "out.mp4"
 fmt.Println(fileName)
 if len(os.Args) > 1 {
 fileName = os.Args[1]
 }

 

 errCh := make(chan error, 2)
 ctx, cancelFn := context.WithCancel(context.Background())
 // Record
 go func() { errCh <- recordToVideo(ctx, fileName) }()

 go func() {
 errCh <- nil
 }()
 err := <-errCh
 cancelFn()
 if err != nil && err != context.Canceled {
 log.Fatalf("Execution failed: %v", err)
 }
 
 return c.Redirect(fmt.Sprintf("/room/%s", guuid.New().String()))
}

func recordToVideo(ctx context.Context, fileName string) error {
 ctx, cancelFn := context.WithCancel(ctx)
 defer cancelFn()
 // Build ffmpeg
 ffmpeg := exec.Command("ffmpeg",
 "-f", "gdigrab",
 "-framerate", "30",
 "-i", "desktop",
 fileName,
 )
 // Stdin for sending data
 stdin, err := ffmpeg.StdinPipe()
 if err != nil {
 return err
 }
 //var buf bytes.Buffer
 defer stdin.Close()
 // Run it in the background
 errCh := make(chan error, 1)

 go func() {
 fmt.Printf("Executing: %v\n", strings.Join(ffmpeg.Args, " "))
 //Here if
 out, err := ffmpeg.CombinedOutput()
 fmt.Printf("FFMPEG output:\n%v\n", string(out))
 errCh <- err
 }()
 // Just start sending a bunch of frames
 for {
 // Check if we're done, otherwise go again
 select {
 case <-ctx.Done():
 return ctx.Err()
 case err := <-errCh:
 return err
 default:
 }
 }
}

//Function to run command FFMPEG
func recordToVideo(ctx context.Context, fileName string) error {
 ctx, cancelFn := context.WithCancel(ctx)
 defer cancelFn()
 // Build ffmpeg
 ffmpeg := exec.Command("ffmpeg",
 "-f", "gdigrab",
 "-framerate", "30",
 "-i", "desktop",
 "-f", "mp4",
 fileName,
 )
 // Stdin for sending data
 stdin, err := ffmpeg.StdinPipe()
 if err != nil {
 return err
 }
 //var buf bytes.Buffer
 defer stdin.Close()
 // Run it in the background
 errCh := make(chan error, 1)

 go func() {
 fmt.Printf("Executing: %v\n", strings.Join(ffmpeg.Args, " "))
 
 if err := ffmpeg.Run(); err != nil {
 return
 }
 //fmt.Printf("FFMPEG output:\n%v\n", string(out))
 errCh <- err
 }()
 // Just start sending a bunch of frames
 for {
 
 // Check if we're done, otherwise go again
 select {
 case <-ctx.Done():
 return ctx.Err()
 case err := <-errCh:
 return err
 default:
 }
 }
}



Thanks for advance


-
Does anyone use go-av to parse mp4 audio and then use oto/portaudio to output it ?
27 juillet 2021, par sevenit is use go-av to get audio


func audio() (<-chan []byte, error) {
 buffer := make(chan []byte, 1024)
 go func() {
 ......
 for inCtx.AvReadFrame(pkt) >= 0 {
 if pkt.StreamIndex() == audioStreamIndex {
 l := pCodecCtx.AvcodecDecodeAudio4((*avcodec.Frame)(unsafe.Pointer(utilFrame)), &gotName, pkt)
 //fmt.Println("AvcodecDecodeAudio4:", l)
 if l < 0 {
 fmt.Println("codec decode audio4 error")
 os.Exit(1)
 }
 if gotName > 0 {

 fram := getFramBytes(utilFrame)
 fmt.Println("buf add:", index)
 buffer <- fram

 }
 }
 pkt.AvFreePacket()
 }
 go func() {
 for {
 if len(buffer) <= 0 {
 fmt.Println("close buf")
 close(buffer)
 break
 }
 }
 }()

 (*avcodec.Context)(unsafe.Pointer(pCodecCtxOrig)).AvcodecClose()
 }()
 return buffer, nil
}
func getFramBytes(f *avutil.Frame) []byte {
 data := avutil.Data(f)
 var bf = make([]byte, len(data))
 for i := 0; i < len(data); i++ {

 if data[i] != nil {
 bf = append(bf, *data[i])
 }
 }
 return bf
}




and it is output it


func main() {

 portaudio.Initialize()
 defer portaudio.Terminate()
 out := make([]int32, 8192)
 stream, err := portaudio.OpenDefaultStream(0, 1, 44100, len(out), &out)
 defer stream.Close()
 if err != nil {
 fmt.Println(err)
 return
 }
 err = stream.Start()
 if err != nil {
 fmt.Println(err)
 return
 }
 defer stream.Stop()
 buf, err := audio()
 if err != nil {
 fmt.Println(err)
 return
 }
 //index := 0
 //c, err := oto.NewContext(44100, 2, 2, 8192)
 //if err != nil {
 // return
 //}
 //defer c.Close()
 //
 //p := c.NewPlayer()
 //defer p.Close()
 for {
 select {
 case frame, ok := <-buf:
 if !ok {
 os.Exit(0)
 }
 //index += 1
 //fmt.Println("$$:", index)
 //if _, err := io.Copy(p, bytes.NewReader(frame)); err != nil {
 // fmt.Println(err)
 // return
 //}
 err := binary.Read(bytes.NewReader(frame), binary.BigEndian, out)
 if err != nil {
 fmt.Println("binary.Read:", err)
 os.Exit(0)
 }
 err = stream.Write()
 if err != nil {
 fmt.Println("stream.Write:", err)
 os.Exit(0)
 }
 }
 }

}




** the result is**


binary.Read : unexpected EOF


if use oto it has no effect


Has anyone used this method, or is there any other way to use go-av to play audio and video ?


Is there a problem in use ? I feel that there is a problem with the data conversion from the audio decoding.


Maybe there is a problem with getFramBytes