Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm converting my .flv file using a vbs command file. I'm attaching here below the code:

Set shell = WScript.CreateObject("WScript.Shell")
Set fs = CreateObject("Scripting.FileSystemObject")
Set darRegex = New RegExp
With darRegex
    .Pattern = "Video:.*DAR (\d+):(\d+)"
    .IgnoreCase = True
End With
Set resolutionRegex = New RegExp
With resolutionRegex
    .Pattern = "Video:.*, (\d+)x(\d+)"
    .IgnoreCase = True
End With
Dim line
Dim width
Dim height
Dim command
Dim FFMPEG_EXECUTABLE_PATH
Dim OUTPUT_PATH
FFMPEG_EXECUTABLE_PATH = "bin\\ffmpeg.exe"
OUTPUT_PATH = "out.alpha.3g2"
If Not fs.FileExists(WScript.Arguments(0)) Then
    WScript.Echo("Video file does not exist: " & WScript.Arguments(0))
    WScript.Quit(1)
End If
Set exec = shell.exec("CMD /S /C "" " & FFMPEG_EXECUTABLE_PATH & " -i """ & WScript.Arguments(0) & """ >video.info 2>&1 """)
Do While exec.Status = 0
    WScript.Sleep(50)
Loop
Set aspectRatioFile = fs.OpenTextFile("video.info", 1)
line = ""
Do While aspectRatioFile.AtEndOfStream <> True
    line = line & aspectRatioFile.ReadLine()
Loop
Set darRegexMatch = darRegex.Execute(line)
If darRegexMatch.Count > 0 Then
    width = darRegexMatch.Item(0).Submatches(0)
    height = darRegexMatch.Item(0).Submatches(1)
Else
    Set resolutionRegexMatch = resolutionRegex.Execute(line)
    If resolutionRegexMatch.Count = 0 Then
        WScript.Echo("Could not find aspect ratio of video")
        WScript.Quit(1)
    End If
    width = resolutionRegexMatch.Item(0).Submatches(0)
    height = resolutionRegexMatch.Item(0).Submatches(1)
End If
WScript.Echo("Video display aspect ratio determined to be " & width & ":" & height)
height2 = CStr(2 * CInt(height))
REM Entered characters won't print while ffmpeg is executing, so take over ffmpeg's task of asking user whether to overwrite
If fs.FileExists(OUTPUT_PATH) Then
    WScript.StdOut.Write("Output file " & OUTPUT_PATH & " already exists, do you want to overwrite? [yN] ")
    answer = WScript.StdIn.ReadLine
    if Not InStr(answer, "y") = 1 And Not InStr(answer, "Y") = 1 Then
        WScript.Quit(1)
    End If
End If
command = "CMD /S /C "" " & FFMPEG_EXECUTABLE_PATH & " -i """ & WScript.Arguments(0) & """ -vf ""[orig] transpose=dir=2 [rotated]; [rotated] split [a][b]; [b] alphaextract [alphaAsGrayscale]; [alphaAsGrayscale] pad=iw*2:ih:iw:0 [alphaAsGrayscalePadded]; [alphaAsGrayscalePadded][a] overlay"" -vcodec mpeg4 - 512x512 -aspect " & height & ":" & width & " -vb 215000 -r 20 -acodec aac -strict experimental -ar 22050 -y " & OUTPUT_PATH & " 2>&1 """
WScript.Echo(command)
Set conversionExec = shell.exec(command)
Do While conversionExec.Status = 0
    Do While Not conversionExec.StdOut.AtEndOfStream
        WScript.StdOut.Write(conversionExec.StdOut.Read(1))
    Loop
    WScript.Sleep(50)
Loop
REM Print any remaining stdout lines
WScript.StdOut.Write(conversionExec.StdOut.ReadAll())

Immediately the process stop showing this error:

Could not find aspect ratio of video

Where I'm wrong?
Considering I'm not a programmer and I'm using a third part site where I found this .vbs file.

share|improve this question
    
Just a side note: I guess those ** signs in the last line of code shouldn't be part of your script, or? Edit & Remove them if confirmed. (That will not solve your issue) –  nixda Aug 13 '13 at 13:35
    
Thanks Nixda they aren't. –  Mikropi Aug 13 '13 at 15:30
    
Can you run the ffmpeg command that's generated by the script on its own? Does it show you the output you want, and does it contain the DAR? Do you need VBS for this, and if not what other scripting languages could you use? And what should the goal of the conversion be? –  slhck Aug 13 '13 at 15:38
    
The command is cscript encode.vbs [filename.flv] –  Mikropi Aug 13 '13 at 15:50
1  
If you want it really simple you can just call ffmpeg -i input.mp4 -c:v libx264 -c:a aac -strict experimental out.3g2 instead of using this script. –  slhck Aug 13 '13 at 16:55

1 Answer 1

up vote 2 down vote accepted

I assume you have

  1. Downloaded ffmpeg to the same folder as your script
  2. A valid FLV video in the same folder (input.flv in my example)

    On Windows it should look like
    enter image description here

You can debug your script from command line with cscript encode.vbs input.flv > log.txt.
It will pipe the output and all errors to a log file.


Beside that, I changed the ffmpeg command which fixed the script

command = "CMD /S /C "" " & FFMPEG_EXECUTABLE_PATH & " -i """ & WScript.Arguments(0) & " "" -c:v libx264 -c:a aac -strict experimental " & OUTPUT_PATH & " 2>&1 """

WScript.Arguments(0) is your input FLV file and OUTPUT_PATH is the output file name

You can copy a working version of your script from github
Thanks should go @slhck.

share|improve this answer
1  
Sure. -vcodec mpeg4 - 512x512 – a single hyphen tells ffmpeg to output to a pipe. I think this is just a typo and it should be -vcodec mpeg4 -s 512x512, which would resize the video to 512 by 512 pixels. –  slhck Aug 13 '13 at 16:47
    
@slhck Can I have your expertise once more? Here is the next error [Parsed_alphaextract_2 @ 00036f00] Requested planes not available. [Parsed_split_1 @ 023ae8e0] Failed to configure input pad on Parsed_alphaextract_2 Error opening filters! –  nixda Aug 13 '13 at 16:54
    
This filter extracts alpha channel information from the input video. I guess your test video (like most video sources) does not have an alpha channel, so you won't get this command to run properly unless you take out the entire filter chain (-vf "…"). –  slhck Aug 13 '13 at 17:03
    
Sorry, I can't figure out whats wrong in my file. I tried the new code kindly provided by slhck and nixda but I still have the return message (also when tried the debugging) "Could not find aspect ratio of video". What should I do? Does anybody would check my video? How I could upload it? Cheers –  Mikropi Aug 13 '13 at 20:14
    
Here it is:ge.tt/69UMsoo/v/0 –  Mikropi Aug 13 '13 at 20:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.