0

I want to run the command ffprobe -i test.m4a -show_entries format=duration -v quiet -of csv="p=0". It works in the terminal and returns output code 0, but running it with subprocess, i.e.

subprocess.check_output(['ffprobe', '-i', 'test.m4a', '-show_entries', 'format=duration', '-v', 'quiet', '-of', 'csv="p=0"'])

raises a CalledProcessError - {Command} returned non-zero exit status 1.. I tried running this command in a try-except loop and printing the error details, but it just outputs as an empty byte string b''.

1

2 Answers 2

1

One way for debugging the issue is adding -report argument:

subprocess.check_output(['ffprobe', '-i', 'output.mp4', '-show_entries', 'format=duration', '-v', 'quiet', '-of', 'csv="p=0"', '-report'])

-report is used for creating a log file with name like ffprobe-20220811-232043.log.

The log files shows the following error:
[csv @ 00000213297fe640] Failed to set option '"p' with value '0"' provided to writer context

The log files shows that the executed "shell command" is:
ffprobe -i output.mp4 -show_entries "format=duration" -v quiet -of "csv=\"p=0\"" -report

The solution is removing the quotes from "p=0":

subprocess.check_output(['ffprobe', '-i', 'output.mp4', '-show_entries', 'format=duration', '-v', 'quiet', '-of', 'csv=p=0'])
Sign up to request clarification or add additional context in comments.

2 Comments

I tried the -report thing in this here question but it didn't generate any .log file. Can you please specify in your post where this file is supposed to get generated? It looks like it's also the quotes in my case but I need the quotes because the path may have directory names with spaces in them.
looks like the solution to my problem is stackoverflow.com/a/74225674/21109385 where I have to transform the command to string using " ".join(command)
0

I recommend using the subprocess.run instead of check_output.

subprocess.run(command, stdout=output, encoding="utf-8")

Command = is the variable that houses the command you want , no need for separation using the commas.

stdout = Output = means that the output should be recorded in the file called (Output) which you can create beforehand.

encoding = just means to make sure it's encoded into texts from bytes

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.