Skip to content

Commit

Permalink
transcode pts bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
3d0c committed Apr 25, 2014
1 parent 2e9a999 commit 5867570
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
22 changes: 22 additions & 0 deletions codecCtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,14 @@ func (this *CodecCtx) ChannelLayout() int {
return int(this.avCodecCtx.channel_layout)
}

func (this *CodecCtx) BitRate() int {
return int(this.avCodecCtx.bit_rate)
}

func (this *CodecCtx) Channels() int {
return int(this.avCodecCtx.channels)
}

func (this *CodecCtx) SetBitRate(val int) *CodecCtx {
this.avCodecCtx.bit_rate = C.int(val)
return this
Expand Down Expand Up @@ -310,6 +318,16 @@ func (this *CodecCtx) SetStrictCompliance(val int) *CodecCtx {
return this
}

func (this *CodecCtx) SetHasBframes(val int) *CodecCtx {
this.avCodecCtx.has_b_frames = C.int(val)
return this
}

func (this *CodecCtx) SetChannels(val int) *CodecCtx {
this.avCodecCtx.channels = C.int(val)
return this
}

func (this *CodecCtx) SelectSampleRate() int {
return int(C.select_sample_rate(this.codec.avCodec))
}
Expand All @@ -321,3 +339,7 @@ func (this *CodecCtx) SelectChannelLayout() int {
func (this *CodecCtx) FlushBuffers() {
C.avcodec_flush_buffers(this.avCodecCtx)
}

func (this *CodecCtx) Dump() {
fmt.Println(this.avCodecCtx)
}
24 changes: 16 additions & 8 deletions examples/transcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ func addStream(codecName string, oc *FmtCtx, ist *Stream) (int, int) {
fatal(errors.New("unable to create codec context"))
}

cc.CopyBasic(ist)

if oc.IsGlobalHeader() {
cc.SetFlag(CODEC_FLAG_GLOBAL_HEADER)
}
Expand All @@ -49,8 +47,19 @@ func addStream(codecName string, oc *FmtCtx, ist *Stream) (int, int) {
}

if cc.Type() == AVMEDIA_TYPE_AUDIO {
// cc.SetSampleFmt(AV_SAMPLE_FMT_S16).SetBitRate(64000)
cc.SetSampleFmt(ist.CodecCtx().SampleFmt())
cc.SetSampleRate(ist.CodecCtx().SampleRate())
cc.SetChannels(ist.CodecCtx().Channels())
cc.SelectChannelLayout()
cc.SelectSampleRate()

}

if cc.Type() == AVMEDIA_TYPE_VIDEO {
cc.SetTimeBase(AVR{1, 25})
cc.SetProfile(FF_PROFILE_MPEG4_SIMPLE)
cc.SetDimension(ist.CodecCtx().Width(), ist.CodecCtx().Height())
cc.SetPixFmt(ist.CodecCtx().PixFmt())
}

if err := cc.Open(nil); err != nil {
Expand Down Expand Up @@ -128,11 +137,11 @@ func main() {

if p, ready, _ := frame.Encode(ost.CodecCtx()); ready {
if p.Pts() != AV_NOPTS_VALUE {
p.SetPts(RescaleQ(p.Pts(), ost.CodecCtx().TimeBase(), ist.TimeBase()))
p.SetPts(RescaleQ(p.Pts(), ost.CodecCtx().TimeBase(), ost.TimeBase()))
}

if p.Dts() != AV_NOPTS_VALUE {
p.SetDts(RescaleQ(p.Dts(), ost.CodecCtx().TimeBase(), ist.TimeBase()))
p.SetDts(RescaleQ(p.Dts(), ost.CodecCtx().TimeBase(), ost.TimeBase()))
}

p.SetStreamIndex(ost.Index())
Expand All @@ -157,11 +166,11 @@ func main() {
for {
if p, ready, _ := frame.Flush(ost.CodecCtx()); ready {
if p.Pts() != AV_NOPTS_VALUE {
p.SetPts(RescaleQ(p.Pts(), ost.CodecCtx().TimeBase(), ist.TimeBase()))
p.SetPts(RescaleQ(p.Pts(), ost.CodecCtx().TimeBase(), ost.TimeBase()))
}

if p.Dts() != AV_NOPTS_VALUE {
p.SetDts(RescaleQ(p.Dts(), ost.CodecCtx().TimeBase(), ist.TimeBase()))
p.SetDts(RescaleQ(p.Dts(), ost.CodecCtx().TimeBase(), ost.TimeBase()))
}

p.SetStreamIndex(ost.Index())
Expand All @@ -178,5 +187,4 @@ func main() {

frame.Free()
}

}

0 comments on commit 5867570

Please sign in to comment.