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
+5.4k Golang : Convert an executable file into []byte example
+8.9k Golang : Find and replace data in all files recursively
+21.2k Golang : Set and Get HTTP request headers example
+9.1k Golang : Resolve domain name to IP4 and IP6 addresses.
+7.6k Golang : Set or add headers for many or different handlers
+11.3k Golang : Remove or trim extra comma from CSV
+35.6k Upload multiple files with Go
+15.8k Golang : XML to JSON example
+11.5k Golang : Get terminal width and height example
+12k Golang : Linear algebra and matrix calculation example
+5k Golang : Extract unicode string from another unicode string example
+7k Golang : Tell color name with OpenCV example