Skip to content

Commit ab3159d

Browse files
committed
Updated writer
1 parent fe0b071 commit ab3159d

File tree

6 files changed

+9
-9
lines changed

6 files changed

+9
-9
lines changed

encoder.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func newEncoder(ctx *ff.AVFormatContext, stream_id int, param Parameters) (*enco
135135
}
136136

137137
// Some formats want stream headers to be separate.
138-
if ctx.Flags().Is(ff.AVFMT_GLOBALHEADER) {
138+
if ctx.Output().Flags().Is(ff.AVFMT_GLOBALHEADER) {
139139
codecctx.SetFlags(codecctx.Flags() | ff.AV_CODEC_FLAG_GLOBAL_HEADER)
140140
}
141141

pkg/ffmpeg/writer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (w *Writer) Close() error {
7474
if w.output != nil {
7575
// This calls avio_close(w.avio)
7676
fmt.Println("TODO: AVFormat_close_writer")
77-
//result = errors.Join(result, ff.AVFormat_close_writer(w.output))
77+
result = errors.Join(result, ff.AVFormat_close_writer(w.output))
7878
w.output = nil
7979
}
8080

pkg/ffmpeg/writer_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ func Test_writer_001(t *testing.T) {
2222
// Create a writer with an audio stream
2323
writer, err := ffmpeg.NewWriter(w,
2424
ffmpeg.OptOutputFormat(w.Name()),
25-
ffmpeg.OptAudioStream(),
26-
ffmpeg.OptVideoStream("1280x720"),
2725
)
2826
if !assert.NoError(err) {
2927
t.FailNow()

sys/ffmpeg61/avformat.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,11 @@ func (ctx *AVFormatContext) Stream(stream int) *AVStream {
254254
}
255255
}
256256

257-
func (ctx *AVFormatContext) Flags() AVFormat {
258-
return AVFormat(ctx.flags)
257+
func (ctx *AVFormatContext) Flags() AVFormatFlag {
258+
return AVFormatFlag(ctx.flags)
259259
}
260260

261-
func (ctx *AVFormatContext) SetFlags(flag AVFormat) {
261+
func (ctx *AVFormatContext) SetFlags(flag AVFormatFlag) {
262262
ctx.flags = C.int(flag)
263263
}
264264

sys/ffmpeg61/avformat_mux.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ func AVFormat_open_writer(writer *AVIOContextEx, format *AVOutputFormat, filenam
2929
ctx.SetPb(writer)
3030
}
3131

32+
ctx.SetFlags(ctx.Flags() | AVFMT_FLAG_CUSTOM_IO)
33+
3234
// TODO: Mark AVFMT_NOFILE
3335

3436
// Return success
@@ -59,7 +61,7 @@ func AVFormat_close_writer(ctx *AVFormatContext) error {
5961
var result error
6062

6163
octx := (*C.struct_AVFormatContext)(ctx)
62-
if octx.oformat.flags&C.int(AVFMT_NOFILE) == 0 && octx.pb != nil {
64+
if octx.oformat.flags&C.int(AVFMT_NOFILE) == 0 && octx.flags&C.int(AVFMT_FLAG_CUSTOM_IO) == 0 {
6365
if err := AVError(C.avio_closep(&octx.pb)); err != 0 {
6466
result = errors.Join(result, err)
6567
}

writer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func createMedia(url string, format Format, metadata []Metadata, params ...Param
8989
}
9090

9191
// Open the output file, if needed
92-
if !ctx.Flags().Is(ff.AVFMT_NOFILE) {
92+
if !ctx.Output().Flags().Is(ff.AVFMT_NOFILE) {
9393
w, err := ff.AVFormat_avio_open(url, ff.AVIO_FLAG_WRITE)
9494
if err != nil {
9595
return nil, errors.Join(err, writer.Close())

0 commit comments

Comments
 (0)