chore: upgrade purego-ffmpeg to v0.3.0 and update transcoder API
Migrate from v0.1.0 flat API to v0.3.0 convenience API. Constant renames only — no logic changes. All 84 transcoder tests pass.
- commit
- defbe8a6c83576f8c7635ed1df0c2c064f482ca4
- author
- brice · · 2026-03-28 05:37 UTC
- parent
- 5023d63
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
5 files · +28 -58
M go.mod +2 -10
| @@ -4,7 +4,7 @@ go 1.26.1 | |||
| 4 | 4 | ||
| 5 | 5 | require ( | |
| 6 | 6 | github.com/bnema/purego-cef v0.0.0-00010101000000-000000000000 | |
| 7 | - | github.com/bnema/purego-ffmpeg v0.1.0 | |
| 7 | + | github.com/bnema/purego-ffmpeg v0.3.0 | |
| 8 | 8 | github.com/bnema/purego-sqlite v0.1.1 | |
| 9 | 9 | github.com/bnema/puregotk v0.2.2 | |
| 10 | 10 | github.com/bnema/puregotk-webkit v0.0.16 | |
| @@ -24,11 +24,8 @@ require ( | |||
| 24 | 24 | golang.org/x/image v0.38.0 | |
| 25 | 25 | golang.org/x/sys v0.42.0 | |
| 26 | 26 | gopkg.in/yaml.v3 v3.0.1 | |
| 27 | - | modernc.org/sqlite v1.47.0 | |
| 28 | 27 | ) | |
| 29 | 28 | ||
| 30 | - | replace github.com/ebitengine/purego => github.com/bnema/purego v0.0.0-20260323095903-91aa177a2704 | |
| 31 | - | ||
| 32 | 29 | replace github.com/bnema/purego-cef => ../purego-cef | |
| 33 | 30 | ||
| 34 | 31 | replace github.com/bnema/purego-ffmpeg => ../purego-ffmpeg | |
| @@ -45,7 +42,6 @@ require ( | |||
| 45 | 42 | github.com/clipperhouse/uax29/v2 v2.5.0 // indirect | |
| 46 | 43 | github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect | |
| 47 | 44 | github.com/davecgh/go-spew v1.1.1 // indirect | |
| 48 | - | github.com/dustin/go-humanize v1.0.1 // indirect | |
| 49 | 45 | github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect | |
| 50 | 46 | github.com/go-viper/mapstructure/v2 v2.5.0 // indirect | |
| 51 | 47 | github.com/inconshreveable/mousetrap v1.1.0 // indirect | |
| @@ -58,9 +54,7 @@ require ( | |||
| 58 | 54 | github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect | |
| 59 | 55 | github.com/muesli/cancelreader v0.2.2 // indirect | |
| 60 | 56 | github.com/muesli/termenv v0.16.0 // indirect | |
| 61 | - | github.com/ncruces/go-strftime v1.0.0 // indirect | |
| 62 | 57 | github.com/pmezard/go-difflib v1.0.0 // indirect | |
| 63 | - | github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect | |
| 64 | 58 | github.com/rivo/uniseg v0.4.7 // indirect | |
| 65 | 59 | github.com/russross/blackfriday/v2 v2.1.0 // indirect | |
| 66 | 60 | github.com/sagikazarmark/locafero v0.12.0 // indirect | |
| @@ -77,9 +71,7 @@ require ( | |||
| 77 | 71 | golang.org/x/sync v0.20.0 // indirect | |
| 78 | 72 | golang.org/x/text v0.35.0 // indirect | |
| 79 | 73 | gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect | |
| 80 | - | modernc.org/libc v1.70.0 // indirect | |
| 81 | - | modernc.org/mathutil v1.7.1 // indirect | |
| 82 | - | modernc.org/memory v1.11.0 // indirect | |
| 74 | + | modernc.org/sqlite v1.47.0 // indirect | |
| 83 | 75 | ) | |
| 84 | 76 | ||
| 85 | 77 | replace github.com/ebitengine/purego => github.com/bnema/purego v0.0.0-20260323095903-91aa177a2704 | |
| @@ -4,7 +4,7 @@ go 1.26.1 | |||||
| 4 | 4 | ||||
| 5 | require ( | 5 | require ( | ||
| 6 | github.com/bnema/purego-cef v0.0.0-00010101000000-000000000000 | 6 | github.com/bnema/purego-cef v0.0.0-00010101000000-000000000000 | ||
| 7 | - | github.com/bnema/purego-ffmpeg v0.1.0 | 7 | + | github.com/bnema/purego-ffmpeg v0.3.0 |
| 8 | github.com/bnema/purego-sqlite v0.1.1 | 8 | github.com/bnema/purego-sqlite v0.1.1 | ||
| 9 | github.com/bnema/puregotk v0.2.2 | 9 | github.com/bnema/puregotk v0.2.2 | ||
| 10 | github.com/bnema/puregotk-webkit v0.0.16 | 10 | github.com/bnema/puregotk-webkit v0.0.16 | ||
| @@ -24,11 +24,8 @@ require ( | |||||
| 24 | golang.org/x/image v0.38.0 | 24 | golang.org/x/image v0.38.0 | ||
| 25 | golang.org/x/sys v0.42.0 | 25 | golang.org/x/sys v0.42.0 | ||
| 26 | gopkg.in/yaml.v3 v3.0.1 | 26 | gopkg.in/yaml.v3 v3.0.1 | ||
| 27 | - | modernc.org/sqlite v1.47.0 | |||
| 28 | ) | 27 | ) | ||
| 29 | 28 | ||||
| 30 | - | replace github.com/ebitengine/purego => github.com/bnema/purego v0.0.0-20260323095903-91aa177a2704 | |||
| 31 | - | ||||
| 32 | replace github.com/bnema/purego-cef => ../purego-cef | 29 | replace github.com/bnema/purego-cef => ../purego-cef | ||
| 33 | 30 | ||||
| 34 | replace github.com/bnema/purego-ffmpeg => ../purego-ffmpeg | 31 | replace github.com/bnema/purego-ffmpeg => ../purego-ffmpeg | ||
| @@ -45,7 +42,6 @@ require ( | |||||
| 45 | github.com/clipperhouse/uax29/v2 v2.5.0 // indirect | 42 | github.com/clipperhouse/uax29/v2 v2.5.0 // indirect | ||
| 46 | github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect | 43 | github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect | ||
| 47 | github.com/davecgh/go-spew v1.1.1 // indirect | 44 | github.com/davecgh/go-spew v1.1.1 // indirect | ||
| 48 | - | github.com/dustin/go-humanize v1.0.1 // indirect | |||
| 49 | github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect | 45 | github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect | ||
| 50 | github.com/go-viper/mapstructure/v2 v2.5.0 // indirect | 46 | github.com/go-viper/mapstructure/v2 v2.5.0 // indirect | ||
| 51 | github.com/inconshreveable/mousetrap v1.1.0 // indirect | 47 | github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||
| @@ -58,9 +54,7 @@ require ( | |||||
| 58 | github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect | 54 | github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect | ||
| 59 | github.com/muesli/cancelreader v0.2.2 // indirect | 55 | github.com/muesli/cancelreader v0.2.2 // indirect | ||
| 60 | github.com/muesli/termenv v0.16.0 // indirect | 56 | github.com/muesli/termenv v0.16.0 // indirect | ||
| 61 | - | github.com/ncruces/go-strftime v1.0.0 // indirect | |||
| 62 | github.com/pmezard/go-difflib v1.0.0 // indirect | 57 | github.com/pmezard/go-difflib v1.0.0 // indirect | ||
| 63 | - | github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect | |||
| 64 | github.com/rivo/uniseg v0.4.7 // indirect | 58 | github.com/rivo/uniseg v0.4.7 // indirect | ||
| 65 | github.com/russross/blackfriday/v2 v2.1.0 // indirect | 59 | github.com/russross/blackfriday/v2 v2.1.0 // indirect | ||
| 66 | github.com/sagikazarmark/locafero v0.12.0 // indirect | 60 | github.com/sagikazarmark/locafero v0.12.0 // indirect | ||
| @@ -77,9 +71,7 @@ require ( | |||||
| 77 | golang.org/x/sync v0.20.0 // indirect | 71 | golang.org/x/sync v0.20.0 // indirect | ||
| 78 | golang.org/x/text v0.35.0 // indirect | 72 | golang.org/x/text v0.35.0 // indirect | ||
| 79 | gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect | 73 | gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect | ||
| 80 | - | modernc.org/libc v1.70.0 // indirect | 74 | + | modernc.org/sqlite v1.47.0 // indirect |
| 81 | - | modernc.org/mathutil v1.7.1 // indirect | |||
| 82 | - | modernc.org/memory v1.11.0 // indirect | |||
| 83 | ) | 75 | ) | ||
| 84 | 76 | ||||
| 85 | replace github.com/ebitengine/purego => github.com/bnema/purego v0.0.0-20260323095903-91aa177a2704 | 77 | replace github.com/ebitengine/purego => github.com/bnema/purego v0.0.0-20260323095903-91aa177a2704 | ||
M go.sum +10 -32 generated file: collapsed
M internal/infrastructure/transcoder/audio.go +4 -4
| @@ -74,7 +74,7 @@ func newAudioTranscoder(inCodecPar, outFmtCtx unsafe.Pointer, inStreamIdx int) ( | |||
| 74 | 74 | } | |
| 75 | 75 | ||
| 76 | 76 | // Opus always works with float planar samples. | |
| 77 | - | ffmpeg.CodecCtxSetSampleFmt(encCtx, int32(ffmpeg.SampleFormatSampleFmtFltp)) | |
| 77 | + | ffmpeg.CodecCtxSetSampleFmt(encCtx, int32(ffmpeg.SampleFmtFltp)) | |
| 78 | 78 | ffmpeg.CodecCtxSetSampleRate(encCtx, opusSampleRate) | |
| 79 | 79 | codecCtxSetBitRate(encCtx, opusBitrate) | |
| 80 | 80 | ||
| @@ -116,7 +116,7 @@ func newAudioTranscoder(inCodecPar, outFmtCtx unsafe.Pointer, inStreamIdx int) ( | |||
| 116 | 116 | ||
| 117 | 117 | inSampleRate := ffmpeg.CodecCtxSampleRate(decCtx) | |
| 118 | 118 | inSampleFmt := ffmpeg.CodecCtxSampleFmt(decCtx) | |
| 119 | - | needResample := inSampleRate != opusSampleRate || inSampleFmt != int32(ffmpeg.SampleFormatSampleFmtFltp) | |
| 119 | + | needResample := inSampleRate != opusSampleRate || inSampleFmt != int32(ffmpeg.SampleFmtFltp) | |
| 120 | 120 | ||
| 121 | 121 | if needResample { | |
| 122 | 122 | swr = ffmpeg.SwrAlloc() | |
| @@ -130,7 +130,7 @@ func newAudioTranscoder(inCodecPar, outFmtCtx unsafe.Pointer, inStreamIdx int) ( | |||
| 130 | 130 | ffmpeg.AVOptSetInt(swr, "in_sample_rate", int64(inSampleRate), 0) | |
| 131 | 131 | ffmpeg.AVOptSetInt(swr, "out_sample_rate", int64(opusSampleRate), 0) | |
| 132 | 132 | ffmpeg.AVOptSet(swr, "in_sample_fmt", ffmpeg.GetSampleFmtName(inSampleFmt), 0) | |
| 133 | - | ffmpeg.AVOptSet(swr, "out_sample_fmt", ffmpeg.GetSampleFmtName(int32(ffmpeg.SampleFormatSampleFmtFltp)), 0) | |
| 133 | + | ffmpeg.AVOptSet(swr, "out_sample_fmt", ffmpeg.GetSampleFmtName(int32(ffmpeg.SampleFmtFltp)), 0) | |
| 134 | 134 | ||
| 135 | 135 | // Modern FFmpeg (8.x) requires explicit channel layout configuration | |
| 136 | 136 | // on the SwrContext. Without it, swr_init may succeed but the resampler | |
| @@ -156,7 +156,7 @@ func newAudioTranscoder(inCodecPar, outFmtCtx unsafe.Pointer, inStreamIdx int) ( | |||
| 156 | 156 | return nil, errors.New("failed to allocate resampled frame") | |
| 157 | 157 | } | |
| 158 | 158 | ||
| 159 | - | frameSetFormat(resampledFrame, int32(ffmpeg.SampleFormatSampleFmtFltp)) | |
| 159 | + | frameSetFormat(resampledFrame, int32(ffmpeg.SampleFmtFltp)) | |
| 160 | 160 | frameSetSampleRate(resampledFrame, opusSampleRate) | |
| 161 | 161 | frameSetNbSamples(resampledFrame, opusFrameSize) | |
| 162 | 162 | // Copy channel layout from decoder to the resampled frame. | |
| @@ -74,7 +74,7 @@ func newAudioTranscoder(inCodecPar, outFmtCtx unsafe.Pointer, inStreamIdx int) ( | |||||
| 74 | } | 74 | } | ||
| 75 | 75 | ||||
| 76 | // Opus always works with float planar samples. | 76 | // Opus always works with float planar samples. | ||
| 77 | - | ffmpeg.CodecCtxSetSampleFmt(encCtx, int32(ffmpeg.SampleFormatSampleFmtFltp)) | 77 | + | ffmpeg.CodecCtxSetSampleFmt(encCtx, int32(ffmpeg.SampleFmtFltp)) |
| 78 | ffmpeg.CodecCtxSetSampleRate(encCtx, opusSampleRate) | 78 | ffmpeg.CodecCtxSetSampleRate(encCtx, opusSampleRate) | ||
| 79 | codecCtxSetBitRate(encCtx, opusBitrate) | 79 | codecCtxSetBitRate(encCtx, opusBitrate) | ||
| 80 | 80 | ||||
| @@ -116,7 +116,7 @@ func newAudioTranscoder(inCodecPar, outFmtCtx unsafe.Pointer, inStreamIdx int) ( | |||||
| 116 | 116 | ||||
| 117 | inSampleRate := ffmpeg.CodecCtxSampleRate(decCtx) | 117 | inSampleRate := ffmpeg.CodecCtxSampleRate(decCtx) | ||
| 118 | inSampleFmt := ffmpeg.CodecCtxSampleFmt(decCtx) | 118 | inSampleFmt := ffmpeg.CodecCtxSampleFmt(decCtx) | ||
| 119 | - | needResample := inSampleRate != opusSampleRate || inSampleFmt != int32(ffmpeg.SampleFormatSampleFmtFltp) | 119 | + | needResample := inSampleRate != opusSampleRate || inSampleFmt != int32(ffmpeg.SampleFmtFltp) |
| 120 | 120 | ||||
| 121 | if needResample { | 121 | if needResample { | ||
| 122 | swr = ffmpeg.SwrAlloc() | 122 | swr = ffmpeg.SwrAlloc() | ||
| @@ -130,7 +130,7 @@ func newAudioTranscoder(inCodecPar, outFmtCtx unsafe.Pointer, inStreamIdx int) ( | |||||
| 130 | ffmpeg.AVOptSetInt(swr, "in_sample_rate", int64(inSampleRate), 0) | 130 | ffmpeg.AVOptSetInt(swr, "in_sample_rate", int64(inSampleRate), 0) | ||
| 131 | ffmpeg.AVOptSetInt(swr, "out_sample_rate", int64(opusSampleRate), 0) | 131 | ffmpeg.AVOptSetInt(swr, "out_sample_rate", int64(opusSampleRate), 0) | ||
| 132 | ffmpeg.AVOptSet(swr, "in_sample_fmt", ffmpeg.GetSampleFmtName(inSampleFmt), 0) | 132 | ffmpeg.AVOptSet(swr, "in_sample_fmt", ffmpeg.GetSampleFmtName(inSampleFmt), 0) | ||
| 133 | - | ffmpeg.AVOptSet(swr, "out_sample_fmt", ffmpeg.GetSampleFmtName(int32(ffmpeg.SampleFormatSampleFmtFltp)), 0) | 133 | + | ffmpeg.AVOptSet(swr, "out_sample_fmt", ffmpeg.GetSampleFmtName(int32(ffmpeg.SampleFmtFltp)), 0) |
| 134 | 134 | ||||
| 135 | // Modern FFmpeg (8.x) requires explicit channel layout configuration | 135 | // Modern FFmpeg (8.x) requires explicit channel layout configuration | ||
| 136 | // on the SwrContext. Without it, swr_init may succeed but the resampler | 136 | // on the SwrContext. Without it, swr_init may succeed but the resampler | ||
| @@ -156,7 +156,7 @@ func newAudioTranscoder(inCodecPar, outFmtCtx unsafe.Pointer, inStreamIdx int) ( | |||||
| 156 | return nil, errors.New("failed to allocate resampled frame") | 156 | return nil, errors.New("failed to allocate resampled frame") | ||
| 157 | } | 157 | } | ||
| 158 | 158 | ||||
| 159 | - | frameSetFormat(resampledFrame, int32(ffmpeg.SampleFormatSampleFmtFltp)) | 159 | + | frameSetFormat(resampledFrame, int32(ffmpeg.SampleFmtFltp)) |
| 160 | frameSetSampleRate(resampledFrame, opusSampleRate) | 160 | frameSetSampleRate(resampledFrame, opusSampleRate) | ||
| 161 | frameSetNbSamples(resampledFrame, opusFrameSize) | 161 | frameSetNbSamples(resampledFrame, opusFrameSize) | ||
| 162 | // Copy channel layout from decoder to the resampled frame. | 162 | // Copy channel layout from decoder to the resampled frame. | ||
M internal/infrastructure/transcoder/hwprobe.go +2 -2
| @@ -32,14 +32,14 @@ type hwProfile struct { | |||
| 32 | 32 | ||
| 33 | 33 | var vaAPIProfile = hwProfile{ | |
| 34 | 34 | api: "vaapi", | |
| 35 | - | deviceType: ffmpeg.AV_HWDEVICE_TYPE_VAAPI, | |
| 35 | + | deviceType: int32(ffmpeg.HwdeviceTypeVaapi), | |
| 36 | 36 | encoders: []string{"av1_vaapi", "vp9_vaapi", "h264_vaapi"}, | |
| 37 | 37 | decoders: []string{"h264_vaapi", "hevc_vaapi"}, | |
| 38 | 38 | } | |
| 39 | 39 | ||
| 40 | 40 | var nvencProfile = hwProfile{ | |
| 41 | 41 | api: "nvenc", | |
| 42 | - | deviceType: ffmpeg.AV_HWDEVICE_TYPE_CUDA, | |
| 42 | + | deviceType: int32(ffmpeg.HwdeviceTypeCuda), | |
| 43 | 43 | // hevc_nvenc and h264_nvenc are probed for logging/diagnostic purposes | |
| 44 | 44 | // but filtered as non-usable by isUsableEncoder (only open codecs like | |
| 45 | 45 | // AV1 and VP9 are usable in CEF's minimal build). | |
| @@ -32,14 +32,14 @@ type hwProfile struct { | |||||
| 32 | 32 | ||||
| 33 | var vaAPIProfile = hwProfile{ | 33 | var vaAPIProfile = hwProfile{ | ||
| 34 | api: "vaapi", | 34 | api: "vaapi", | ||
| 35 | - | deviceType: ffmpeg.AV_HWDEVICE_TYPE_VAAPI, | 35 | + | deviceType: int32(ffmpeg.HwdeviceTypeVaapi), |
| 36 | encoders: []string{"av1_vaapi", "vp9_vaapi", "h264_vaapi"}, | 36 | encoders: []string{"av1_vaapi", "vp9_vaapi", "h264_vaapi"}, | ||
| 37 | decoders: []string{"h264_vaapi", "hevc_vaapi"}, | 37 | decoders: []string{"h264_vaapi", "hevc_vaapi"}, | ||
| 38 | } | 38 | } | ||
| 39 | 39 | ||||
| 40 | var nvencProfile = hwProfile{ | 40 | var nvencProfile = hwProfile{ | ||
| 41 | api: "nvenc", | 41 | api: "nvenc", | ||
| 42 | - | deviceType: ffmpeg.AV_HWDEVICE_TYPE_CUDA, | 42 | + | deviceType: int32(ffmpeg.HwdeviceTypeCuda), |
| 43 | // hevc_nvenc and h264_nvenc are probed for logging/diagnostic purposes | 43 | // hevc_nvenc and h264_nvenc are probed for logging/diagnostic purposes | ||
| 44 | // but filtered as non-usable by isUsableEncoder (only open codecs like | 44 | // but filtered as non-usable by isUsableEncoder (only open codecs like | ||
| 45 | // AV1 and VP9 are usable in CEF's minimal build). | 45 | // AV1 and VP9 are usable in CEF's minimal build). | ||
M internal/infrastructure/transcoder/pipeline.go +10 -10
| @@ -591,9 +591,9 @@ func (p *pipeline) openVideoEncoder(decCtx unsafe.Pointer) (hwDeviceCtx unsafe.P | |||
| 591 | 591 | var deviceType int32 | |
| 592 | 592 | switch p.hwCaps.API { | |
| 593 | 593 | case "vaapi": | |
| 594 | - | deviceType = ffmpeg.AV_HWDEVICE_TYPE_VAAPI | |
| 594 | + | deviceType = int32(ffmpeg.HwdeviceTypeVaapi) | |
| 595 | 595 | case "nvenc": | |
| 596 | - | deviceType = ffmpeg.AV_HWDEVICE_TYPE_CUDA | |
| 596 | + | deviceType = int32(ffmpeg.HwdeviceTypeCuda) | |
| 597 | 597 | default: | |
| 598 | 598 | return nil, nil, fmt.Errorf("unknown HW API: %s", p.hwCaps.API) | |
| 599 | 599 | } | |
| @@ -660,9 +660,9 @@ func (p *pipeline) tryOpenVideoEncoder(decCtx, hwDeviceCtx unsafe.Pointer, encod | |||
| 660 | 660 | ffmpeg.CodecCtxSetTimeBase(encCtx, ffmpeg.AVRational{Num: framerate.Den, Den: framerate.Num}) | |
| 661 | 661 | ||
| 662 | 662 | if p.hwCaps.API == "vaapi" { | |
| 663 | - | ffmpeg.CodecCtxSetPixFmt(encCtx, int32(ffmpeg.PixelFormatPixFmtVaapi)) | |
| 663 | + | ffmpeg.CodecCtxSetPixFmt(encCtx, int32(ffmpeg.PixFmtVaapi)) | |
| 664 | 664 | } else { | |
| 665 | - | ffmpeg.CodecCtxSetPixFmt(encCtx, int32(ffmpeg.PixelFormatPixFmtNv12)) | |
| 665 | + | ffmpeg.CodecCtxSetPixFmt(encCtx, int32(ffmpeg.PixFmtNv12)) | |
| 666 | 666 | } | |
| 667 | 667 | ||
| 668 | 668 | gopSize := int32(framerate.Num / framerate.Den * 2) | |
| @@ -694,8 +694,8 @@ func (p *pipeline) tryOpenVideoEncoder(decCtx, hwDeviceCtx unsafe.Pointer, encod | |||
| 694 | 694 | } | |
| 695 | 695 | ||
| 696 | 696 | ffmpeg.HWFramesCtxSetInitialPoolSize(hwFramesData, 20) | |
| 697 | - | ffmpeg.HWFramesCtxSetFormat(hwFramesData, int32(ffmpeg.PixelFormatPixFmtVaapi)) | |
| 698 | - | ffmpeg.HWFramesCtxSetSWFormat(hwFramesData, int32(ffmpeg.PixelFormatPixFmtNv12)) | |
| 697 | + | ffmpeg.HWFramesCtxSetFormat(hwFramesData, int32(ffmpeg.PixFmtVaapi)) | |
| 698 | + | ffmpeg.HWFramesCtxSetSWFormat(hwFramesData, int32(ffmpeg.PixFmtNv12)) | |
| 699 | 699 | ffmpeg.HWFramesCtxSetWidth(hwFramesData, width) | |
| 700 | 700 | ffmpeg.HWFramesCtxSetHeight(hwFramesData, height) | |
| 701 | 701 | ||
| @@ -759,7 +759,7 @@ func (p *pipeline) applyQualityPreset(encCtx unsafe.Pointer, encoderName string, | |||
| 759 | 759 | ||
| 760 | 760 | // transcodeVideoPacket decodes a video packet, encodes the resulting | |
| 761 | 761 | // frames, and writes them to the output. | |
| 762 | - | func (p *pipeline) transcodeVideoPacket(pkt, frame, encPkt, decCtx, encCtx, outFmtCtx unsafe.Pointer, inStreamWrap *ffmpeg.Stream, outVideoIdx int) error { | |
| 762 | + | func (p *pipeline) transcodeVideoPacket(pkt, frame, encPkt, decCtx, encCtx, outFmtCtx unsafe.Pointer, inStreamWrap ffmpeg.Stream, outVideoIdx int) error { | |
| 763 | 763 | ret := ffmpeg.CodecSendPacket(decCtx, pkt) | |
| 764 | 764 | if ret < 0 { | |
| 765 | 765 | return fmt.Errorf("video decode send packet: %d", ret) | |
| @@ -784,7 +784,7 @@ func (p *pipeline) transcodeVideoPacket(pkt, frame, encPkt, decCtx, encCtx, outF | |||
| 784 | 784 | ||
| 785 | 785 | // encodeAndWriteVideoFrame sends a decoded frame to the encoder and | |
| 786 | 786 | // writes any resulting packets to the output. | |
| 787 | - | func (p *pipeline) encodeAndWriteVideoFrame(frame, encPkt, encCtx, outFmtCtx unsafe.Pointer, inStreamWrap *ffmpeg.Stream, outVideoIdx int) error { | |
| 787 | + | func (p *pipeline) encodeAndWriteVideoFrame(frame, encPkt, encCtx, outFmtCtx unsafe.Pointer, inStreamWrap ffmpeg.Stream, outVideoIdx int) error { | |
| 788 | 788 | encFrame := frame | |
| 789 | 789 | var cleanup func() | |
| 790 | 790 | if p.hwCaps.API == "vaapi" { | |
| @@ -824,7 +824,7 @@ func (p *pipeline) encodeAndWriteVideoFrame(frame, encPkt, encCtx, outFmtCtx uns | |||
| 824 | 824 | } | |
| 825 | 825 | ||
| 826 | 826 | func (p *pipeline) uploadVideoFrameToVAAPI(frame, encCtx unsafe.Pointer) (unsafe.Pointer, func(), error) { | |
| 827 | - | if frameFormat(frame) == int32(ffmpeg.PixelFormatPixFmtVaapi) { | |
| 827 | + | if frameFormat(frame) == int32(ffmpeg.PixFmtVaapi) { | |
| 828 | 828 | return frame, func() {}, nil | |
| 829 | 829 | } | |
| 830 | 830 | ||
| @@ -844,7 +844,7 @@ func (p *pipeline) uploadVideoFrameToVAAPI(frame, encCtx unsafe.Pointer) (unsafe | |||
| 844 | 844 | } | |
| 845 | 845 | } | |
| 846 | 846 | ||
| 847 | - | frameSetFormat(hwFrame, int32(ffmpeg.PixelFormatPixFmtVaapi)) | |
| 847 | + | frameSetFormat(hwFrame, int32(ffmpeg.PixFmtVaapi)) | |
| 848 | 848 | frameSetWidth(hwFrame, frameWidth(frame)) | |
| 849 | 849 | frameSetHeight(hwFrame, frameHeight(frame)) | |
| 850 | 850 | frameSetPts(hwFrame, framePts(frame)) | |
| @@ -591,9 +591,9 @@ func (p *pipeline) openVideoEncoder(decCtx unsafe.Pointer) (hwDeviceCtx unsafe.P | |||||
| 591 | var deviceType int32 | 591 | var deviceType int32 | ||
| 592 | switch p.hwCaps.API { | 592 | switch p.hwCaps.API { | ||
| 593 | case "vaapi": | 593 | case "vaapi": | ||
| 594 | - | deviceType = ffmpeg.AV_HWDEVICE_TYPE_VAAPI | 594 | + | deviceType = int32(ffmpeg.HwdeviceTypeVaapi) |
| 595 | case "nvenc": | 595 | case "nvenc": | ||
| 596 | - | deviceType = ffmpeg.AV_HWDEVICE_TYPE_CUDA | 596 | + | deviceType = int32(ffmpeg.HwdeviceTypeCuda) |
| 597 | default: | 597 | default: | ||
| 598 | return nil, nil, fmt.Errorf("unknown HW API: %s", p.hwCaps.API) | 598 | return nil, nil, fmt.Errorf("unknown HW API: %s", p.hwCaps.API) | ||
| 599 | } | 599 | } | ||
| @@ -660,9 +660,9 @@ func (p *pipeline) tryOpenVideoEncoder(decCtx, hwDeviceCtx unsafe.Pointer, encod | |||||
| 660 | ffmpeg.CodecCtxSetTimeBase(encCtx, ffmpeg.AVRational{Num: framerate.Den, Den: framerate.Num}) | 660 | ffmpeg.CodecCtxSetTimeBase(encCtx, ffmpeg.AVRational{Num: framerate.Den, Den: framerate.Num}) | ||
| 661 | 661 | ||||
| 662 | if p.hwCaps.API == "vaapi" { | 662 | if p.hwCaps.API == "vaapi" { | ||
| 663 | - | ffmpeg.CodecCtxSetPixFmt(encCtx, int32(ffmpeg.PixelFormatPixFmtVaapi)) | 663 | + | ffmpeg.CodecCtxSetPixFmt(encCtx, int32(ffmpeg.PixFmtVaapi)) |
| 664 | } else { | 664 | } else { | ||
| 665 | - | ffmpeg.CodecCtxSetPixFmt(encCtx, int32(ffmpeg.PixelFormatPixFmtNv12)) | 665 | + | ffmpeg.CodecCtxSetPixFmt(encCtx, int32(ffmpeg.PixFmtNv12)) |
| 666 | } | 666 | } | ||
| 667 | 667 | ||||
| 668 | gopSize := int32(framerate.Num / framerate.Den * 2) | 668 | gopSize := int32(framerate.Num / framerate.Den * 2) | ||
| @@ -694,8 +694,8 @@ func (p *pipeline) tryOpenVideoEncoder(decCtx, hwDeviceCtx unsafe.Pointer, encod | |||||
| 694 | } | 694 | } | ||
| 695 | 695 | ||||
| 696 | ffmpeg.HWFramesCtxSetInitialPoolSize(hwFramesData, 20) | 696 | ffmpeg.HWFramesCtxSetInitialPoolSize(hwFramesData, 20) | ||
| 697 | - | ffmpeg.HWFramesCtxSetFormat(hwFramesData, int32(ffmpeg.PixelFormatPixFmtVaapi)) | 697 | + | ffmpeg.HWFramesCtxSetFormat(hwFramesData, int32(ffmpeg.PixFmtVaapi)) |
| 698 | - | ffmpeg.HWFramesCtxSetSWFormat(hwFramesData, int32(ffmpeg.PixelFormatPixFmtNv12)) | 698 | + | ffmpeg.HWFramesCtxSetSWFormat(hwFramesData, int32(ffmpeg.PixFmtNv12)) |
| 699 | ffmpeg.HWFramesCtxSetWidth(hwFramesData, width) | 699 | ffmpeg.HWFramesCtxSetWidth(hwFramesData, width) | ||
| 700 | ffmpeg.HWFramesCtxSetHeight(hwFramesData, height) | 700 | ffmpeg.HWFramesCtxSetHeight(hwFramesData, height) | ||
| 701 | 701 | ||||
| @@ -759,7 +759,7 @@ func (p *pipeline) applyQualityPreset(encCtx unsafe.Pointer, encoderName string, | |||||
| 759 | 759 | ||||
| 760 | // transcodeVideoPacket decodes a video packet, encodes the resulting | 760 | // transcodeVideoPacket decodes a video packet, encodes the resulting | ||
| 761 | // frames, and writes them to the output. | 761 | // frames, and writes them to the output. | ||
| 762 | - | func (p *pipeline) transcodeVideoPacket(pkt, frame, encPkt, decCtx, encCtx, outFmtCtx unsafe.Pointer, inStreamWrap *ffmpeg.Stream, outVideoIdx int) error { | 762 | + | func (p *pipeline) transcodeVideoPacket(pkt, frame, encPkt, decCtx, encCtx, outFmtCtx unsafe.Pointer, inStreamWrap ffmpeg.Stream, outVideoIdx int) error { |
| 763 | ret := ffmpeg.CodecSendPacket(decCtx, pkt) | 763 | ret := ffmpeg.CodecSendPacket(decCtx, pkt) | ||
| 764 | if ret < 0 { | 764 | if ret < 0 { | ||
| 765 | return fmt.Errorf("video decode send packet: %d", ret) | 765 | return fmt.Errorf("video decode send packet: %d", ret) | ||
| @@ -784,7 +784,7 @@ func (p *pipeline) transcodeVideoPacket(pkt, frame, encPkt, decCtx, encCtx, outF | |||||
| 784 | 784 | ||||
| 785 | // encodeAndWriteVideoFrame sends a decoded frame to the encoder and | 785 | // encodeAndWriteVideoFrame sends a decoded frame to the encoder and | ||
| 786 | // writes any resulting packets to the output. | 786 | // writes any resulting packets to the output. | ||
| 787 | - | func (p *pipeline) encodeAndWriteVideoFrame(frame, encPkt, encCtx, outFmtCtx unsafe.Pointer, inStreamWrap *ffmpeg.Stream, outVideoIdx int) error { | 787 | + | func (p *pipeline) encodeAndWriteVideoFrame(frame, encPkt, encCtx, outFmtCtx unsafe.Pointer, inStreamWrap ffmpeg.Stream, outVideoIdx int) error { |
| 788 | encFrame := frame | 788 | encFrame := frame | ||
| 789 | var cleanup func() | 789 | var cleanup func() | ||
| 790 | if p.hwCaps.API == "vaapi" { | 790 | if p.hwCaps.API == "vaapi" { | ||
| @@ -824,7 +824,7 @@ func (p *pipeline) encodeAndWriteVideoFrame(frame, encPkt, encCtx, outFmtCtx uns | |||||
| 824 | } | 824 | } | ||
| 825 | 825 | ||||
| 826 | func (p *pipeline) uploadVideoFrameToVAAPI(frame, encCtx unsafe.Pointer) (unsafe.Pointer, func(), error) { | 826 | func (p *pipeline) uploadVideoFrameToVAAPI(frame, encCtx unsafe.Pointer) (unsafe.Pointer, func(), error) { | ||
| 827 | - | if frameFormat(frame) == int32(ffmpeg.PixelFormatPixFmtVaapi) { | 827 | + | if frameFormat(frame) == int32(ffmpeg.PixFmtVaapi) { |
| 828 | return frame, func() {}, nil | 828 | return frame, func() {}, nil | ||
| 829 | } | 829 | } | ||
| 830 | 830 | ||||
| @@ -844,7 +844,7 @@ func (p *pipeline) uploadVideoFrameToVAAPI(frame, encCtx unsafe.Pointer) (unsafe | |||||
| 844 | } | 844 | } | ||
| 845 | } | 845 | } | ||
| 846 | 846 | ||||
| 847 | - | frameSetFormat(hwFrame, int32(ffmpeg.PixelFormatPixFmtVaapi)) | 847 | + | frameSetFormat(hwFrame, int32(ffmpeg.PixFmtVaapi)) |
| 848 | frameSetWidth(hwFrame, frameWidth(frame)) | 848 | frameSetWidth(hwFrame, frameWidth(frame)) | ||
| 849 | frameSetHeight(hwFrame, frameHeight(frame)) | 849 | frameSetHeight(hwFrame, frameHeight(frame)) | ||
| 850 | frameSetPts(hwFrame, framePts(frame)) | 850 | frameSetPts(hwFrame, framePts(frame)) | ||