Skip to content

Effort free video editing!

Export easeNames, parseKfTime and more FFmpeg bindings

WyattBlue76ce61fcef30
diff --git a/src/action.nim b/src/action.nim
index fedfa690..839e4474 100644
--- a/src/action.nim
+++ b/src/action.nim
@@ -416,12 +416,7 @@ func applyEase*(e: Easing, t: float32): float32 =
if x < 0.5'f32: 2.0'f32 * x * x
else: 1.0'f32 - 2.0'f32 * (1.0'f32 - x) * (1.0'f32 - x)
-func easeName(e: Easing): string =
- case e
- of easeLinear: "linear"
- of easeIn: "in"
- of easeOut: "out"
- of easeInOut: "inout"
+const easeNames*: array[Easing, string] = ["linear", "in", "out", "inout"]
proc pFloat(s: string): float32 {.raises: [ActionParseError].} =
# parseFloat accepts "nan" and "inf", which slip past `v < lo or v > hi`
@@ -454,7 +449,7 @@ proc parseDuration(spec: string): (float32, DurUnit) {.raises: [ActionParseError
if not (result[0] >= 0 and result[0] < Inf):
raise newException(ActionParseError, &"Duration can't be negative or infinite: {spec}")
-proc parseKfTime(spec: string): KfTime {.raises: [ActionParseError].} =
+proc parseKfTime*(spec: string): KfTime {.raises: [ActionParseError].} =
## "50%" -> percent of the section; otherwise a duration, as parseDuration.
if spec.endsWith("%"):
result = KfTime(at: pFloat(spec[0 ..< spec.len - 1]), unit: kuPercent)
@@ -648,12 +643,12 @@ func timedKeys*(a: Action, kf: seq[float32], kt: seq[KfTime], clipDur: int,
proc parseEasing(spec: string): Easing {.raises: [ActionParseError].} =
let name = if spec.startsWith("ease="): spec[5 .. ^1] else: spec
- case name
- of "linear": easeLinear
- of "in": easeIn
- of "out": easeOut
- of "inout", "in-out": easeInOut
- else: raise newException(ActionParseError, &"Unknown easing: {spec}")
+ if name == "in-out":
+ return easeInOut
+ for e, n in easeNames:
+ if n == name:
+ return e
+ raise newException(ActionParseError, &"Unknown easing: {spec}")
proc parseEaseTail(act: var Action, parts: seq[string], idx: int,
val: string) {.raises: [ActionParseError].} =
@@ -1357,7 +1352,7 @@ func parseAction*(val: string): Action {.raises: [ActionParseError].} =
func easeSuffix(a: Action): string =
## The trailing ":ease=..." for an animated action, or "" if it has none.
if not a.hasEase: return ""
- result = &":ease={easeName(a.easeCurve)}"
+ result = &":ease={easeNames[a.easeCurve]}"
case a.easeDurUnit
of duClip: discard
of duSec: result.add &":{a.easeDur}sec"
diff --git a/src/ffmpeg.nim b/src/ffmpeg.nim
index cbac12b0..52f5cd1a 100644
--- a/src/ffmpeg.nim
+++ b/src/ffmpeg.nim
@@ -306,6 +306,7 @@ type
subtitle_header*: ptr uint8
subtitle_header_size*: cint
pkt_timebase*: AVRational
+ skip_frame*: AVDiscard
# ... other fields omitted for brevity
proc `==`*(a: AVSampleFormat, b: cint): bool = cint(ord(a)) == b
@@ -660,6 +661,7 @@ proc av_samples_alloc*(audio_data: ptr ptr uint8, linesize: ptr cint, nb_channel
header: "<libavutil/samplefmt.h>".}
proc av_strdup*(s: cstring): cstring {.importc, header: "<libavutil/mem.h>".}
+proc av_free*(`ptr`: pointer) {.importc, header: "<libavutil/mem.h>".}
proc av_freep*(`ptr`: pointer) {.importc, header: "<libavutil/mem.h>".}
proc av_mallocz*(size: csize_t): pointer {.importc, header: "<libavutil/mem.h>".}
proc av_realloc_array*(`ptr`: pointer, nmemb, size: csize_t): pointer {.importc,
@@ -892,12 +894,16 @@ proc av_buffersink_get_frame_flags*(ctx: ptr AVFilterContext, frame: ptr AVFrame
flags: cint): cint {.importc, header: "<libavfilter/buffersink.h>".}
const AVSEEK_FLAG_BACKWARD* = 1
+const AVSEEK_FLAG_BYTE* = 2
const AV_PKT_FLAG_KEY* = 0x0001
const AV_PKT_FLAG_DISCARD* = 0x0004
const AVINDEX_KEYFRAME* = 0x0001
proc av_seek_frame*(s: ptr AVFormatContext, stream_index: cint, timestamp: int64,
flags: cint): cint {.importc, header: "<libavformat/avformat.h>".}
+proc avformat_seek_file*(s: ptr AVFormatContext, stream_index: cint,
+ min_ts, ts, max_ts: int64, flags: cint): cint {.importc,
+ header: "<libavformat/avformat.h>".}
type AVIndexEntry* {.importc, header: "<libavformat/avformat.h>".} = object
pos*: int64 # byte position in file
@@ -928,3 +934,22 @@ func planeRow*(frame: ptr AVFrame, plane, y: int): ptr UncheckedArray[uint8] {.i
## Row `y` of a picture's plane.
cast[ptr UncheckedArray[uint8]](cast[int](frame.data[plane]) +
y * frame.linesize[plane].int)
+
+proc av_cpu_force_count*(count: cint) {.importc, header: "<libavutil/cpu.h>".}
+
+type AVSHA* {.importc: "struct AVSHA", header: "<libavutil/sha.h>", incompleteStruct.} = object
+
+proc av_sha_alloc*(): ptr AVSHA {.importc, header: "<libavutil/sha.h>".}
+proc av_sha_init*(ctx: ptr AVSHA, bits: cint): cint {.importc, header: "<libavutil/sha.h>".}
+proc av_sha_update*(ctx: ptr AVSHA, data: pointer, len: csize_t) {.importc,
+ header: "<libavutil/sha.h>".}
+proc av_sha_final*(ctx: ptr AVSHA, digest: pointer) {.importc, header: "<libavutil/sha.h>".}
+
+type AVHMAC* {.importc, header: "<libavutil/hmac.h>", incompleteStruct.} = object
+
+const AV_HMAC_SHA256* = cint(3) # enum AVHMACType: MD5, SHA1, SHA224, SHA256, ...
+
+proc av_hmac_alloc*(kind: cint): ptr AVHMAC {.importc, header: "<libavutil/hmac.h>".}
+proc av_hmac_free*(ctx: ptr AVHMAC) {.importc, header: "<libavutil/hmac.h>".}
+proc av_hmac_calc*(ctx: ptr AVHMAC, data: pointer, len: cuint, key: pointer, keylen: cuint,
+ output: pointer, outlen: cuint): cint {.importc, header: "<libavutil/hmac.h>".}