Skip to content

Commit 61ee559

Browse files
committed
Updated encoder
1 parent 80efb24 commit 61ee559

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

pkg/ffmpeg/encoder.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,6 @@ func (e *Encoder) encode(frame *ff.AVFrame, fn EncoderPacketFn) error {
184184

185185
// Send the frame to the encoder
186186
if err := ff.AVCodec_send_frame(e.ctx, frame); err != nil {
187-
if errors.Is(err, syscall.EAGAIN) || errors.Is(err, io.EOF) {
188-
return nil
189-
}
190187
return err
191188
}
192189

@@ -201,6 +198,10 @@ func (e *Encoder) encode(frame *ff.AVFrame, fn EncoderPacketFn) error {
201198
return err
202199
}
203200

201+
// rescale output packet timestamp values from codec to stream timebase
202+
ff.AVCodec_packet_rescale_ts(e.packet, e.ctx.TimeBase(), e.stream.TimeBase())
203+
e.packet.SetStreamIndex(e.stream.Index())
204+
204205
// Pass back to the caller
205206
if err := fn(e.packet, &timebase); errors.Is(err, io.EOF) {
206207
// End early, return EOF

pkg/ffmpeg/par.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,21 @@ func NewVideoPar(pixfmt string, size string, framerate float64) (*Par, error) {
8080
// Set default sample aspect ratio
8181
par.SetSampleAspectRatio(ff.AVUtil_rational(1, 1))
8282

83+
/* TODO
84+
c->gop_size = 12; // emit one intra frame every twelve frames at most
85+
c->pix_fmt = STREAM_PIX_FMT;
86+
if (c->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
87+
// just for testing, we also add B-frames
88+
c->max_b_frames = 2;
89+
}
90+
if (c->codec_id == AV_CODEC_ID_MPEG1VIDEO) {
91+
// Needed to avoid using macroblocks in which some coeffs overflow.
92+
// This does not happen with normal video, it just happens here as
93+
// the motion of the chroma plane does not match the luma plane.
94+
c->mb_decision = 2;
95+
}
96+
*/
97+
8398
// Return success
8499
return par, nil
85100
}

sys/ffmpeg61/avcodec_packet.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ func (ctx *AVPacket) StreamIndex() int {
110110
return int(ctx.stream_index)
111111
}
112112

113+
func (ctx *AVPacket) SetStreamIndex(index int) {
114+
ctx.stream_index = C.int(index)
115+
}
116+
113117
func (ctx *AVPacket) Pts() int64 {
114118
return int64(ctx.pts)
115119
}

0 commit comments

Comments
 (0)