FFMPEG converts to MOV only, but want MP4

Questions involving a Windows version of FFmpeg.
Post Reply
awc214
Posts: 7
Joined: Fri Oct 12, 2018 6:35 pm

FFMPEG converts to MOV only, but want MP4

Post by awc214 » Sun May 12, 2019 9:53 am

Hi all, I have a basic AutoHotKey script and I have little knowledge on how to manipulate it correctly.
The end goal is to process short videos into an MP4 via FFMPEG in real-time, but the end video file created is an MOV file, which is what I don't want since my video galleries do not accept MOV files, only MP4. There is no command line for MOV file so I'm not sure where to add a line where I designate MP4 being created. What is missing from the script? Thanks for any help for a beginner!

pandy
Posts: 204
Joined: Mon Feb 24, 2014 1:46 pm

Re: FFMPEG converts to MOV only, but want MP4

Post by pandy » Sun May 12, 2019 3:26 pm

Since you not providing your script all i can provide is part of ffmpeg commandline to output mp4 container:

Code: Select all

-movflags faststart -f mp4 "outputfilename.mp4"
where '-movflags faststart' is optional (recommended by YT).

awc214
Posts: 7
Joined: Fri Oct 12, 2018 6:35 pm

Re: FFMPEG converts to MOV only, but want MP4

Post by awc214 » Fri May 17, 2019 5:17 am

Hi, sorry for the delay. I wasn't notified anyone responded. Thanks for the help. Oops, you're absolutely right, the script might actually be helpful.

#singleinstance force
SetTitleMatchMode,2
StringCaseSense, Off

; subfolder in which to save a copy of the original video
copyFolder := "originals"

; rotate video in 90 degree increments, valid values: 0, 90, 180, 270
rotateDegreesClockwise := 0

; height of the video (after rotation). Set this to 0 to disable resizing
videoHeight := 600

; Crop the video to this width (after rotation). Set this to 0 to disable cropping
cropWidth := 0

; ffmpeg video preset, choose from: veryslow, slow, fast, veryfast and ultrafast
videoPreset := "veryfast"

; the number of times to loop the boomerang
loops := 3

; video playback speed
playbackSpeed := 2

; set this to 1 to display debug info (0 to disable debug)
showDebugMessages := 0

;----------- Please don't change anything below here unless you know what you're doing! ----------------

; make sure videoHeight is an even number
if Mod(videoHeight, 2)
{
videoHeight++
}

ffmpeg = %A_ScriptDir%\ffmpeg.exe
ifNotExist,%ffmpeg%
{
MsgBox ERROR: ffmpeg.exe not found.`nPlease make sure ffmpeg.exe is in the same folder as this script:`n%A_ScriptDir%
exitapp
}

if showDebugMessages
{
; display a debug window at the top of the screen
Gui +LastFound +AlwaysOnTop +ToolWindow ; +ToolWindow avoids a taskbar button and an alt-tab menu item.
Gui, Color, cBlack
Gui, Font, s12
Gui, Add, Text, vStatusText cLime, AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Gui, Add, Text, vStatusText2 cLime, AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Gui, Show,x100 y0 NoActivate,%A_ScriptName% ; NoActivate avoids deactivating the currently active window.
GuiControl,,StatusText,Please wait...
GuiControl,,StatusText2,
}

; look for XML file in the command line
if %0%
{
path = %1%
SplitPath, path,,, ext
if (ext = "mp4")
{
video = %1%
screenDir := "."
}
else if (ext = "xml")
{
IfNotExist, %1%
{
MsgBox ERROR: XML file not found: %1%
exitapp
}
; read XML file, process video and exit
FileRead, Contents, %1%
RegExMatch(Contents, "<video_information>", video)
RegExMatch(Contents, "<photobooth_images_folder>(.*)</photobooth_images_folder>", photoboothFolder)
RegExMatch(Contents, "<download_folder>(.*)</download_folder>", downloadFolder)
RegExMatch(Contents, "<video_file>(.*)</video_file>", file)

if not Contents contains <video_information>
{
MsgBox ERROR: not a video booth summary file: %1%
exitapp
}
if photoboothFolder < 1
{
MsgBox ERROR: video booth summary file doesn't contain <photobooth_images_folder> tag
exitapp
}
if downloadFolder < 1
{
MsgBox ERROR: video booth summary file doesn't contain <download_folder> tag
exitapp
}
if file < 1
{
MsgBox ERROR: video booth summary file doesn't contain <video_file> tag
exitapp
}

screenDir = %photoboothFolder1%
video = %downloadFolder1%\%file1%
}
else
{
MsgBox XML or MP4 image not found
exitapp
}

IfNotExist, %video%
{
MsgBox ERROR: video file not found: %video%
exitapp
}
IfNotExist, %screenDir%
{
;MsgBox ERROR: Screen folder not found: %screenDir%
;exitapp
}
showDebugMessages = 1
ProcessVideo(video, screenDir)
exitapp
}

; loop waiting for video files to process
DebugMessage(1,"Window title")
Loop
{
IfWinExist, Breeze Systems Photobooth -
{
WinGetTitle, Title, Breeze Systems Photobooth -
if title contains video_processing
{
RegExMatch(title, "\s-\s(.*)", screen)
SplitPath, screen1, screenFilename, screenDir
DebugMessage(1, "Screen folder: " screenDir)
ControlGetText, msg, Static2, Breeze Systems Photobooth
RegExMatch(msg, ",\s*movie=(.*)", video)
IfExist, %video1%
{
ProcessVideo(video1, screenDir)

; tell photo booth the processed video is ready
WinActivate, Breeze Systems Photobooth -
Send ^z
DebugMessage(2, "Sending Ctrl+Z to photo booth...")
Sleep 1000
}
else
{
DebugMessage(2, "Waiting for movie to download...")
}
}
else
{
DebugMessage(1, Title)
DebugMessage(2, "Waiting for video_processing screen...")
}
}
else
{
IfWinExist, DSLR Remote Pro for Windows -
{
DebugMessage(1, "Not running in photo booth mode")
}
else
{
DebugMessage(1, "DSLR Remote Pro is not running")
}
DebugMessage(2, "")
}
Sleep 100 ; sleep for 1/10th sec to avoid hogging the processor
}

ProcessVideo(video, screenFolder)
{
global ffmpeg, copyFolder, videoHeight, rotateDegreesClockwise
global videoPreset, showDebugMessages
global boomerang, playbackSpeed, cropWidth, loops

DebugMessage(2, "Processing " video)

rotate :=
if rotateDegreesClockwise = 90
{
rotate := "transpose=1"
}
else if rotateDegreesClockwise = 180
{
rotate := "transpose=2,transpose=2"
}
else if rotateDegreesClockwise = 270
{
rotate := "transpose=2"
}

overlay = %screenFolder%\video_overlay.png
outro = %screenFolder%\video_outro.mp4

audio = %screenFolder%\video_soundtrack.mp3
IfNotExist,%audio%
{
audio = %screenFolder%\video_soundtrack.wav
}

; make a copy of the original video and delete any temp files
SplitPath,video,name,folder
videoCopyFolder = %folder%\%copyFolder%
FileCreateDir,%videoCopyFolder%
videoCopy = %videoCopyFolder%\%name%
videoTemp = %videoCopyFolder%\temp_%name%
videoTempReversed = %videoCopyFolder%\temp_reversed_%name%
videoProcessed = %videoCopyFolder%\processed_%name%
FileDelete,%videoCopy%
FileDelete,%videoTemp%
FileDelete,%videoTempReversed%
FileDelete,%videoProcessed%
FileCopy,%video%,%videoCopy%

; First pass: speed up, crop, rotate, scale, add overlay and drop audio
inputFiles = -i "%video%"
filter :=
if playbackSpeed <> 1
{
speed := 1 / playbackSpeed
filter = setpts=%speed%*PTS
}
if cropWidth
{
if filter
{
filter = %filter%,crop=%cropWidth%
}
else
{
filter = crop=%cropWidth%
}
}
if rotate
{
if filter
{
filter = %filter%,%rotate%
}
else
{
filter = %rotate%
}
}
if videoHeight > 0
{
if filter
{
filter = %filter%,scale=-2:%videoHeight%
}
else
{
filter = scale=-2:%videoHeight%
}
}
if filter
{
filter = [0:v]%filter%
}
else
{
filter = [0:v]copy
}
IfExist,%overlay%
{
inputFiles = %inputFiles% -i "%overlay%"
filter = %filter%[bg],[bg][1:v]overlay=0:0
}
cmd = "%ffmpeg%" %inputFiles% -filter_complex "%filter%" -c:v libx264 -preset %videoPreset% -an "%videoTemp%"
;MsgBox %filter%`n%inputFiles%`n%cmd%
;FileAppend,%cmd%,test.bat
runwait,%cmd%,,Hide

; Second pass: create reversed copy
cmd = "%ffmpeg%" -i "%videoTemp%" -vf reverse "%videoTempReversed%"
; MsgBox %cmd%
runwait,%cmd%,,Hide

; Third pass: join them together with optional 'outro' video
if loops < 1
{
loops := 1
}
numInputs := 0
inputFiles :=

filter :=
Loop, %loops%
{
inputFiles = %inputFiles% -i "%videoTemp%" -i "%videoTempReversed%"
filter = %filter%[%numInputs%:v:0]
numInputs := numInputs + 1
filter = %filter%[%numInputs%:v:0]
numInputs := numInputs + 1
}
IfExist,%outro%
{
inputFiles = %inputFiles% -i "%outro%"
filter = %filter%[%numInputs%:v:0]
numInputs := numInputs + 1
}
IfExist,%audio%
{
inputFiles = %inputFiles% -i "%audio%"
filter = %filter% concat=n=%numInputs%:v=1:a=0 [v]
mapAndCodec = -map "[v]" -map %numInputs%:a -c:v libx264 -preset %videoPreset% -shortest
}
else
{
filter = %filter% concat=n=%numInputs%:v=1 [v]
mapAndCodec = -map "[v]" -preset %videoPreset% -c:v libx264
}
cmd = "%ffmpeg%" %inputFiles% -filter_complex "%filter%" %mapAndCodec% "%videoProcessed%"
FileDelete test.bat
FileAppend,%cmd%,test.bat
;MsgBox %cmd%
runwait,%cmd%,,Hide

; delete temporary files and overwrite original with processed video
FileDelete,%videoTemp%
FileDelete,%videoTempReversed%
FileMove,%videoProcessed%,%video%,1
}

; Display a debug message if showDebugMessages = 1
; num specifies the line on which to display the message (1 or 2)
; msg is the message to display
DebugMessage(num, msg)
{
global cStatusText, cStatusText2
global showDebugMessages
msg := A_Hour ":" A_Min ":" A_Sec ": " msg
if showDebugMessages
{
if num=1
{
GuiControl,,StatusText,%msg%
}
else
{
GuiControl,,StatusText2,%msg%
}
}
}

GuiClose:
ExitApp

Post Reply
'