Hello Tello Pilot!
Join our DJI Tello community & remove this banner.
Sign up

Gobot - Saving video

FlandersNed

Active member
Joined
May 30, 2018
Messages
27
Reaction score
4
I have been using the Gobot sample code to display video into mplayer, and do a simple takeoff/landing.

Code:
 package main

  import (
      "fmt"
      "os/exec"
      "time"

      "gobot.io/x/gobot"
      "gobot.io/x/gobot/platforms/dji/tello"
  )

  func main() {
      drone := tello.NewDriver("8890")

      work := func() {
          mplayer := exec.Command("mplayer","-fps", "25", "-")
          mplayerIn, _ := mplayer.StdinPipe()
          if err := mplayer.Start(); err != nil {
              fmt.Println(err)
              return
          }

          drone.On(tello.ConnectedEvent, func(data interface{}) {
              fmt.Println("Connected")
              drone.StartVideo()
              drone.SetVideoEncoderRate(5)
              gobot.Every(100*time.Millisecond, func() {
                  drone.StartVideo()
              })
          })
          
          drone.TakeOff()

          gobot.After(5*time.Second, func() {
              drone.Land()
          })

          drone.On(tello.VideoFrameEvent, func(data interface{}) {
              pkt := data.([]byte)
              if _, err := mplayerIn.Write(pkt); err != nil {
                  fmt.Println(err)
              }
          })
      }

      robot := gobot.NewRobot("tello",
          []gobot.Connection{},
          []gobot.Device{drone},
          work,
      )

      robot.Start()
  }
How can I use mplayer to save the video stream to a file? I've seen something called -dumpstream (and -dumpfile) but I don't know how I'd apply this here.
 

gss

Member
Joined
Apr 29, 2019
Messages
7
Reaction score
4
Hi, i see that no one answered here, but in case you are still interested or if someone else has the same need, guess would be possible by passing some mplayer command line options...
I succeded on this, see the following excerpt with a modified TelloTerm version (see also SMerrony/telloterm):

// start external mplayer instance...
// the -vo X11 parm allows it to run nicely inside a virtual machine
// setting the FPS to 60 seems to produce smoother video
var player *exec.Cmd
if *x11Flag {
player = exec.Command("mplayer", "-nosound", "-capture", "-vo", "x11", "-fps", "60", "-")
} else if *swinFlag {
player = exec.Command("mplayer", "-nosound", "-capture", "-vf", "scale", "-zoom", "-xy", "320", "-fps", "60", "-")
} else if *streamFlag {
player = exec.Command("mplayer", "-nosound", "-dumpvideo", "-fps", "60", "-")
} else {
player = exec.Command("mplayer", "-nosound", "-capture", "-fps", "60", "-")
}


Bottom line you have simply to add something like this:

- either
"mplayer -nosound -dumpvideo -fps 60"
(here you'll have the raw video stream automatically saved into "stream.dump" file)
- or
"mplayer -nosound -capture -fps 60"
(and here you may start/stop capture into the mplayer windows by pressing "c", then again you'll have the raw video stream automatically saved into "stream.dump" file)

In both case you may later watch the captured stream with mplayer or ffmpeg decoding.
A playback example is "mplayer -nosound -fps 60 streamp.dump""

Hope this helps

Cheers,
GSS
 

zantarob

Member
Joined
Feb 28, 2019
Messages
18
Reaction score
4
Hi, i see that no one answered here, but in case you are still interested or if someone else has the same need, guess would be possible by passing some mplayer command line options...
I succeded on this, see the following excerpt with a modified TelloTerm version (see also SMerrony/telloterm):

// start external mplayer instance...
// the -vo X11 parm allows it to run nicely inside a virtual machine
// setting the FPS to 60 seems to produce smoother video
var player *exec.Cmd
if *x11Flag {
player = exec.Command("mplayer", "-nosound", "-capture", "-vo", "x11", "-fps", "60", "-")
} else if *swinFlag {
player = exec.Command("mplayer", "-nosound", "-capture", "-vf", "scale", "-zoom", "-xy", "320", "-fps", "60", "-")
} else if *streamFlag {
player = exec.Command("mplayer", "-nosound", "-dumpvideo", "-fps", "60", "-")
} else {
player = exec.Command("mplayer", "-nosound", "-capture", "-fps", "60", "-")
}


Bottom line you have simply to add something like this:

- either
"mplayer -nosound -dumpvideo -fps 60"
(here you'll have the raw video stream automatically saved into "stream.dump" file)
- or
"mplayer -nosound -capture -fps 60"
(and here you may start/stop capture into the mplayer windows by pressing "c", then again you'll have the raw video stream automatically saved into "stream.dump" file)

In both case you may later watch the captured stream with mplayer or ffmpeg decoding.
A playback example is "mplayer -nosound -fps 60 streamp.dump""

Hope this helps

Cheers,
GSS
Thank you so much.
 
  • Like
Reactions: umanbean

New Threads

Members online

Forum statistics

Threads
3,243
Messages
25,084
Members
8,358
Latest member
Sai harish