ffmpeg through PowerShell error Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
TablePerson22
Posts: 40
Joined: 04 Mar 2021, 20:27

ffmpeg through PowerShell error

11 Apr 2022, 18:28

Hello everyone,
I'm trying to use 'runwait, powershell.exe' to modify some videos with ffmpeg.
Pasting the ffmpeg command directly into PowerShell works, but it fails when trying through AHK.

I'm not sure if any other characters besides '%' needs to be escaped here.
Any help is appreciated.

Code:

Code: Select all

var = ffmpeg -y -i "C:/Users/userid/Desktop/1_0.mp4" -vf "drawtext=fontfile=C\\:/Windows/Fonts/Verdana.ttf:fontsize=20:fontcolor=#ffffff:box=1:boxborderw=10:bordercolor=#000000:boxcolor=#000000@1:x=390:y=329:text='`%{pts\:gmtime\:$([int32](New-TimeSpan -Start (Get-Date "01/01/1970") -End (Get-Date "04/08/2022 12:01:41")).TotalSeconds)}'" "C:/Users/userid/Desktop/1_0_NewTS.mp4"
msgbox % var
runwait, powershell.exe -noexit -command %var%
Message Box Result:

Code: Select all

---------------------------
test.ahk
---------------------------
ffmpeg -y -i "C:/Users/userid/Desktop/1_0.mp4" -vf "drawtext=fontfile=C\\:/Windows/Fonts/Verdana.ttf:fontsize=20:fontcolor=#ffffff:box=1:boxborderw=10:bordercolor=#000000:boxcolor=#000000@1:x=390:y=329:text='%{pts\:gmtime\:$([int32](New-TimeSpan -Start (Get-Date "01/01/1970") -End (Get-Date "04/08/2022 12:01:41")).TotalSeconds)}'" "C:/Users/userid/Desktop/1_0_NewTS.mp4"
---------------------------
OK   
---------------------------
PowerShell Returns 'Conversion Failed':

Code: Select all

ffmpeg version N-91282-gc5e6c0b5f6 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 7.3.0 (GCC)
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth
  libavutil      56. 18.102 / 56. 18.102
  libavcodec     58. 20.101 / 58. 20.101
  libavformat    58. 17.100 / 58. 17.100
  libavdevice    58.  4.101 / 58.  4.101
  libavfilter     7. 25.100 /  7. 25.100
  libswscale      5.  2.100 /  5.  2.100
  libswresample   3.  2.100 /  3.  2.100
  libpostproc    55.  2.100 / 55.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:/Users/userid/Desktop/1_0.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.17.100
  Duration: 00:00:30.98, start: 0.000000, bitrate: 303 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x360, 172 kb/s, 25 fps, 25 tbr, 30k tbn, 60k tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 32000 Hz, mono, fltp, 126 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
Fontconfig error: Cannot load default config file
[Parsed_drawtext_0 @ 000001fcc3950d40] Using "C:/WINDOWS/fonts/mingliub.ttc"
[AVFilterGraph @ 000001fcc2a85d80] Unable to parse graph description substring: "(New-TimeSpan -Start (Get-Date 01/01/1970) -End (Get-Date 04/08/2022 12:01:41)).TotalSeconds)}"
Error reinitializing filters!
Failed to inject frame into filter network: Invalid argument
Error while processing the decoded data for stream #0:0
[aac @ 000001fcc2563a00] Qavg: 65536.000
[aac @ 000001fcc2563a00] 2 frames left in the queue on closing
Conversion failed!
Pasting message box result in PS results in successful execution:

Code: Select all

ffmpeg version N-91282-gc5e6c0b5f6 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 7.3.0 (GCC)
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth
  libavutil      56. 18.102 / 56. 18.102
  libavcodec     58. 20.101 / 58. 20.101
  libavformat    58. 17.100 / 58. 17.100
  libavdevice    58.  4.101 / 58.  4.101
  libavfilter     7. 25.100 /  7. 25.100
  libswscale      5.  2.100 /  5.  2.100
  libswresample   3.  2.100 /  3.  2.100
  libpostproc    55.  2.100 / 55.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:/Users/userid/Desktop/1_0.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.17.100
  Duration: 00:00:30.98, start: 0.000000, bitrate: 303 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x360, 172 kb/s, 25 fps, 25 tbr, 30k tbn, 60k tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 32000 Hz, mono, fltp, 126 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 @ 00000160364e75c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 00000160364e75c0] profile High, level 3.0
[libx264 @ 00000160364e75c0] 264 - core 155 r2901 7d0ff22 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=11 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'C:/Users/userid/Desktop/1_0_NewTS.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.17.100
    Stream #0:0(und): Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 640x360, q=-1--1, 25 fps, 12800 tbn, 25 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc58.20.101 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 32000 Hz, mono, fltp, 69 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      encoder         : Lavc58.20.101 aac
frame=  774 fps=679 q=-1.0 Lsize=     616kB time=00:00:30.97 bitrate= 162.9kbits/s speed=27.2x
video:335kB audio:256kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 4.169868%
[libx264 @ 00000160364e75c0] frame I:4     Avg QP:12.40  size: 12060
[libx264 @ 00000160364e75c0] frame P:203   Avg QP:19.21  size:  1068
[libx264 @ 00000160364e75c0] frame B:567   Avg QP:27.11  size:   136
[libx264 @ 00000160364e75c0] consecutive B-frames:  0.6%  2.8%  6.6% 89.9%
[libx264 @ 00000160364e75c0] mb I  I16..4: 37.7% 37.0% 25.4%
[libx264 @ 00000160364e75c0] mb P  I16..4:  1.5%  1.2%  0.3%  P16..4: 14.8%  4.4%  2.2%  0.0%  0.0%    skip:75.6%
[libx264 @ 00000160364e75c0] mb B  I16..4:  0.1%  0.0%  0.0%  B16..8: 11.6%  0.2%  0.0%  direct: 0.0%  skip:88.0%  L0:42.2% L1:57.1% BI: 0.7%
[libx264 @ 00000160364e75c0] 8x8 transform intra:37.1% inter:68.0%
[libx264 @ 00000160364e75c0] coded y,uvDC,uvAC intra: 34.4% 31.6% 12.2% inter: 1.7% 1.9% 0.0%
[libx264 @ 00000160364e75c0] i16 v,h,dc,p: 48% 19%  6% 27%
[libx264 @ 00000160364e75c0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 41% 13% 29%  2%  3%  4%  2%  3%  2%
[libx264 @ 00000160364e75c0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 34% 32% 13%  3%  4%  4%  4%  4%  2%
[libx264 @ 00000160364e75c0] i8c dc,h,v,p: 68% 13% 17%  2%
[libx264 @ 00000160364e75c0] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 00000160364e75c0] ref P L0: 70.2%  8.1% 17.5%  4.2%
[libx264 @ 00000160364e75c0] ref B L0: 83.6% 14.9%  1.5%
[libx264 @ 00000160364e75c0] ref B L1: 94.1%  5.9%
[libx264 @ 00000160364e75c0] kb/s:88.49
[aac @ 0000016035fc3c40] Qavg: 8044.003
User avatar
mikeyww
Posts: 27191
Joined: 09 Sep 2014, 18:38

Re: ffmpeg through PowerShell error

11 Apr 2022, 18:43

I don't think you need PowerShell, since you can just run ffmpeg instead. If your Windows command line has no commas, then put RunWait in front of that command line. You might need to include the full path to ffmpeg.
TablePerson22
Posts: 40
Joined: 04 Mar 2021, 20:27

Re: ffmpeg through PowerShell error

11 Apr 2022, 20:30

Running it directly results in:

Code: Select all

[NULL @ 000001441e764fc0] Unable to find a suitable output format for '12:01:41)).TotalSeconds)}''
12:01:41)).TotalSeconds)}': Invalid argument
It looks like it's interpreting incorrectly which means my syntax is wrong, although I'm not sure how, or why it works in PowerShell.

I did also try specifying the output format with "-f mp4" but it results in the same error.
User avatar
mikeyww
Posts: 27191
Joined: 09 Sep 2014, 18:38

Re: ffmpeg through PowerShell error  Topic is solved

11 Apr 2022, 20:47

Feel free to post your revised script here. Whatever works on the Windows command line would work in AHK as well.
TablePerson22
Posts: 40
Joined: 04 Mar 2021, 20:27

Re: ffmpeg through PowerShell error

11 Apr 2022, 22:23

I took another route with the ffmpeg command and it works with just a 'runwait' in ahk now:

Code: Select all

var = %ffmpeg% -y -i "%input%" -vf "drawtext=fontfile=C\\:/Windows/Fonts/Verdana.ttf:fontsize=20:fontcolor=#ffffff:box=1:boxborderw=10:bordercolor=#000000:boxcolor=#000000@1:x=390:y=329:text='02/02/2022  `%{pts\:gmtime\:30\:`%H\\\:`%M\\\:`%S}'" "%output%"

runwait, %var%
Thank you
nacken012
Posts: 92
Joined: 22 Jul 2016, 14:39

Re: ffmpeg through PowerShell error

12 Apr 2022, 22:29

I made that myself.
After the start, first enter the video name and the fps and then simply drag the video in.

Code: Select all

#SingleInstance, Force
#NoEnv
SetBatchLines, -1
ListLines Off

IniRead,ReadWinPosX,WinPos.ini,WinPos,Key1
IniRead,ReadWinPosY,WinPos.ini,WinPos,Key2
IniRead,ReadEncoder,WinPos.ini,Encoder,Key1

Gui, New, ,Handy Video Converter 


Gui, Add, Text, x144 y7, Handy Video Converter Version 1.0
Gui, Add, Picture, x1 y6 w121 h90, Bilder/Handy.png

Gui, Add, Text, x144 y27, File einfach reinziehen ; vcmd_path, cmd_path
Gui, Add, Edit, x144 y50 w200 VVideoName, Video Name
Gui, Add, Radio, x144 y80 v29, 29,97 Frames
Gui, Add, Radio, x260 y80 v25 checked, 25 Frames

Gui, Add, Text, x360 y7 w400 vdauer, Video Dauer:   
Gui, Add, Text, x360 y27 w300 vformat, Video Größe:
Gui, Add, Text, x360 y47 w300 vfps, Video Format:
Gui, Add, Text, x690 y70, kb/s
Gui, Add, Slider, x355 y70 w295 h15 Thick15 Range1500-5000 ToolTip vencoder gencoder AltSubmit ,%Readencoder%
Gui, Add, Text, x660 y70 w30 vencodertext,%encoder% %readencoder%
;Gui, Add, Button, x600 y30 gStart, Start

Gui, Show, x%ReadWinPosX% y%ReadWinPosY% w730 h105 ;x419 y910

return

GuiDropFiles:
Gui, Submit, nohide



If 29 = 1
    Frames = 29
If 25 = 1
    Frames = 25



SplitPath, A_GuiEvent, Dateiname, Verzeichnis, Erweiterung, NameOhneErw, Laufwerk

;goto, neu

FileDelete, video.bat
FileAppend,  ; Das Komma ist in diesem Fall erforderlich.
(
ffprobe.exe -show_streams -hide_banner -select_streams v:0 "%A_GuiEvent%" > breite.txt
), video.bat
sleep, 300
runwait,%comspec% /c video.bat

;------------------Video Dauer-----------
Filename := "Breite.txt", FoundAt := 0
Loop 
{
    FileReadLine, Line, % Filename, % A_Index
    If (Line = "") || RegExMatch(Line, "duration=") Or RegExMatch(Line, "\QX:\\E")
    {
        FoundAt := A_Index
        Break
    }
}
If (FoundAt)
FileReadLine, line, Breite.txt, %FoundAt%
Var := StrSplit(line, "duration=").2
Zeit := var/60
Wert := Round(Zeit,-0)
GuiControl, text, dauer, Video Dauer:    %wert% Minuten
;------------------Video Dauer-----------


;------------------Video Breite-----------
Filename := "Breite.txt", FoundAt := 0
Loop 
{
    FileReadLine, Line, % Filename, % A_Index
    If (Line = "") || RegExMatch(Line, "width=") Or RegExMatch(Line, "\QX:\\E")
    {
        FoundAt := A_Index
        Break
    }
}
If (FoundAt)
FileReadLine, line, Breite.txt, %FoundAt%
Var := StrSplit(line, "width=").2
;------------------Video Breite-----------

;------------------Video Höhe-----------
Filename1 := "Breite.txt", FoundAt := 0
Loop 
{
    FileReadLine, Line1, % Filename1, % A_Index
    If (Line1 = "") || RegExMatch(Line1, "height=") Or RegExMatch(Line, "\QX:\\E")
    {
        FoundAt1 := A_Index
        Break
    }
}
If (FoundAt1)
FileReadLine, line1, Breite.txt, %FoundAt1%
Var1 := StrSplit(line1, "height=").2
GuiControl, text, format, Video Größe:    %var% x %var1%
;------------------Video Höhe-----------

;------------------Video fps-----------
Filename2 := "Breite.txt", FoundAt := 0
Loop 
{
    FileReadLine, Line2, % Filename2, % A_Index
    If (Line2 = "") || RegExMatch(Line2, "display_aspect_ratio=") Or RegExMatch(Line, "\QX:\\E")
    {
        FoundAt2 := A_Index
        Break
    }
}
If (FoundAt2)
FileReadLine, line2, Breite.txt, %FoundAt2%
Var2 := StrSplit(line2, "display_aspect_ratio=").2
Var3 := StrSplit(var2, "`/").1

GuiControl, text, fps, Video Format:   %var3%
;------------------Video fps-----------


return
start:

runwait,%comspec% /c bin\ffmpeg.exe -y -i "%A_GuiEvent%" -threads 32 -b:v 1700k -r "%Frames%" -c:a aac -ar 48000 -b:a 160k -bufsize 4096k -maxrate 30000k -preset fast "%Verzeichnis%\%VideoName%.mp4"

return

encoder:
Gui, Submit, nohide
guicontrol,, encodertext, %encoder%

return


GuiClose:
GuiEscape:
WinGetPos, WinPosX, WinPosY
IniWrite,%WinPosX%,WinPos.ini,WinPos,Key1
IniWrite,%WinPosY%,WinPos.ini,WinPos,Key2
IniWrite,%Encoder%,WinPos.ini,Encoder,Key1
ExitApp

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Chunjee and 138 guests