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
+12.6k Golang : Forwarding a local port to a remote server example
+20.1k Golang : Convert(cast) bytes.Buffer or bytes.NewBuffer type to io.Reader
+15.7k Chrome : ERR_INSECURE_RESPONSE and allow Chrome browser to load insecure content
+16.5k Golang : How to implement two-factor authentication?
+11.6k SSL : The certificate is not trusted because no issuer chain was provided
+17.6k Golang : Clone with pointer and modify value
+28k Golang : Decode/unmarshal unknown JSON data type with map[string]interface
+6.2k Golang : Extract XML attribute data with attr field tag example
+7k Fix sudo yum hang problem with no output or error messages
+4.8k Unix/Linux : How to pipe/save output of a command to file?
+13.1k Golang : Get terminal width and height example
+6.8k Golang : Output or print out JSON stream/encoded data