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
+3.8k Python : Find out the variable type and determine the type with simple test
+6.4k Golang : Lock executable to a specific machine with unique hash of the machine
+14.2k Golang : Get checkbox or extract multipart form data value example
+6k Golang : Get environment variable
+13.5k Golang : Normalize unicode strings for comparison purpose
+6.4k Javascript : Push notifications to browser with Push.js
+17.6k Golang : Populate dropdown with html/template example
+18.2k Golang : Measure http.Get() execution time
+23.4k Golang : Change file read or write permission example
+5.7k Unix/Linux : How to fix CentOS yum duplicate glibc or device-mapper-libs dependency error?
+8.2k Golang : How to control fmt or log print format?