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
+8.7k Android Studio : Import third-party library or package into Gradle Scripts
+11.5k Golang : How to flush a channel before the end of program?
+88.6k Golang : How to convert character to ASCII and back
+27.4k Golang : Find files by name - cross platform example
+7.5k Golang : Word limiter example
+7.5k Golang : Scanf function weird error in Windows
+21k Golang : Underscore or snake_case to camel case example
+5.9k Golang : Launching your executable inside a console under Linux
+48.7k Golang : Upload file from web browser to server
+7.1k Golang : Levenshtein distance example
+6k Golang : Fix opencv.LoadHaarClassifierCascade The node does not represent a user object error
+14.1k Golang: Pad right or print ending(suffix) zero or spaces in fmt.Printf example