Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 254
Konstantin Avatar asked Jun 19 '18 09:06

Konstantin


1 Answers

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.

like image 152
geo-freak Avatar answered Oct 05 '22 10:10

geo-freak