Skip to content
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

Provide example reading from file #388

Open
carolinasolfernandez opened this issue Sep 19, 2023 · 0 comments
Open

Provide example reading from file #388

carolinasolfernandez opened this issue Sep 19, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@carolinasolfernandez
Copy link

It would be great to have an example reading from a file. I'm trying to make it work without luck

Current code

        reader, _ := wave.NewReader(mediaFile)
	tracks := []kvm.TrackEntry{
		{
			TrackNumber: 1,
			TrackUID:    123,
			TrackType:   2,
			CodecID:     "A_CID",
			Name:        "TEST",
		},
	}
	pro, err := manager.Provider(kvm.StreamName(streamName), tracks)
	if err != nil {
		log.Fatal(err)
	}

	w, err := pro.PutMedia()
	if err != nil {
		log.Fatal(err)
	}
	go func() {
		for {
			fe, err := w.ReadResponse()
			if err != nil {
				log.Println(err)
				return
			}
			log.Printf("response: %+v", *fe)
		}
	}()

	chunk := reader.FmtChunk
	channel := uint64(chunk.Data.Channel)
	samplesPerSec := chunk.Data.SamplesPerSec

	t := uint64(0)

	for {
		d, _ := reader.ReadRawSample()

		data := &kvm.BlockWithBaseTimecode{
			Timecode: t,
			Block: ebml.Block{
				TrackNumber: channel,
				Timecode:    0,
				Keyframe:    true,
				Lacing:      ebml.LacingNo,
				Data:        [][]byte{d},
			},
		}
		if err := w.Write(data); err != nil {
			log.Println(err)
		}
		t += 1000000 / uint64(samplesPerSec) //useconds per sample
		
		if reader.NumSamples == reader.ReadSampleNum {
			break
		}
	}

I'm getting noise when reading so I'm not sure whats' wrong

@carolinasolfernandez carolinasolfernandez changed the title Provde example reading from file Provode example reading from file Sep 19, 2023
@carolinasolfernandez carolinasolfernandez changed the title Provode example reading from file Provide example reading from file Sep 19, 2023
@at-wat at-wat added the enhancement New feature or request label Sep 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants