-
Notifications
You must be signed in to change notification settings - Fork 170
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
unexpected signal during runtime execution #50
Comments
@xuxiangyang Hi. |
sure, Like this package snapshot
import (
"errors"
"github.com/3d0c/gmf"
"io/ioutil"
"os"
)
func Grab(url string) (*os.File, error) {
inputCtx, err := gmf.NewInputCtx(url)
if err != nil {
return nil, err
}
defer inputCtx.CloseInputAndRelease()
srcVideoStream, err := inputCtx.GetBestStream(gmf.AVMEDIA_TYPE_VIDEO)
if err != nil {
return nil, err
}
codec, err := gmf.FindEncoder("mjpeg")
if err != nil {
return nil, err
}
cc := gmf.NewCodecCtx(codec)
defer gmf.Release(cc)
cc.SetPixFmt(gmf.AV_PIX_FMT_YUVJ420P)
cc.SetWidth(srcVideoStream.CodecCtx().Width())
cc.SetHeight(srcVideoStream.CodecCtx().Height())
cc.SetTimeBase(srcVideoStream.CodecCtx().TimeBase().AVR())
if codec.IsExperimental() {
cc.SetStrictCompliance(gmf.FF_COMPLIANCE_EXPERIMENTAL)
}
if err := cc.Open(nil); err != nil {
return nil, err
}
for packet := range inputCtx.GetNewPackets() {
if packet.StreamIndex() != srcVideoStream.Index() {
continue
}
ist, err := inputCtx.GetStream(packet.StreamIndex())
if err != nil {
return nil, err
}
for frame := range packet.Frames(ist.CodecCtx()) {
if p, ready, _ := frame.EncodeNewPacket(cc); ready {
defer gmf.Release(p)
return newFile(p.Data())
}
}
}
return nil, errors.New("can not get Packets")
}
func newFile(b []byte) (*os.File, error) {
fp, err := ioutil.TempFile("", "snapshot_")
if err != nil {
return nil, err
}
defer fp.Close()
_, err = fp.Write(b)
if err != nil {
return nil, err
} else {
return fp, nil
}
} I concomitantly use |
@xuxiangyang Fixed via #51 Please pull latest master and test. I don't know what type of synchronization do you use, but here is my package main
import (
"errors"
"io/ioutil"
"log"
"os"
"sync"
"github.com/3d0c/gmf"
)
func Grab(url string, wg *sync.WaitGroup) (*os.File, error) {
defer wg.Done()
inputCtx, err := gmf.NewInputCtx(url)
if err != nil {
return nil, err
}
defer inputCtx.CloseInputAndRelease()
srcVideoStream, err := inputCtx.GetBestStream(gmf.AVMEDIA_TYPE_VIDEO)
if err != nil {
return nil, err
}
codec, err := gmf.FindEncoder("mjpeg")
if err != nil {
return nil, err
}
cc := gmf.NewCodecCtx(codec)
defer gmf.Release(cc)
cc.SetPixFmt(gmf.AV_PIX_FMT_YUVJ420P)
cc.SetWidth(srcVideoStream.CodecCtx().Width())
cc.SetHeight(srcVideoStream.CodecCtx().Height())
cc.SetTimeBase(srcVideoStream.CodecCtx().TimeBase().AVR())
if codec.IsExperimental() {
cc.SetStrictCompliance(gmf.FF_COMPLIANCE_EXPERIMENTAL)
}
if err := cc.Open(nil); err != nil {
return nil, err
}
for packet := range inputCtx.GetNewPackets() {
if packet.StreamIndex() != srcVideoStream.Index() {
continue
}
ist, err := inputCtx.GetStream(packet.StreamIndex())
if err != nil {
return nil, err
}
for frame := range packet.Frames(ist.CodecCtx()) {
if p, ready, _ := frame.EncodeNewPacket(cc); ready {
defer gmf.Release(p)
return newFile(p.Data())
}
}
}
return nil, errors.New("can not get Packets")
}
func newFile(b []byte) (*os.File, error) {
log.Println("len(b):", len(b))
fp, err := ioutil.TempFile("./", "snapshot_")
if err != nil {
return nil, err
}
defer fp.Close()
n, err := fp.Write(b)
log.Println(n, "written to", fp.Name())
if err != nil {
return nil, err
} else {
return fp, nil
}
}
func main() {
// runtime.GOMAXPROCS(runtime.NumCPU())
src := []string{"tmp/vid480.mp4", "tmp/vid481.mp4", "tmp/vid482.mp4", "tmp/vid483.mp4", "tmp/vid484.mp4", "tmp/vid485.mp4"}
wg := new(sync.WaitGroup)
for _, url := range src {
wg.Add(1)
go func(url string) {
fp, err := Grab(url, wg)
log.Println(fp, err)
}(url)
}
wg.Wait()
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am using master gmf with golang 1.7, I got this error when concurrency convert flv to mjpeg
what could I do with this error?
The text was updated successfully, but these errors were encountered: