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
+9.3k Golang : How to delete element(data) from map ?
+19.1k Golang : Saving private and public key to files
+9.7k Android Studio : Create custom icons for your application example
+29.5k error: trying to remove "yum", which is protected
+13.2k Golang : package is not in GOROOT during compilation
+16.9k Golang : Implement getters and setters
+3.7k Mac OSX : Get disk partitions' size, type and name
+7.7k Golang : Handle sub domain with Gin
+13.7k Golang : Basic authentication with .htpasswd file
+40.5k Golang : Get hardware information such as disk, memory and CPU usage
+3.8k Unix/Linux : How to pipe/save output of a command to file?
+20.5k Golang : How to run Golang application such as web server in the background or as daemon?