Konstantin
Konstantin

Reputation: 101

using ffmpeg with python, Input buffer exhausted before END element found

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?

Upvotes: 10

Views: 8222

Answers (2)

Rich
Rich

Reputation: 11

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.

Upvotes: 1

geo-freak
geo-freak

Reputation: 357

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.

Upvotes: 2

Related Questions