Skip to content

Effort free video editing!

Take common codec names and stop suggesting odd encoders

WyattBlue865d1a0dd8a5
diff --git a/src/av.nim b/src/av.nim
index 85cadb61..315b7218 100644
--- a/src/av.nim
+++ b/src/av.nim
@@ -150,16 +150,34 @@ proc resolveEncoderContext*(ctx: var ptr AVCodecContext) =
avcodec_free_context(addr ctx)
ctx = replacement
-proc initCodec*(name: string): ptr AVCodec =
- if name == "opus":
- return avcodec_find_encoder_by_name("libopus")
+const codecAliases = {
+ "h265": "hevc", "x265": "libx265", "x264": "libx264", "avc": "h264",
+ "svtav1": "libsvtav1", "svt-av1": "libsvtav1", "opus": "libopus",
+ "lame": "libmp3lame", "pcm": "pcm_s16le",
+}
+
+func codecAlias*(name: string): string {.raises: [].} =
+ ## The encoder name for what people commonly call a codec, as `h265` for
+ ## hevc. FFmpeg's own names are all lowercase.
+ result = name.toLowerAscii
+ for (alias, real) in codecAliases:
+ if result == alias:
+ return real
+proc initCodec*(name: string): ptr AVCodec =
+ let name = codecAlias(name)
result = avcodec_find_encoder_by_name(name.cstring)
if result == nil:
let desc = avcodec_descriptor_get_by_name(name.cstring)
if desc != nil:
result = avcodec_find_encoder(desc.id)
+const neverSuggest = ["h263", "libx264rgb", "prores_aw", "ac3_fixed",
+ "mp2fixed", "pcm_bluray", "hdr"]
+
+func suggestable(name: string): bool {.raises: [].} =
+ name notin neverSuggest and not name.endsWith("_planar")
+
proc encoderNames(): seq[string] =
var opaque: pointer = nil
while true:
@@ -167,8 +185,12 @@ proc encoderNames(): seq[string] =
if c == nil:
break
if av_codec_is_encoder(c) != 0:
- result.add $c.name
- result.add $avcodec_get_name(c.id)
+ for name in [$c.name, $avcodec_get_name(c.id)]:
+ if name.suggestable:
+ result.add name
+ for (alias, real) in codecAliases:
+ if avcodec_find_encoder_by_name(real.cstring) != nil:
+ result.add alias
result = result.deduplicate()
proc unknownEncoder(name: string) {.noreturn.} =
diff --git a/src/main.nim b/src/main.nim
index cb565408..1043231b 100644
--- a/src/main.nim
+++ b/src/main.nim
@@ -11,6 +11,7 @@ when not defined(windows) and not defined(emscripten):
import std/posix_utils
import ./[about, action, cli, conductor, edit, ffmpeg, license, log]
+from ./av import codecAlias
import render/burnsubs
import ./lib/escape
when defined(emscripten):
@@ -598,7 +599,7 @@ judge making cuts.
of coFrameRate:
args.frameRate = frameRateArg(key)
of coVcodec:
- video.codec = key
+ video.codec = codecAlias(key)
of coVideoBitrate:
video.bitrate = parseBitrate(key)
of coCrf:
@@ -619,7 +620,7 @@ judge making cuts.
of coPixFmt:
video.pixFmt = key
of coAcodec:
- audio.codec = key
+ audio.codec = codecAlias(key)
of coLayout:
audio.layout = key
of coAudioNormalize: