10

When I run this from command line everything is fine

ffmpeg -i input.mp4 -f mp3 -ab 320000 -vn output.mp3 

But when I call the same from python

subprocess.call(['ffmpeg', '-i', 'input.mp4', '-f', 'mp3', '-ab', '320000', '-vn', 'output.mp3'])

After several seconds converting I'm getting this error

[aac @ 0x7fb3d803e000] decode_band_types: Input buffer exhausted before 
END element found
Error while decoding stream #0:1: Invalid data found when processing 
input
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fb3d8000000] stream 1, offset 0x80011d: 
partial file
input.mp4: Invalid data found when processing input

Any ideas?

2 Answers 2

2

You need to add -dn & -ignore_unknown and -sn option (if subtitles causing encoding failure).

-dn refers to no data encoding.

-sn refers to no subtitles encoding

-ignore_unknown refers to ignore the unknown streams(SCTE 35, 128 data)

Irrespective of the input streams, -dn -sn & -ignore_unknown options will work.

That will solve your problem.

There are another options if you want to preserve the data, subtitles streams.

-c:d copy refers to copy the data streams.

-c:s copy refers to copy the subtitle streams.

You can use -copy_unknown option to get the unknown streams into your output.

Your final code would look like below.

subprocess.call(['ffmpeg', '-i', 'input.mp4', '-f', 'mp3', '-ab', '320000', '-vn', '-sn', '-dn', '-ignore_unknown', 'output.mp3'])

NOTE: -copy_unknown option only works with ffmpeg 4.x version or above.

Sign up to request clarification or add additional context in comments.

Comments

1

Note - this error is not a FATAL error as defined by ffmpeg, meaning you could catch the error in code and the conversion will continue and the mp4 will be playable. It will be missing the 'failed' information, but most likely this was invisible to the user.

1 Comment

To improve your answer please add the respective code.

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.