If the stream is stopped, av_read_frame() will be woken up and yield a corrupted packet. Do not try to decode or record it.