Golang : ffmpeg with os/exec.Command() returns non-zero status
Problem:
You want to use ffmpeg
with os/exec.Command() and Run() to create your video files.
However, it keeps bombing out with the error message:
exit status 1
You are able to execute the command with the supplied parameters and flags just fine on your terminal.
What's going on? How to fix this?
Solution:
Golang's os/exec.Command()
function does not have the shell=true
feature like Python did. ffmpeg is very sensitive to white spaces when running from another program. To fix the problem, simply remove whitespaces by using ,
instead of +
to assemble the flags and parameters to ffmpeg.
For example,
cmd := exec.Command("ffmpeg", "-r "+recordedFPSstring+" -i "+videoFileName+" -r 6 temp_"+videoFileName)
to
cmd := exec.Command("ffmpeg", "-r", recordedFPSstring, "-i", videoFileName, "-r", "6", "temp_"+videoFileName)
See also : Golang : Merge video(OpenCV) and audio(PortAudio) into a mp4 file
By
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+6.4k Golang : Join lines with certain suffix symbol example
+15.3k Chrome : ERR_INSECURE_RESPONSE and allow Chrome browser to load insecure content
+9.4k Golang : Sort and reverse sort a slice of floats
+7.9k Golang : Randomize letters from a string example
+10.9k CodeIgniter : How to check if a session exist in PHP?
+9k Golang : How to get garbage collection data?
+14.2k Golang : GUI with Qt and OpenCV to capture image from camera
+8k Golang : Oanda bot with Telegram and RSI example
+9.1k Golang : Launch Mac OS X Preview (or other OS) application from your program example
+23.6k Golang : Use regular expression to validate domain name
+5.9k Golang : Create new color from command line parameters
+15.7k Golang : Generate universally unique identifier(UUID) example