Skip to content

Migration API FFmpeg 6.0+ (codecpar/AVBSFContext) : tested for compatibility FFmpeg 8.0/8.1 (PR v2)#2

Open
M2G wants to merge 2 commits into
cwinging:masterfrom
M2G:master
Open

Migration API FFmpeg 6.0+ (codecpar/AVBSFContext) : tested for compatibility FFmpeg 8.0/8.1 (PR v2)#2
M2G wants to merge 2 commits into
cwinging:masterfrom
M2G:master

Conversation

@M2G

@M2G M2G commented Jul 2, 2026

Copy link
Copy Markdown

Background

The segment package was still using the old FFmpeg 2.x API (AVStream->codec,
AVBitStreamFilterContext, av_register_all(), av_free_packet()...), which was deprecated and then
removed in recent versions of FFmpeg.
This fork migrates the code to the modern API, which has been stable since FFmpeg 6.0 and has been verified as compatible up to FFmpeg 8.

Changes

AVStream->codec to AVStream->codecpar: Copy parameters using
avcodec_parameters_copy() instead of manually setting each field (codec_type, bit_rate,
extradata, channel_layout, etc.)

  • AVBitStreamFilterContext to AVBSFContext: Replaces
    av_bitstream_filter_init()/av_bitstream_filter_filter() with
    av_bsf_alloc()/av_bsf_init()/av_bsf_send_packet()/av_bsf_receive_packet()
  • AVPacket on the stack to av_packet_alloc()/av_packet_free(): Replaces the old
    av_free_packet() (removed since FFmpeg 4.0)
  • avformat_alloc_context() + av_guess_format() to avformat_alloc_output_context2()
  • Removal of av_register_all() (no-op since FFmpeg 4.0)
  • Removal of CODEC_FLAG_GLOBAL_HEADER and the CODEC_ID_MP3/CODEC_ID_AC3 switch
    (automatically handled by avcodec_parameters_copy)
  • Build system: Hard-coded #cgo LDFLAGS/CFLAGS (path /root/ffmpeg_build) replaced
    with #cgo pkg-config: libavformat libavcodec libavutil, for a portable build without
    path changes across environments
  • Cleaned up a dead variable (first_frame_sec, assigned but never read)

Tests performed

  • OK : Clean compilation (gcc -Wall -Wextra, 0 warnings) against FFmpeg 8.0 compiled from
    source (libavcodec 62 / libavformat 62)
  • OK : Successful compilation on macOS (Apple Silicon) via Homebrew, FFmpeg 8.1.2, pkg-config
  • OK : End-to-end HLS segmentation working: 12-second H.264/AAC MP4 input split into 3
    4-second .ts segments + valid .m3u8 playlist; each segment validated with ffprobe

Compatibility

Linux and macOS (Apple Silicon), FFmpeg 6.0 through 8.1, without platform-specific code
thanks to pkg-config.

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

Successfully merging this pull request may close these issues.

1 participant