douqipi9704 2016-12-01 23:31
浏览 272

如何使用Go读取FFMPEG?

How can you read UDP sent from ffmpeg?

I wrote a script to listen to UDP packets and write them into file, but the file is invalid and almost twice the size.

This is how I send the data:

ffmpeg -i video.mp4 -c:a aac -ar 48000 -ab 196k \
 -ac 2 -strict -2 -c:v libx264 -vb 500k -r 25 -s 320x240 \
 -ss 00.000 -f mp4 -movflags frag_keyframe+empty_moov \ udp://127.0.0.1:1936

This is the code in Go. It should simply write the video into a new video file:

package main

import (
  "net"
  "os"
)

func main(){
  var buf []byte = make([]byte, 512)
  addr, _ := net.ResolveUDPAddr("udp", ":1936")
  conn, _ := net.ListenUDP("udp", addr)
  defer conn.Close()

  os.Create("new_video.mp4")
  f, _ := os.OpenFile("new_video.mp4", syscall.O_WRONLY, 0644)
  defer f.Close()


  for {
    n, _ := conn.Read(buf)
    f.Write(buf[0:n])
    buf = make([]byte, 512)
  }
}

Thanks

Updated

I changed the format to mp4 but the file is still invalid.

  • 写回答

1条回答 默认 最新

  • dtlc84438 2016-12-02 04:29
    关注

    The buffer size on the server was too small (512byte)

    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序