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.9k Golang : Edge detection with Sobel method
+17.9k Golang : Get current URL example
+17.8k Golang : Get RGBA values of each image pixel
+5.9k Swift : substringWithRange() function example
+15.9k Golang : Check if IP address is version 4 or 6
+12k Golang : How to get a user home directory path?
+5.6k Golang : Derive cryptographic key from passwords with Argon2
+20.1k Golang : Convert(cast) string to rune and back to string example
+9.1k Golang : Wait and sync.WaitGroup example
+16k Golang : How to make a file read only and set it to writable again?
+16.4k How to enable MariaDB/MySQL logs ?