[FFmpeg-devel] [PATCH] ffmpeg_mux: terminate stream thread queue only on sq_send EOF

Gyan Doshi ffmpeg at gyani.pro
Tue Feb 7 10:43:09 EET 2023



On 2023-02-07 02:03 pm, Anton Khirnov wrote:
> Quoting Gyan Doshi (2023-02-07 09:18:22)
>>
>> On 2023-02-07 01:39 pm, Anton Khirnov wrote:
>>> Quoting Gyan Doshi (2023-02-04 11:01:21)
>>>> Prior to 2d924b3a630, ffmpeg would exit if any packet write failed.
>>>> After the switch to threaded mode for muxing, ffmpeg only closes that
>>>> OutputStream instead of closng the file. This happens because EOF
>>>> returned by write_packet isn't distinguished from EOF returned by sq_send,
>>>> both relayed via sync_queue_process.
>>>>
>>>> This breaks the abort behaviour when there are multiple streams in an output,
>>>> and can leave the ffmpeg process running beyond the intended point of abortion.
>>>>
>>>> Fixed by marking the OutputStream as finished upon sq_send EOF and letting
>>>> write_packet EOF lead to muxer termination.
>>> What is the situation you're handling exactly?
>>> av_interleaved_write_frame() returns EOF?
>> Yes.
> How does that happen? Doesn't seem to me that muxers should do this.

For repro, see this: 
https://ffmpeg.org/pipermail/ffmpeg-devel/2023-February/306247.html
> Otherwise, I'm not a big fan of your patch since it adds yet more
> overloading to ost->finished, which I'd like to remove actually. Not to
> mention you manipulate it from the muxer thread, which is a race.
> IMO this should be done without any context variables.

How would one do that, in this case?

I first thought of checking SyncQueue->stream[i]->finished but 
SyncQueueStream's declaration is private.

Regards,
Gyan



More information about the ffmpeg-devel mailing list