Effort free video editing!
Make openFormatCtx's file a `string`, not `cstring`
WyattBlue48276c80802f
diff --git a/src/av.nim b/src/av.nimindex c9dec41a..cad71e89 100644--- a/src/av.nim+++ b/src/av.nim@@ -308,21 +308,18 @@ type InputContainer* = objectsubtitle*: seq[ptr AVStream]func fileUrl*(path: string): string =- ## `path` for FFmpeg to open as the file it names. Given a bare path, FFmpeg- ## takes what comes before a colon for a protocol, so `a:b.mp4` isn't found- ## and `file:b.mp4` is `b.mp4`."file:" & path-proc openFormatCtx*(file: cstring): ptr AVFormatContext {.raises: [IOError].} =+proc openFormatCtx*(file: string): ptr AVFormatContext {.raises: [IOError].} =# For a name with `%d` in it FFmpeg picks the image demuxer without opening# the file, so one that isn't there would come back as an empty input.- try: discard getFileInfo($file)+ try: discard getFileInfo(file)except OSError: raise newException(IOError, &"Input file doesn't exist: {file}")# That demuxer otherwise reads `%d` as a frame number and opens# `shot0.png`, `shot1.png`, ... for `shot%d.png`.var options: ptr AVDictionary = nildiscard av_dict_set(addr options, "pattern_type", "none", 0)- let ret = avformat_open_input(addr result, fileUrl($file).cstring, nil, addr options)+ let ret = avformat_open_input(addr result, fileUrl(file).cstring, nil, addr options)av_dict_free(addr options)if ret == AVERROR(ENOENT):raise newException(IOError, &"Input file doesn't exist: {file}")@@ -336,7 +333,7 @@ proc openFormatCtx*(file: cstring): ptr AVFormatContext {.raises: [IOError].} =raise newException(IOError, "Could not find stream information")proc open*(filename: string): InputContainer {.raises: [IOError].} =- result.formatContext = openFormatCtx(filename.cstring)+ result.formatContext = openFormatCtx(filename)result.packet = av_packet_alloc()for i in 0 ..< result.formatContext.nb_streams:let stream: ptr AVStream = result.formatContext.streams[i]diff --git a/src/cmds/desc.nim b/src/cmds/desc.nimindex 8b382838..e4854ba0 100644--- a/src/cmds/desc.nim+++ b/src/cmds/desc.nim@@ -14,7 +14,7 @@ proc main*(args: seq[string]) =var formatContext: ptr AVFormatContextfor inputFile in inputFiles:try:- formatContext = av.openFormatCtx(inputFile.cstring)+ formatContext = av.openFormatCtx(inputFile)except IOError:formatContext = nildiff --git a/src/cmds/info.nim b/src/cmds/info.nimindex 9b0f81d2..01a526cd 100644--- a/src/cmds/info.nim+++ b/src/cmds/info.nim@@ -325,7 +325,7 @@ proc main*(args: seq[string]) =var fileInfo: JsonNode = %* {}for inputFile in inputFiles:try:- let formatCtx = av.openFormatCtx(inputFile.cstring)+ let formatCtx = av.openFormatCtx(inputFile)let mediaInfo = initMediaInfo(formatCtx, inputFile)avformat_close_input(addr formatCtx)diff --git a/src/render/format.nim b/src/render/format.nimindex 20b10e9d..b1bb4578 100644--- a/src/render/format.nim+++ b/src/render/format.nim@@ -349,7 +349,7 @@ proc makeMedia*(args: mainArgs, inputVideo: VideoSettings, audio: AudioSettings,if cache != nil:imageSourceCtx = cache.getContainer(tl.templateFile).formatContextelse:- imageSourceCtx = av.openFormatCtx(tl.templateFile[].cstring)+ imageSourceCtx = av.openFormatCtx(tl.templateFile[])ownsImageSourceCtx = truefor i in 0 ..< imageSourceCtx.nb_streams: