Skip packets the decoder rejects instead of ending the conversion - #337
Open
MAX-WiRED wants to merge 1 commit into
Open
Skip packets the decoder rejects instead of ending the conversion#337MAX-WiRED wants to merge 1 commit into
MAX-WiRED wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Converting an mp3 fails. Audio → Convert simfile to ogg on a perfectly
ordinary mp3 reports
and leaves a nearly complete file behind, which is why the failure is easy to
miss: the .ogg is there, it plays, and only the last fraction of a second is
gone.
What happens
Two things in
decode_audio_frame, both at the end of the file.The packet that was never read. At
AVERROR_EOFthe function sets*finishedand falls through toavcodec_send_packetwith the packetav_read_framedid not fill:A null packet is what flushes a decoder; an empty one is just an empty one.
A packet the decoder rejects ends the conversion. An mp3 written with
padding after its last frame - which is common, and true of every file I
reproduced this on - ends on a packet that is not an mp3 frame.
mp3floatanswers
AVERROR_INVALIDDATAand saysHeader missing, and one bad packettakes the whole conversion down with it. Vorbis happens to tolerate the same
packet, which is why ogg input never showed the problem.
The change
At the end of the file the decoder is flushed with a null packet, and a packet
the decoder cannot make sense of is skipped rather than treated as fatal. That
is what ffmpeg's own examples do with
AVERROR_INVALIDDATA, and it is what aplayer does: one unreadable frame is not a reason to stop.
This also unblocks mp3 for #333, which runs the same conversion and hits the
same packet.
Testing
Built on Windows with clang-tidy and clang-format enforced, as the build does.
The mp3 that reported
Conversion failednow reportsand the .ogg is 226 bytes longer than the one the failing run left behind - the
tail that used to be dropped. Converting an ogg, which worked before, still
works and is unchanged.