-
Notifications
You must be signed in to change notification settings - Fork 499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No RTSP client example file #11
Comments
Yes, it would be nice. |
I'd like to see this too |
+1, I'd like to see as well |
@nareix Ping :) |
Anyone got it working? Any examples? |
+1 this would be really helpful. |
I finally got this working. It turned out to be a lot simpler than I thought. It uses a modified version of CopyFile and CopyPackets from the avutil package in order to stop copying packets from a live stream. package main
import (
"flag"
"io"
"time"
"github.com/nareix/joy4/av"
"github.com/nareix/joy4/av/avutil"
"github.com/nareix/joy4/format"
)
func init() {
format.RegisterAll()
}
func main() {
srcfile := flag.String("src", "rtsp://192.168.1.1/camera1", "Source file")
dstfile := flag.String("dst", "output.mp4", "Output file")
max := flag.Int("max", 5, "Max seconds")
flag.Parse()
src, err := avutil.Open(*srcfile)
if err != nil {
panic(err)
}
dst, err := avutil.Create(*dstfile)
if err != nil {
panic(err)
}
// same as calling avutil.CopyFile(dst, src) but added
// max duration in case the src is live and never ends
err = CopyFileMax(dst, src, time.Duration(*max)*time.Second)
if err != nil {
panic(err)
}
}
func CopyPacketsMax(dst av.PacketWriter, src av.PacketReader, max time.Duration) (err error) {
for {
var pkt av.Packet
if pkt, err = src.ReadPacket(); err != nil {
if err == io.EOF {
err = nil
break
}
return
}
// break when max time has been reached
if max > 0 && pkt.Time >= max {
return
}
if err = dst.WritePacket(pkt); err != nil {
return
}
}
return
}
func CopyFileMax(dst av.Muxer, src av.Demuxer, max time.Duration) (err error) {
var streams []av.CodecData
if streams, err = src.Streams(); err != nil {
return
}
if err = dst.WriteHeader(streams); err != nil {
return
}
if err = CopyPacketsMax(dst, src, max); err != nil {
return
}
if err = dst.WriteTrailer(); err != nil {
return
}
return
} |
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you please provide some example file that reads RTSP video and then write the data to some other file?Currently there is no example file relating to RTSP.
The text was updated successfully, but these errors were encountered: