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

How to packet g711 into flv? #39

Open
quanqigu opened this issue Nov 4, 2021 · 2 comments
Open

How to packet g711 into flv? #39

quanqigu opened this issue Nov 4, 2021 · 2 comments

Comments

@quanqigu
Copy link

quanqigu commented Nov 4, 2021

Thanks for your great library.
But I didn't find an example how to use it?
I want transcode g711 to aac?

@quanqigu
Copy link
Author

quanqigu commented Nov 4, 2021

I don't know how to package g711 to flv, so I want to transcocde it to aac.

@quanqigu
Copy link
Author

quanqigu commented Nov 4, 2021

I have tried to packet pcm into flv, and it works, I can play it with sound via ffplay.
But I don't know why, as there's no tag data when calling CodecDataToTag func.

Could you help me how to packet CodecDataToTag or give some hint for me?

I would be appreciate that. Thanks again.

diff --git a/format/flv/flv.go b/format/flv/flv.go
index db51e79..b23ff55 100644
--- a/format/flv/flv.go
+++ b/format/flv/flv.go
@@ -256,7 +256,63 @@ func CodecDataToTag(stream av.CodecData) (_tag flvio.Tag, ok bool, err error) {
 		}
 		ok = true
 		_tag = tag
+	case av.PCM_MULAW:
+		mlaw := stream.(codec.PCMUCodecData)
+		tag := flvio.Tag{
+			Type:          flvio.TAG_AUDIO,
+			SoundFormat:   flvio.SOUND_MULAW,
+			SoundRate:     flvio.SOUND_5_5Khz,
+			//Data:          stream,
+		}
+		switch mlaw.SampleFormat().BytesPerSample() {
+		case 1:
+			tag.SoundSize = flvio.SOUND_8BIT
+		default:
+			tag.SoundSize = flvio.SOUND_16BIT
+		}
+		switch mlaw.ChannelLayout().Count() {
+		case 1:
+			tag.SoundType = flvio.SOUND_MONO
+		case 2:
+			tag.SoundType = flvio.SOUND_STEREO
+		}
 
+		//TagData - First Byte Data
+		//int data_size=reverse_bytes((byte *)&tagheader.DataSize, sizeof(tagheader.DataSize))-1;
+		//if(output_a!=0){
+		//	//TagData+1
+		//	for (int i=0; i<data_size; i++)
+		//	fputc(fgetc(ifh),afh);
+		//
+		//}else{
+		//	for (int i=0; i<data_size; i++)
+		//	fgetc(ifh);
+		//}
+
+		ok = true
+		_tag = tag
+	case av.PCM_ALAW:
+		alaw := stream.(codec.PCMUCodecData)
+		tag := flvio.Tag{
+			Type:          flvio.TAG_AUDIO,
+			SoundFormat:   flvio.SOUND_MULAW,
+			SoundRate:     flvio.SOUND_5_5Khz,
+			//Data:          stream,
+		}
+		switch alaw.SampleFormat().BytesPerSample() {
+		case 1:
+			tag.SoundSize = flvio.SOUND_8BIT
+		default:
+			tag.SoundSize = flvio.SOUND_16BIT
+		}
+		switch alaw.ChannelLayout().Count() {
+		case 1:
+			tag.SoundType = flvio.SOUND_MONO
+		case 2:
+			tag.SoundType = flvio.SOUND_STEREO
+		}
+		ok = true
+		_tag = tag
 	default:
 		err = fmt.Errorf("flv: unspported codecType=%v", stream.Type())
 		return
@@ -302,6 +358,46 @@ func PacketToTag(pkt av.Packet, stream av.CodecData) (tag flvio.Tag, timestamp i
 			tag.SoundType = flvio.SOUND_STEREO
 		}
 
+	case av.PCM_MULAW:
+		tag = flvio.Tag{
+			Type:          flvio.TAG_AUDIO,
+			SoundFormat:   flvio.SOUND_MULAW,
+			SoundRate:     flvio.SOUND_5_5Khz,
+			Data:          pkt.Data,
+		}
+		astream := stream.(av.AudioCodecData)
+		switch astream.SampleFormat().BytesPerSample() {
+		case 1:
+			tag.SoundSize = flvio.SOUND_8BIT
+		default:
+			tag.SoundSize = flvio.SOUND_16BIT
+		}
+		switch astream.ChannelLayout().Count() {
+		case 1:
+			tag.SoundType = flvio.SOUND_MONO
+		case 2:
+			tag.SoundType = flvio.SOUND_STEREO
+		}
+	case av.PCM_ALAW:
+		tag = flvio.Tag{
+			Type:          flvio.TAG_AUDIO,
+			SoundFormat:   flvio.SOUND_ALAW,
+			SoundRate:     flvio.SOUND_5_5Khz,
+			Data:          pkt.Data,
+		}
+		astream := stream.(av.AudioCodecData)
+		switch astream.SampleFormat().BytesPerSample() {
+		case 1:
+			tag.SoundSize = flvio.SOUND_8BIT
+		default:
+			tag.SoundSize = flvio.SOUND_16BIT
+		}
+		switch astream.ChannelLayout().Count() {
+		case 1:
+			tag.SoundType = flvio.SOUND_MONO
+		case 2:
+			tag.SoundType = flvio.SOUND_STEREO
+		}
 	case av.SPEEX:
 		tag = flvio.Tag{
 			Type:        flvio.TAG_AUDIO,
diff --git a/format/rtmp/rtmp.go b/format/rtmp/rtmp.go
index 7f38296..934de97 100644
--- a/format/rtmp/rtmp.go
+++ b/format/rtmp/rtmp.go
@@ -588,7 +588,7 @@ func (self *Conn) writeConnect(path string) (err error) {
 			"tcUrl":         getTcUrl(self.URL),
 			"fpad":          false,
 			"capabilities":  15,
-			"audioCodecs":   4071,
+			"audioCodecs":   4095,
 			"videoCodecs":   252,
 			"videoFunction": 1,
 		},

@quanqigu quanqigu changed the title Is there any example about using transcode How to packet pcm into flv? Nov 4, 2021
@quanqigu quanqigu changed the title How to packet pcm into flv? How to packet g711 into flv? Nov 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant