Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 47 additions & 47 deletions av.zig
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ pub extern fn avio_alloc_context(
buffer_size: c_int,
write_flag: IOContext.WriteFlag,
@"opaque": ?*anyopaque,
read_packet: ?*const fn (?*anyopaque, [*:0]u8, c_int) callconv(.C) c_int,
write_packet: ?*const fn (?*anyopaque, [*:0]u8, c_int) callconv(.C) c_int,
seek: ?*const fn (?*anyopaque, i64, SEEK) callconv(.C) i64,
read_packet: ?*const fn (?*anyopaque, [*:0]u8, c_int) callconv(.c) c_int,
write_packet: ?*const fn (?*anyopaque, [*:0]u8, c_int) callconv(.c) c_int,
seek: ?*const fn (?*anyopaque, i64, SEEK) callconv(.c) i64,
) [*c]IOContext;
/// Prefer `IOContext.free`.
pub extern fn avio_context_free(s: *?*IOContext) void;
Expand Down Expand Up @@ -215,7 +215,7 @@ pub const tx_fn = fn (
output_array: ?*anyopaque,
input_array: ?*anyopaque,
stride_in_bytes: isize,
) callconv(.C) void;
) callconv(.c) void;

pub fn malloc(size: usize) error{OutOfMemory}![]u8 {
const ptr = av_malloc(size) orelse return error.OutOfMemory;
Expand Down Expand Up @@ -800,7 +800,7 @@ pub const FormatContext = extern struct {
/// additional internal format contexts. Thus the AVFormatContext pointer
/// passed to this callback may be different from the one facing the caller.
/// It will, however, have the same 'opaque' field.
io_open: ?*const fn (*FormatContext, **IOContext, [*]const u8, c_int, *Dictionary.Mutable) callconv(.C) c_int,
io_open: ?*const fn (*FormatContext, **IOContext, [*]const u8, c_int, *Dictionary.Mutable) callconv(.c) c_int,
/// A callback for closing the streams opened with AVFormatContext.io_open().
///
/// Using this is preferred over io_close, because this can return an error.
Expand All @@ -810,7 +810,7 @@ pub const FormatContext = extern struct {
/// @param s the format context
/// @param pb IO context to be closed and freed
/// @return 0 on success, a negative AVERROR code on failure
io_close2: ?*const fn (*FormatContext, *IOContext) callconv(.C) c_int,
io_close2: ?*const fn (*FormatContext, *IOContext) callconv(.c) c_int,

/// `free` can be used to free the context and everything
/// allocated by the framework within it.
Expand Down Expand Up @@ -978,16 +978,16 @@ pub const FormatContext = extern struct {

pub const Class = extern struct {
class_name: [*c]const u8,
item_name: ?*const fn (?*anyopaque) callconv(.C) [*c]const u8,
item_name: ?*const fn (?*anyopaque) callconv(.c) [*c]const u8,
option: ?*const Option_6,
version: c_int,
log_level_offset_offset: c_int,
parent_log_context_offset: c_int,
category: ClassCategory,
get_category: ?*const fn (?*anyopaque) callconv(.C) ClassCategory,
query_ranges: ?*const fn ([*c]?*OptionRanges, ?*anyopaque, [*c]const u8, c_int) callconv(.C) c_int,
child_next: ?*const fn (?*anyopaque, ?*anyopaque) callconv(.C) ?*anyopaque,
child_class_iterate: ?*const fn ([*c]?*anyopaque) callconv(.C) [*c]const Class,
get_category: ?*const fn (?*anyopaque) callconv(.c) ClassCategory,
query_ranges: ?*const fn ([*c]?*OptionRanges, ?*anyopaque, [*c]const u8, c_int) callconv(.c) c_int,
child_next: ?*const fn (?*anyopaque, ?*anyopaque) callconv(.c) ?*anyopaque,
child_class_iterate: ?*const fn ([*c]?*anyopaque) callconv(.c) [*c]const Class,
};

pub const InputFormat = extern struct {
Expand All @@ -1001,16 +1001,16 @@ pub const InputFormat = extern struct {
raw_codec_id: c_int,
priv_data_size: c_int,
flags_internal: c_int,
read_probe: ?*const fn ([*c]const ProbeData) callconv(.C) c_int,
read_header: ?*const fn ([*c]FormatContext) callconv(.C) c_int,
read_packet: ?*const fn ([*c]FormatContext, [*c]Packet) callconv(.C) c_int,
read_close: ?*const fn ([*c]FormatContext) callconv(.C) c_int,
read_seek: ?*const fn ([*c]FormatContext, c_int, i64, c_int) callconv(.C) c_int,
read_timestamp: ?*const fn ([*c]FormatContext, c_int, [*c]i64, i64) callconv(.C) i64,
read_play: ?*const fn ([*c]FormatContext) callconv(.C) c_int,
read_pause: ?*const fn ([*c]FormatContext) callconv(.C) c_int,
read_seek2: ?*const fn ([*c]FormatContext, c_int, i64, i64, i64, c_int) callconv(.C) c_int,
get_device_list: ?*const fn ([*c]FormatContext, ?*DeviceInfoList) callconv(.C) c_int,
read_probe: ?*const fn ([*c]const ProbeData) callconv(.c) c_int,
read_header: ?*const fn ([*c]FormatContext) callconv(.c) c_int,
read_packet: ?*const fn ([*c]FormatContext, [*c]Packet) callconv(.c) c_int,
read_close: ?*const fn ([*c]FormatContext) callconv(.c) c_int,
read_seek: ?*const fn ([*c]FormatContext, c_int, i64, c_int) callconv(.c) c_int,
read_timestamp: ?*const fn ([*c]FormatContext, c_int, [*c]i64, i64) callconv(.c) i64,
read_play: ?*const fn ([*c]FormatContext) callconv(.c) c_int,
read_pause: ?*const fn ([*c]FormatContext) callconv(.c) c_int,
read_seek2: ?*const fn ([*c]FormatContext, c_int, i64, i64, i64, c_int) callconv(.c) c_int,
get_device_list: ?*const fn ([*c]FormatContext, ?*DeviceInfoList) callconv(.c) c_int,
};

pub const OutputFormat = extern struct {
Expand All @@ -1033,9 +1033,9 @@ pub const IOContext = extern struct {
buf_ptr: [*]u8,
buf_end: [*]u8,
@"opaque": ?*anyopaque,
read_packet: ?*const fn (?*anyopaque, [*c]u8, c_int) callconv(.C) c_int,
write_packet: ?*const fn (?*anyopaque, [*c]const u8, c_int) callconv(.C) c_int,
seek: ?*const fn (?*anyopaque, i64, SEEK) callconv(.C) i64,
read_packet: ?*const fn (?*anyopaque, [*c]u8, c_int) callconv(.c) c_int,
write_packet: ?*const fn (?*anyopaque, [*c]const u8, c_int) callconv(.c) c_int,
seek: ?*const fn (?*anyopaque, i64, SEEK) callconv(.c) i64,
pos: i64,
eof_reached: c_int,
@"error": c_int,
Expand All @@ -1044,14 +1044,14 @@ pub const IOContext = extern struct {
min_packet_size: c_int,
checksum: c_ulong,
checksum_ptr: [*c]u8,
update_checksum: ?*const fn (c_ulong, [*c]const u8, c_uint) callconv(.C) c_ulong,
read_pause: ?*const fn (?*anyopaque, c_int) callconv(.C) c_int,
read_seek: ?*const fn (?*anyopaque, c_int, i64, c_int) callconv(.C) i64,
update_checksum: ?*const fn (c_ulong, [*c]const u8, c_uint) callconv(.c) c_ulong,
read_pause: ?*const fn (?*anyopaque, c_int) callconv(.c) c_int,
read_seek: ?*const fn (?*anyopaque, c_int, i64, c_int) callconv(.c) i64,
seekable: c_int,
direct: c_int,
protocol_whitelist: [*c]const u8,
protocol_blacklist: [*c]const u8,
write_data_type: ?*const fn (?*anyopaque, [*c]const u8, c_int, IODataMarkerType, i64) callconv(.C) c_int,
write_data_type: ?*const fn (?*anyopaque, [*c]const u8, c_int, IODataMarkerType, i64) callconv(.c) c_int,
ignore_boundary_point: c_int,
buf_ptr_max: [*c]u8,
bytes_read: i64,
Expand Down Expand Up @@ -1082,13 +1082,13 @@ pub const IOContext = extern struct {
/// A function for refilling the buffer.
///
/// For stream protocols, must never return 0 but rather a proper AVERROR code.
read_packet: ?*const fn (?*anyopaque, [*:0]u8, c_int) callconv(.C) c_int,
read_packet: ?*const fn (?*anyopaque, [*:0]u8, c_int) callconv(.c) c_int,
/// A function for writing the buffer contents.
///
/// The function may not change the input buffers content.
write_packet: ?*const fn (?*anyopaque, [*:0]u8, c_int) callconv(.C) c_int,
write_packet: ?*const fn (?*anyopaque, [*:0]u8, c_int) callconv(.c) c_int,
/// A function for seeking to specified byte position.
seek: ?*const fn (?*anyopaque, i64, SEEK) callconv(.C) i64,
seek: ?*const fn (?*anyopaque, i64, SEEK) callconv(.c) i64,
) error{OutOfMemory}!*IOContext {
return avio_alloc_context(
buffer.ptr,
Expand Down Expand Up @@ -1302,7 +1302,7 @@ pub const Dictionary = opaque {
};

pub const IOInterruptCB = extern struct {
callback: ?*const fn (?*anyopaque) callconv(.C) c_int,
callback: ?*const fn (?*anyopaque) callconv(.c) c_int,
@"opaque": ?*anyopaque,
};

Expand All @@ -1312,7 +1312,7 @@ pub const DurationEstimationMethod = enum(c_uint) {
BITRATE = 2,
};

pub const av_format_control_message = ?*const fn ([*c]FormatContext, c_int, ?*anyopaque, usize) callconv(.C) c_int;
pub const av_format_control_message = ?*const fn ([*c]FormatContext, c_int, ?*anyopaque, usize) callconv(.c) c_int;

pub const Option_6 = opaque {};

Expand Down Expand Up @@ -2633,8 +2633,8 @@ pub const Codec = extern struct {
refs: c_int,
has_b_frames: c_int,
slice_flags: c_int,
draw_horiz_band: ?*const fn (s: *Context, src: *const Frame, offset: *[Frame.NUM_DATA_POINTERS]c_int, y: c_int, @"type": c_int, height: c_int) callconv(.C) void,
get_format: *const fn (s: *Context, fmt: *const PixelFormat) callconv(.C) PixelFormat,
draw_horiz_band: ?*const fn (s: *Context, src: *const Frame, offset: *[Frame.NUM_DATA_POINTERS]c_int, y: c_int, @"type": c_int, height: c_int) callconv(.c) void,
get_format: *const fn (s: *Context, fmt: *const PixelFormat) callconv(.c) PixelFormat,
max_b_frames: c_int,
b_quant_factor: f32,
b_quant_offset: f32,
Expand Down Expand Up @@ -2679,7 +2679,7 @@ pub const Codec = extern struct {
initial_padding: c_int,
trailing_padding: c_int,
seek_preroll: c_int,
get_buffer2: *const fn (s: *Context, frame: *Frame, flags: c_int) callconv(.C) c_int,
get_buffer2: *const fn (s: *Context, frame: *Frame, flags: c_int) callconv(.c) c_int,
bit_rate_tolerance: c_int,
global_quality: c_int,
compression_level: c_int,
Expand Down Expand Up @@ -2718,8 +2718,8 @@ pub const Codec = extern struct {
thread_count: c_int,
thread_type: c_int,
active_thread_type: c_int,
execute: *const fn (c: *Context, *const fn (c2: *Context, arg: [*]u8) callconv(.C) c_int, arg2: [*]u8, ret: ?[*]c_int, count: c_int, size: c_int) callconv(.C) c_int,
execute2: *const fn (c: *Context, *const fn (c2: *Context, arg: [*]u8, jobnr: c_int, threadnr: c_int) callconv(.C) c_int, arg2: [*]u8, ret: ?[*]c_int, count: c_int) callconv(.C) c_int,
execute: *const fn (c: *Context, *const fn (c2: *Context, arg: [*]u8) callconv(.c) c_int, arg2: [*]u8, ret: ?[*]c_int, count: c_int, size: c_int) callconv(.c) c_int,
execute2: *const fn (c: *Context, *const fn (c2: *Context, arg: [*]u8, jobnr: c_int, threadnr: c_int) callconv(.c) c_int, arg2: [*]u8, ret: ?[*]c_int, count: c_int) callconv(.c) c_int,
profile: c_int,
level: c_int,
properties: c_uint,
Expand All @@ -2744,7 +2744,7 @@ pub const Codec = extern struct {
apply_cropping: c_int,
discard_damaged_percentage: c_int,
max_samples: i64,
get_encode_buffer: *const fn (s: *Context, pkt: *Packet, flags: c_int) callconv(.C) c_int,
get_encode_buffer: *const fn (s: *Context, pkt: *Packet, flags: c_int) callconv(.c) c_int,
frame_num: i64,
side_data_prefer_packet: ?[*]c_int,
nb_side_data_prefer_packet: c_uint,
Expand Down Expand Up @@ -3394,8 +3394,8 @@ pub const BUFFERSINK_FLAG = packed struct(c_uint) {
_: u30 = 0,
};

pub const filter_execute_func = fn ([*c]FilterContext, ?*const filter_action_func, ?*anyopaque, [*c]c_int, c_int) callconv(.C) c_int;
pub const filter_action_func = fn ([*c]FilterContext, ?*anyopaque, c_int, c_int) callconv(.C) c_int;
pub const filter_execute_func = fn ([*c]FilterContext, ?*const filter_action_func, ?*anyopaque, [*c]c_int, c_int) callconv(.c) c_int;
pub const filter_action_func = fn ([*c]FilterContext, ?*anyopaque, c_int, c_int) callconv(.c) c_int;
pub const FilterLink = extern struct {
src: [*c]FilterContext,
srcpad: ?*FilterPad,
Expand Down Expand Up @@ -3437,20 +3437,20 @@ pub const Filter = extern struct {
nb_inputs: u8,
nb_outputs: u8,
formats_state: u8,
preinit: ?*const fn ([*c]FilterContext) callconv(.C) c_int,
init: ?*const fn ([*c]FilterContext) callconv(.C) c_int,
uninit: ?*const fn ([*c]FilterContext) callconv(.C) void,
preinit: ?*const fn ([*c]FilterContext) callconv(.c) c_int,
init: ?*const fn ([*c]FilterContext) callconv(.c) c_int,
uninit: ?*const fn ([*c]FilterContext) callconv(.c) void,
formats: extern union {
query_func: ?*const fn ([*c]FilterContext) callconv(.C) c_int,
query_func: ?*const fn ([*c]FilterContext) callconv(.c) c_int,
pixels_list: [*c]const PixelFormat,
samples_list: [*c]const SampleFormat,
pix_fmt: PixelFormat,
sample_fmt: SampleFormat,
},
priv_size: c_int,
flags_internal: c_int,
process_command: ?*const fn ([*c]FilterContext, [*c]const u8, [*c]const u8, [*c]u8, c_int, c_int) callconv(.C) c_int,
activate: ?*const fn ([*c]FilterContext) callconv(.C) c_int,
process_command: ?*const fn ([*c]FilterContext, [*c]const u8, [*c]const u8, [*c]u8, c_int, c_int) callconv(.c) c_int,
activate: ?*const fn ([*c]FilterContext) callconv(.c) c_int,

/// Get a filter definition matching the given name.
///
Expand Down
19 changes: 11 additions & 8 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
});

const lib = b.addStaticLibrary(.{
.name = "ffmpeg",
const lib = b.addLibrary(.{ .name = "ffmpeg", .root_module = b.createModule(.{
.target = target,
.optimize = optimize,
});
}) });
lib.linkLibrary(libz_dep.artifact("z"));
if (lazy_mbedtls_dep) |mbedtls_dep| lib.linkLibrary(mbedtls_dep.artifact("mbedtls"));
if (lazy_openssl_dep) |openssl_dep| lib.linkLibrary(openssl_dep.artifact("openssl"));
Expand Down Expand Up @@ -3173,8 +3172,10 @@ pub fn build(b: *std.Build) void {

const show_metadata_c = b.addExecutable(.{
.name = "show_metadata_c",
.target = target,
.optimize = optimize,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
}),
});
show_metadata_c.addCSourceFiles(.{
.files = &.{"doc/examples/show_metadata.c"},
Expand All @@ -3184,9 +3185,11 @@ pub fn build(b: *std.Build) void {

const show_metadata_zig = b.addExecutable(.{
.name = "show_metadata_zig",
.root_source_file = b.path("doc/examples/show_metadata.zig"),
.target = target,
.optimize = optimize,
.root_module = b.createModule(.{
.root_source_file = b.path("doc/examples/show_metadata.zig"),
.target = target,
.optimize = optimize,
}),
});
show_metadata_zig.root_module.addImport("av", bindings);
b.installArtifact(show_metadata_zig);
Expand Down
32 changes: 16 additions & 16 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,43 @@

.dependencies = .{
.libz = .{
.url = "https://github.com/allyourcodebase/zlib/archive/6c72830882690c1eb2567a537525c3f432c1da50.tar.gz",
.hash = "zlib-1.3.1-ZZQ7lVgMAACwO4nUUd8GLhsuQ5JQq_VAhlEiENJTUv6h",
.url = "https://github.com/allyourcodebase/zlib/archive/8a8161babd4b79ea47d5a5976337a96ac4a5666b.tar.gz",
.hash = "zlib-1.3.1-ZZQ7lbYMAAAuaZnFj2675ah508w1Oc-EuY1V1cWJka2C",
},
.mbedtls = .{
.url = "git+https://github.com/allyourcodebase/mbedtls#7d862fe61ff2eac37ee54e1e017fc287bed1cd7a",
.hash = "mbedtls-3.6.2-E4NURzYUAABWLBwHJWx_ppb_j2kDSoGfCfR2rI2zs9dz",
.url = "git+https://github.com/dasimmet/mbedtls#c86bbeb05de1a2c4645de2b973ee07f33a82d538",
.hash = "mbedtls-3.6.4-E4NUR7EUAAC0PK_jVCUyV3dvci1Uwbl4JFQzScnyqcsn",
.lazy = true,
},
.openssl = .{
.url = "https://github.com/allyourcodebase/openssl/archive/f348124c5382bcc377f1b3277357cbf2ed2fb8db.tar.gz",
.hash = "openssl-3.3.1-2-TC9C3Se3ZACF5WO_CjoD7Bt_X94oCsAAbbwhOp1rTZBe",
.url = "https://github.com/allyourcodebase/openssl/archive/refs/tags/3.3.2.tar.gz",
.hash = "openssl-3.3.2-TC9C3Wa3ZACgB1hZbrLOQCK9XccIBaW_F3imFfIeYP06",
.lazy = true,
},
.libressl = .{
.url = "https://github.com/allyourcodebase/libressl/archive/refs/tags/4.0.0+2.tar.gz",
.hash = "libressl-4.0.0--kqV4LnSAACWhbUEm8O5KHGuJpNJsN0xLIlbFun7ql-m",
.url = "https://github.com/allyourcodebase/libressl/archive/refs/tags/4.0.0+3.tar.gz",
.hash = "libressl-4.0.0--kqV4OjTAADhw9rD-tZaxFy2KPrSU4Bt9FOi9UZe-Zjl",
.lazy = true,
},

.libmp3lame = .{
.url = "https://github.com/andrewrk/libmp3lame/archive/9a7e3db1a86d86c33e1663c13ebe8e8f047fc008.tar.gz",
.hash = "libmp3lame-3.100.1-5-67wlF1KvEwDaCOrGGAl9Yb52UG3bcezunnbLcJo2t2HC",
.url = "https://github.com/jaysonsantos/libmp3lame/archive/62ed386c7f10926d9d53df768b0b0f73934e9522.tar.gz",
.hash = "libmp3lame-3.100.1-5-67wlF6uvEwBKHk2TOnFZQwpod8u9kmIIdpgCAmtc2kZp",
},
.libvorbis = .{
.url = "https://github.com/andrewrk/libvorbis/archive/f276273dcb0d9a5e0d832e3745c458c8056ee7ad.tar.gz",
.hash = "libvorbis-1.3.8-4-gL_KI2kPJACPcXW6H_SSrsaRnauuaJGPS9wPqg5ALE8q",
.url = "https://github.com/floatdrop/libvorbis/archive/6049d325043ab6f08b19fb760b8633815ff305c7.tar.gz",
.hash = "libvorbis-1.3.8-4-gL_KI9QPJAC3loix2mlGg1pXcJwogdNlh2S4rNJIyG0w",
},
.libogg = .{
.url = "https://github.com/andrewrk/libogg/archive/a0dc88e815fdd278b412d9b5ba09221f20517e03.tar.gz",
.hash = "libogg-1.3.6-3-ZBKq7fQUAgCz4fszMXyS-erQljD2tL5Z6A0Kh4B1T4qk",
.url = "https://github.com/jaysonsantos/libogg/archive/5b8e403d1a296a8adc27735ed6bb0a1ca560ddfd.tar.gz",
.hash = "libogg-1.3.6-3-ZBKq7UcVAgD8yYBphV_PiV9Si8rBvZBYLBbdbbFIbKLX",
},

// This is used to compile some assembly files into object files for x86.
// Without this, ffmpeg considers the build "crippled".
.nasm = .{
.url = "https://github.com/allyourcodebase/nasm/archive/c153aec97cfe50a4600d9cf3d5f703d58f9ccd56.tar.gz",
.hash = "nasm-2.16.1-4-J30EdyVnXADate9iz7jWR4Q9tL1jU9S2Lw7PGgfOjP0v",
.url = "https://github.com/vytskalt/nasm/archive/af40be2131cd2f4787fee97c3a543c2e6642ace9.tar.gz",
.hash = "nasm-2.16.1-4-J30Ed2hnXADeQLsOnARG2k-8pbg7qc4OsJFAU8DDYLDm",
},
},
.paths = .{
Expand Down
4 changes: 3 additions & 1 deletion doc/examples/show_metadata.zig
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub fn main() !void {

var it: ?*const av.Dictionary.Entry = null;
while (fc.metadata.iterate(it)) |tag| : (it = tag) {
try std.io.getStdOut().writer().print("{s}={s}\n", .{ tag.key, tag.value });
var w = std.fs.File.stdout().writer(&.{});
const stdout = &w.interface;
try stdout.print("{s}={s}\n", .{ tag.key, tag.value });
}
}